Skip to content

Commit d5781a0

Browse files
committed
Add auto-sync workflow from main to offline branch
- Add sync-build-json.yml workflow to automatically sync build.json from main branch to offline branch when updated - Update update-deploy-pr.sh to use auto/wire-server-version-bump branch name for regular commits (instead of auto/bump-wire-build) - Update README.md to document the workflow chain and triggers - Preserves original commit message and author from main branch This enables automatic PR creation to wire-server-deploy when build.json is updated on the main branch.
1 parent fd87d68 commit d5781a0

File tree

3 files changed

+121
-16
lines changed

3 files changed

+121
-16
lines changed

.github/scripts/update-deploy-pr.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ OPTIONS:
2222
-r, --ref REF Git reference (commit SHA or tag name) (required)
2323
-d, --deploy-dir DIR Path to wire-server-deploy directory (required)
2424
-t, --token TOKEN GitHub token for creating PRs (required)
25+
-b, --source-branch BRANCH Source branch name (main/offline) (optional, default: offline)
26+
-T, --target-branch BRANCH Target branch in wire-server-deploy (optional, default: master)
2527
-h, --help Show this help message
2628
2729
ENVIRONMENT:
@@ -32,6 +34,7 @@ ENVIRONMENT:
3234
EXAMPLE:
3335
$0 --ref abc123 --deploy-dir ./wire-server-deploy --token \$ZEBOT_TOKEN
3436
$0 --ref pinned-offline-5.23.0 --deploy-dir ./wire-server-deploy --token \$ZEBOT_TOKEN
37+
$0 --ref abc123 --deploy-dir ./wire-server-deploy --token \$ZEBOT_TOKEN --source-branch main --target-branch develop
3538
3639
EOF
3740
exit 1
@@ -98,8 +101,8 @@ get_branch_name() {
98101
local version="${BASH_REMATCH[2]}"
99102
echo "auto/pin-${base_branch}-${version}"
100103
else
101-
# For regular commits, use the standard branch name
102-
echo "auto/bump-wire-build"
104+
# For regular commits, use version-bump branch name
105+
echo "auto/wire-server-version-bump"
103106
fi
104107
}
105108

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Sync build.json from main to offline
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'build.json'
9+
10+
jobs:
11+
sync-to-offline:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: write
15+
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
ref: offline
22+
token: ${{ secrets.ZEBOT_TOKEN || secrets.GITHUB_TOKEN }}
23+
24+
- name: Configure git
25+
run: |
26+
git config user.name "zebot"
27+
git config user.email "zebot@users.noreply.github.com"
28+
29+
- name: Get build.json from main
30+
run: |
31+
git fetch origin main
32+
git checkout origin/main -- build.json
33+
34+
- name: Check if there are changes
35+
id: check-changes
36+
run: |
37+
if git diff --quiet HEAD build.json; then
38+
echo "No changes to sync"
39+
echo "has_changes=false" >> $GITHUB_OUTPUT
40+
else
41+
echo "Changes detected"
42+
echo "has_changes=true" >> $GITHUB_OUTPUT
43+
fi
44+
45+
- name: Commit and push changes
46+
if: steps.check-changes.outputs.has_changes == 'true'
47+
run: |
48+
git add build.json
49+
50+
# Get the commit message from the main branch's latest commit that changed build.json
51+
git fetch origin main
52+
COMMIT_MSG=$(git log origin/main -1 --format=%B -- build.json)
53+
COMMIT_AUTHOR=$(git log origin/main -1 --format="%an" -- build.json)
54+
COMMIT_EMAIL=$(git log origin/main -1 --format="%ae" -- build.json)
55+
56+
# Use the original author for the commit
57+
git config user.name "$COMMIT_AUTHOR"
58+
git config user.email "$COMMIT_EMAIL"
59+
60+
# Commit with the same message as main
61+
git commit -m "$COMMIT_MSG"
62+
63+
git push origin offline
64+
65+
- name: Summary
66+
if: steps.check-changes.outputs.has_changes == 'true'
67+
run: |
68+
echo "✅ build.json synced from main to offline"
69+
echo " The create-deploy-pr workflow will be triggered next"

README.md

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,25 @@ The workflow automatically creates or updates pull requests in the [wire-server-
1313

1414
### Triggers
1515

16-
1. **Push to `offline` branch** when `build.json` is modified
17-
2. **Pull requests** that modify `build.json`
18-
3. **Manual dispatch (CLI)** with optional wire-server version pinning
16+
1. **Push to `main` branch** when `build.json` is modified - automatically syncs to `offline` branch
17+
2. **Push to `offline` branch** when `build.json` is modified
18+
3. **Pull requests** that modify `build.json`
19+
4. **Manual dispatch (CLI)** with optional wire-server version pinning
1920

2021
### Features
2122

22-
#### Automatic PR Creation
23+
#### Automatic Build Sync and PR Creation
2324

24-
When `build.json` is updated on the `offline` branch, the workflow:
25-
1. Updates the wire-build URL in `wire-server-deploy/offline/tasks/proc_pull_charts.sh`
26-
2. Creates/updates a PR in wire-server-deploy with version details and commit links
25+
When `build.json` is updated on the `main` branch:
26+
1. The `sync-build-json.yml` workflow automatically syncs it to the `offline` branch
27+
2. This triggers the `create-deploy-pr.yml` workflow, which:
28+
- Updates the wire-build URL in `wire-server-deploy/offline/tasks/proc_pull_charts.sh`
29+
- Creates/updates a PR in wire-server-deploy with version details and commit links
30+
- Uses branch name: `auto/wire-server-version-bump`
31+
32+
When `build.json` is updated directly on the `offline` branch (manual changes):
33+
1. The `create-deploy-pr.yml` workflow triggers directly
34+
2. Updates wire-server-deploy and creates a PR (same as above)
2735

2836
#### Wire-Server Version Pinning (CLI)
2937

@@ -105,12 +113,37 @@ $ git ls-tree pinned-offline-5.23.0
105113
- `meta.commit`: Git commit SHA for this chart version
106114
- `meta.commitURL`: Direct link to the commit on GitHub
107115

116+
## Workflow Chain
117+
118+
When `build.json` is updated on the `main` branch, a two-step workflow chain executes:
119+
120+
```
121+
main: build.json updated
122+
123+
sync-build-json.yml workflow triggers
124+
125+
Syncs build.json to offline branch
126+
127+
create-deploy-pr.yml workflow triggers
128+
129+
Creates PR in wire-server-deploy
130+
```
131+
132+
This ensures that production-ready versions on `main` are automatically propagated to the offline deployment configuration.
133+
108134
## Common Operations
109135

110136
### Updating Chart Versions
111137

112-
1. Modify `build.json` with new chart versions
113-
2. Commit and push to the `offline` branch
138+
**Option 1: Update main branch (recommended for production versions)**
139+
1. Modify `build.json` with new chart versions on `main` branch
140+
2. Commit and push to `main`
141+
3. Sync workflow automatically updates `offline` branch
142+
4. PR creation workflow automatically creates a PR in wire-server-deploy
143+
144+
**Option 2: Update offline branch directly (for testing or offline-specific changes)**
145+
1. Modify `build.json` with new chart versions on `offline` branch
146+
2. Commit and push to `offline`
114147
3. Workflow automatically creates a PR in wire-server-deploy
115148

116149
### Checking Workflow Status
@@ -132,23 +165,23 @@ The workflow uses different branch naming strategies:
132165

133166
| Trigger | Branch Name | Behavior |
134167
|---------|-------------|----------|
135-
| Automatic (push to `build.json`) | `auto/bump-wire-build` | Reused for all automatic updates |
168+
| Automatic (sync from `main`) | `auto/wire-server-version-bump` | Reused for all automatic version bumps |
136169
| Pinned version (workflow_dispatch) | `auto/pin-<branch>-<version>` | Unique per pinned version |
137170

138-
**For automatic updates (`auto/bump-wire-build`):**
171+
**For automatic updates (`auto/wire-server-version-bump`):**
139172

140173
After you merge a PR, the next trigger will:
141-
1. Fetch the existing `auto/bump-wire-build` branch
174+
1. Fetch the existing `auto/wire-server-version-bump` branch
142175
2. Attempt to rebase it on master (which includes the merged changes)
143176
3. If rebase succeeds: update the branch and create a new PR
144177
4. If rebase fails: delete and recreate the branch from master
145178

146-
**Best practice:** Delete the `auto/bump-wire-build` branch after merging to ensure clean PR history:
179+
**Best practice:** Delete the `auto/wire-server-version-bump` branch after merging to ensure clean PR history:
147180

148181
```bash
149182
# Delete the branch after merging
150183
cd wire-server-deploy
151-
git push origin --delete auto/bump-wire-build
184+
git push origin --delete auto/wire-server-version-bump
152185
```
153186

154187
Or enable "Automatically delete head branches" in GitHub repository settings.

0 commit comments

Comments
 (0)