Skip to content

Commit 63d46be

Browse files
committed
sync main -> dev -> vX.Y-dev via sync branches
Steps: - create sync branch from base branch - merge head branch into sync branch - restore src/* and tests/* from base branch - commit & push - create PR for merging sync branch into base branch
1 parent 5f46ea3 commit 63d46be

File tree

2 files changed

+41
-12
lines changed

2 files changed

+41
-12
lines changed

.github/workflows/sync-dev-to-vX.Y-dev.yaml

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ on:
1111
push:
1212
branches:
1313
- dev
14+
workflow_dispatch: {}
1415

1516
jobs:
1617
sync-branches:
@@ -22,36 +23,49 @@ jobs:
2223
with:
2324
app-id: ${{ secrets.OAI_SPEC_PUBLISHER_APPID }}
2425
private-key: ${{ secrets.OAI_SPEC_PUBLISHER_PRIVATE_KEY }}
25-
26+
2627
- name: Checkout repository
2728
uses: actions/checkout@v5
2829
with:
2930
fetch-depth: 0
31+
token: ${{ steps.generate-token.outputs.token }}
3032

3133
- name: Create pull requests
3234
id: pull_requests
3335
shell: bash
3436
run: |
37+
git config user.name "github-actions[bot]"
38+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
39+
3540
DEV_BRANCHES=$(git branch -r --list origin/v?.?-dev)
3641
for DEV_BRANCH in $DEV_BRANCHES; do
3742
BASE=${DEV_BRANCH:7}
38-
EXISTS=$(gh pr list --base $BASE --head $HEAD \
43+
SYNC="$BASE-sync-with-$HEAD"
44+
45+
git checkout -b $SYNC origin/$SYNC || git checkout -b $SYNC origin/$BASE
46+
git merge origin/$HEAD -m "Merge $HEAD into $SYNC"
47+
git checkout origin/$BASE src/*
48+
git checkout origin/$BASE tests/*
49+
git commit -m "Restored src/* and tests/*" || echo ""
50+
git push -u origin $SYNC
51+
52+
EXISTS=$(gh pr list --base $BASE --head $SYNC \
3953
--json number --jq '.[] | .number')
4054
if [ ! -z "$EXISTS" ]; then
41-
echo "PR #$EXISTS already wants to merge $HEAD into $BASE"
55+
echo "PR #$EXISTS already wants to merge $SYNC into $BASE"
4256
continue
4357
fi
4458
45-
PR=$(gh pr create --base $BASE --head $HEAD \
59+
PR=$(gh pr create --base $BASE --head $SYNC \
4660
--label "Housekeeping" \
47-
--title "$BASE: update from $HEAD" \
48-
--body "Merge \`$HEAD\` into \`$BASE\`.")
61+
--title "$BASE: sync with $HEAD" \
62+
--body "Merge relevant changes from \`$HEAD\` into \`$BASE\`.")
4963
echo ""
5064
echo "PR to sync $DEV_BRANCH: $PR"
5165
sleep 10 # allow status checks to be triggered
5266
5367
gh pr checks $PR --watch --required || continue
54-
gh pr merge $PR --merge --admin
68+
# gh pr merge $PR --merge --admin
5569
done
5670
env:
5771
GH_TOKEN: ${{ steps.generate-token.outputs.token }}

.github/workflows/sync-main-to-dev.yaml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ on:
1111
push:
1212
branches:
1313
- main
14+
workflow_dispatch: {}
1415

1516
jobs:
1617
sync-branch:
@@ -25,22 +26,36 @@ jobs:
2526

2627
- name: Checkout repository
2728
uses: actions/checkout@v5
29+
with:
30+
fetch-depth: 0
31+
token: ${{ steps.generate-token.outputs.token }}
2832

2933
- name: Create pull request
3034
id: pull_request
3135
shell: bash
3236
run: |
33-
EXISTS=$(gh pr list --base $BASE --head $HEAD \
37+
git config user.name "github-actions[bot]"
38+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
39+
SYNC="$BASE-sync-with-$HEAD"
40+
41+
git checkout -b $SYNC origin/$SYNC || git checkout -b $SYNC origin/$BASE
42+
git merge origin/$HEAD -m "Merge $HEAD into $SYNC"
43+
git checkout origin/$BASE src/*
44+
git checkout origin/$BASE tests/*
45+
git commit -m "Restored src/* and tests/*" || echo ""
46+
git push -u origin $SYNC
47+
48+
EXISTS=$(gh pr list --base $BASE --head $SYNC \
3449
--json number --jq '.[] | .number')
3550
if [ ! -z "$EXISTS" ]; then
36-
echo "PR #$EXISTS already wants to merge $HEAD into $BASE"
51+
echo "PR #$EXISTS already wants to merge $SYNC into $BASE"
3752
exit 0
3853
fi
3954
40-
gh pr create --base $BASE --head $HEAD \
55+
gh pr create --base $BASE --head $SYNC \
4156
--label "Housekeeping" \
42-
--title "$BASE: update from $HEAD" \
43-
--body "Merge \`$HEAD\` into \`$BASE\`."
57+
--title "$BASE: sync with $HEAD" \
58+
--body "Merge relevant changes from \`$HEAD\` into \`$BASE\`."
4459
env:
4560
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
4661
HEAD: main

0 commit comments

Comments
 (0)