Skip to content

Commit 3a2b9eb

Browse files
committed
feat(ci): sync 'dev' branch with 'main' after successful release
1 parent 4bf335d commit 3a2b9eb

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Sync Branches
2+
on:
3+
workflow_run:
4+
workflows: [Release]
5+
types: [completed]
6+
branches: [main]
7+
workflow_dispatch:
8+
branches: [main]
9+
10+
permissions:
11+
contents: read # for checkout
12+
13+
jobs:
14+
sync-branches:
15+
name: sync dev branch with main
16+
runs-on: ubuntu-latest
17+
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }}
18+
steps:
19+
- name: generate token
20+
id: generate_token
21+
uses: tibdex/github-app-token@v1
22+
with:
23+
app_id: ${{ secrets.RELEASE_BOT_APP_ID }}
24+
private_key: ${{ secrets.RELEASE_BOT_PRIVATE_KEY }}
25+
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
26+
with:
27+
fetch-depth: 0 # Need full history for branch operations
28+
token: ${{ steps.generate_token.outputs.token }}
29+
- name: sync dev with main
30+
run: |
31+
git config --global user.name '${{ vars.RELEASE_BOT_GIT_AUTHOR_NAME }}'
32+
git config --global user.email '${{ vars.RELEASE_BOT_GIT_AUTHOR_EMAIL }}'
33+
34+
# Fetch all branches
35+
git fetch origin
36+
37+
# Get the latest release tag
38+
LATEST_TAG=$(git describe --tags --abbrev=0 origin/main)
39+
40+
# Check if dev branch exists
41+
if git ls-remote --heads origin dev | grep -q 'dev'; then
42+
# Checkout dev branch
43+
git checkout dev
44+
45+
# Merge main into dev with release version in commit message
46+
# Add --strategy-option=theirs to automatically resolve conflicts in favor of main
47+
git merge --no-edit main -m "Merge 'main' into 'dev' after release $LATEST_TAG"
48+
49+
# Push the merged changes
50+
git push origin dev
51+
else
52+
# If dev doesn't exist, create it from main
53+
git checkout -b dev
54+
git push origin dev
55+
fi

0 commit comments

Comments
 (0)