Skip to content

Commit 9bca06c

Browse files
feat: sync config/** from main → data on every config change, committing to data
1 parent ceb3349 commit 9bca06c

3 files changed

Lines changed: 155 additions & 14 deletions

File tree

.github/SETUP.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,38 @@ Only needed if you want cross-repo commits (e.g., pushing to YogaMatLabApp).
3232
- Value: Your personal access token
3333
- Click **Add secret**
3434

35+
### 3. (Optional, recommended) Set up BRANDS_SYNC_TOKEN
36+
37+
Only needed if you want `config/brands.json` changes to automatically sync into your app repo via `.github/workflows/update-brands.yml`.
38+
39+
This token must have access to the *target repo* (by default `productStripesAdmin/YogaMatLabApp`).
40+
41+
1. Create a Personal Access Token:
42+
- Recommended: **Tokens (classic)** with scope `repo` (private repos)
43+
- Alternative: fine-grained token that has access to the target repo and can trigger workflows / dispatch events
44+
45+
2. Add to this repository:
46+
- Go to repository Settings → Secrets and variables → Actions
47+
- Click **New repository secret**
48+
- Name: `BRANDS_SYNC_TOKEN`
49+
- Value: Your token
50+
- Click **Add secret**
51+
52+
### 4. (Optional) Configure target repo variables
53+
54+
If the app repo is not `productStripesAdmin/YogaMatLabApp`, set these repository variables (Settings → Secrets and variables → Actions → **Variables**):
55+
56+
- `BRANDS_SYNC_TARGET_OWNER` (defaults to this repo owner)
57+
- `BRANDS_SYNC_TARGET_REPO` (defaults to `YogaMatLabApp`)
58+
- `BRANDS_SYNC_TARGET_BRANCH` (defaults to `main`)
59+
- `BRANDS_SYNC_TARGET_PATH` (defaults to `config/brands.json`)
60+
61+
## Config Sync to data branch
62+
63+
If YogaMatLabApp consumes this repo via a submodule tracking the `data` branch (common for production), the `config/` directory also needs to be kept up to date there.
64+
65+
This repo includes `.github/workflows/sync-config-to-data-branch.yml`, which syncs `config/**` from `main``data` on every config change.
66+
3567
## Testing the Workflow
3668

3769
### Manual Trigger
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Sync config/ to data branch
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'config/**'
9+
workflow_dispatch:
10+
11+
permissions:
12+
contents: write
13+
14+
jobs:
15+
sync:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
with:
22+
token: ${{ secrets.PAT_TOKEN || github.token }}
23+
24+
- name: Sync config/ into data branch
25+
run: |
26+
set -euo pipefail
27+
28+
DATA_BRANCH="data"
29+
30+
git config user.name "github-actions[bot]"
31+
git config user.email "github-actions[bot]@users.noreply.github.com"
32+
33+
# Prepare a separate worktree for the data branch so main stays clean.
34+
git fetch origin "${DATA_BRANCH}" || true
35+
rm -rf ../data-branch
36+
37+
if git show-ref --verify --quiet "refs/remotes/origin/${DATA_BRANCH}"; then
38+
git worktree add ../data-branch "origin/${DATA_BRANCH}"
39+
else
40+
git worktree add ../data-branch --detach
41+
cd ../data-branch
42+
git checkout --orphan "${DATA_BRANCH}"
43+
git rm -rf . || true
44+
cd -
45+
fi
46+
47+
rsync -a --delete --exclude '.git' config/ ../data-branch/config/
48+
49+
cd ../data-branch
50+
git add -A config/
51+
52+
if git diff --staged --quiet; then
53+
echo "## ✅ config/ already up to date on ${DATA_BRANCH}" >> "$GITHUB_STEP_SUMMARY"
54+
exit 0
55+
fi
56+
57+
git commit -m "chore: sync config into data branch (${GITHUB_SHA::7})"
58+
git push origin HEAD:"${DATA_BRANCH}"
59+
60+
echo "## ✅ Synced config/ to ${DATA_BRANCH} branch" >> "$GITHUB_STEP_SUMMARY"
Lines changed: 63 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,78 @@
1-
name: Trigger Brands Update
1+
name: Sync brands.json to app repo
22

33
on:
44
push:
55
branches:
66
- main
77
paths:
88
- 'config/brands.json'
9-
- 'data/**'
9+
workflow_dispatch:
1010

1111
jobs:
12-
trigger-update:
12+
sync:
1313
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read
1416

1517
steps:
16-
- name: Trigger YogaMatLabApp submodule update
18+
- name: Preflight (ensure token configured)
19+
if: ${{ !secrets.BRANDS_SYNC_TOKEN && !secrets.PAT_TOKEN }}
1720
run: |
18-
curl -X POST \
19-
-H "Accept: application/vnd.github.v3+json" \
20-
-H "Authorization: token ${{ secrets.PAT_TOKEN }}" \
21-
https://api.github.com/repos/productStripesAdmin/YogaMatLabApp/dispatches \
22-
-d '{"event_type":"data-updated"}'
21+
echo "Missing required token." >> "$GITHUB_STEP_SUMMARY"
22+
echo "" >> "$GITHUB_STEP_SUMMARY"
23+
echo "Set BRANDS_SYNC_TOKEN (recommended) or PAT_TOKEN with access to the target repo." >> "$GITHUB_STEP_SUMMARY"
24+
exit 1
2325
24-
- name: Summary
26+
- name: Checkout YogaMatLabData
27+
uses: actions/checkout@v4
28+
with:
29+
path: source
30+
31+
- name: Checkout target app repo
32+
uses: actions/checkout@v4
33+
with:
34+
repository: ${{ format('{0}/{1}', vars.BRANDS_SYNC_TARGET_OWNER || github.repository_owner, vars.BRANDS_SYNC_TARGET_REPO || 'YogaMatLabApp') }}
35+
ref: ${{ vars.BRANDS_SYNC_TARGET_BRANCH || 'main' }}
36+
token: ${{ secrets.BRANDS_SYNC_TOKEN || secrets.PAT_TOKEN }}
37+
path: target
38+
39+
- name: Copy brands.json into target repo
40+
env:
41+
TARGET_OWNER: ${{ vars.BRANDS_SYNC_TARGET_OWNER || github.repository_owner }}
42+
TARGET_REPO: ${{ vars.BRANDS_SYNC_TARGET_REPO || 'YogaMatLabApp' }}
43+
TARGET_BRANCH: ${{ vars.BRANDS_SYNC_TARGET_BRANCH || 'main' }}
44+
TARGET_PATH: ${{ vars.BRANDS_SYNC_TARGET_PATH || 'config/brands.json' }}
2545
run: |
26-
echo "## ✅ Webhook Sent" >> $GITHUB_STEP_SUMMARY
27-
echo "" >> $GITHUB_STEP_SUMMARY
28-
echo "Triggered YogaMatLabApp to update its data submodule." >> $GITHUB_STEP_SUMMARY
29-
echo "Check the workflow run at: https://github.com/productStripesAdmin/YogaMatLabApp/actions" >> $GITHUB_STEP_SUMMARY
46+
set -euo pipefail
47+
48+
if [ ! -f "source/config/brands.json" ]; then
49+
echo "Expected file not found: source/config/brands.json"
50+
exit 1
51+
fi
52+
53+
mkdir -p "target/$(dirname "$TARGET_PATH")"
54+
cp "source/config/brands.json" "target/$TARGET_PATH"
55+
56+
cd target
57+
58+
git config user.name "github-actions[bot]"
59+
git config user.email "github-actions[bot]@users.noreply.github.com"
60+
61+
git add "$TARGET_PATH"
62+
63+
if git diff --staged --quiet; then
64+
echo "No changes to commit."
65+
echo "## ✅ brands.json already up to date" >> "$GITHUB_STEP_SUMMARY"
66+
echo "" >> "$GITHUB_STEP_SUMMARY"
67+
echo "Target: ${TARGET_OWNER}/${TARGET_REPO}@${TARGET_BRANCH}" >> "$GITHUB_STEP_SUMMARY"
68+
echo "Path: ${TARGET_PATH}" >> "$GITHUB_STEP_SUMMARY"
69+
exit 0
70+
fi
71+
72+
git commit -m "chore: sync brands.json from YogaMatLabData (${GITHUB_SHA::7})"
73+
git push origin "HEAD:${TARGET_BRANCH}"
74+
75+
echo "## ✅ Synced brands.json to target repo" >> "$GITHUB_STEP_SUMMARY"
76+
echo "" >> "$GITHUB_STEP_SUMMARY"
77+
echo "Target: ${TARGET_OWNER}/${TARGET_REPO}@${TARGET_BRANCH}" >> "$GITHUB_STEP_SUMMARY"
78+
echo "Path: ${TARGET_PATH}" >> "$GITHUB_STEP_SUMMARY"

0 commit comments

Comments
 (0)