Skip to content
This repository was archived by the owner on Aug 12, 2025. It is now read-only.

Commit e336773

Browse files
authored
Update sync-master-to-dev.yml
1 parent 6596662 commit e336773

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed
Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,68 @@
11
name: Sync master → dev
22

3-
permissions:
4-
contents: write
5-
63
on:
74
push:
85
branches:
96
- master
107

8+
permissions:
9+
contents: write # ensure GITHUB_TOKEN can push code
10+
1111
jobs:
1212
sync-to-dev:
1313
runs-on: ubuntu-latest
1414

1515
steps:
16-
# 1. Check out the full repository (all branches)
16+
# 1. Checkout all history and branches
1717
- name: Checkout repository
1818
uses: actions/checkout@v3
1919
with:
2020
fetch-depth: 0
21+
persist-credentials: true
2122

22-
# 2. Configure Git user for commits
23+
# 2. Configure Git user
2324
- name: Configure Git
2425
run: |
2526
git config user.name "github-actions[bot]"
2627
git config user.email "github-actions[bot]@users.noreply.github.com"
2728
28-
# 3. Attempt to merge master into dev (or create dev if it doesn't exist)
29+
# 3. Fetch and checkout dev properly, then merge master
2930
- name: Merge master into dev
3031
id: merge
3132
run: |
32-
# Switch to dev branch, or create it if missing
33-
if git show-ref --quiet refs/heads/dev; then
34-
git checkout dev
33+
# If remote dev exists…
34+
if git ls-remote --exit-code --heads origin dev; then
35+
# Fetch just the dev branch
36+
git fetch origin dev
37+
# If we have a local dev, reset it to remote; otherwise create it tracking origin/dev
38+
if git show-ref --quiet refs/heads/dev; then
39+
git checkout dev
40+
git reset --hard origin/dev
41+
else
42+
git checkout -b dev origin/dev
43+
fi
3544
else
45+
# No remote dev yet, branch off master
3646
git checkout -b dev
3747
fi
3848
39-
# Merge origin/master into dev and capture exit code
49+
# Merge the latest master in
4050
git merge origin/master --no-edit
4151
continue-on-error: true
4252

43-
# 4. If merge succeeded, push dev back to remote
53+
# 4. Push if merge succeeded
4454
- name: Push changes if merge succeeded
4555
if: steps.merge.outcome == 'success'
4656
run: git push origin dev
4757

48-
# 5. If merge failed (conflicts), open a PR and request reviewers
58+
# 5. Open a PR and request review if there were conflicts
4959
- name: Open Pull Request on conflicts
5060
if: steps.merge.outcome == 'failure'
5161
uses: actions/github-script@v6
5262
with:
5363
github-token: ${{ secrets.GITHUB_TOKEN }}
5464
script: |
55-
// Create a Pull Request from master → dev
65+
// 1) Create the PR from master → dev
5666
const pr = await github.pulls.create({
5767
owner: context.repo.owner,
5868
repo: context.repo.repo,
@@ -62,11 +72,10 @@ jobs:
6272
body: 'Automatic merge from **master** into **dev** failed due to conflicts. Please resolve and merge.',
6373
draft: false
6474
});
65-
66-
// Request review from your team — replace with actual GitHub usernames
75+
// 2) Request reviews (replace with your team’s GitHub handles)
6776
await github.pulls.requestReviewers({
6877
owner: context.repo.owner,
6978
repo: context.repo.repo,
7079
pull_number: pr.data.number,
71-
reviewers: ['whynotmax'] //Add more if needed
80+
reviewers: ['reviewer1', 'reviewer2']
7281
});

0 commit comments

Comments
 (0)