This repository was archived by the owner on Aug 12, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
76 lines (66 loc) · 2.32 KB
/
sync-master-to-dev.yml
File metadata and controls
76 lines (66 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
name: Sync master → dev
on:
push:
branches:
- master
permissions:
contents: write # ensure GITHUB_TOKEN can push code
pull-requests: write # allow creating PRs
jobs:
sync-to-dev:
runs-on: ubuntu-latest
steps:
# 1. Checkout all history and branches
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
persist-credentials: true
# 2. Configure Git user
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# 3. Fetch and checkout dev properly, then merge master
- name: Merge master into dev
id: merge
run: |
# If remote dev exists…
if git ls-remote --exit-code --heads origin dev; then
# Fetch just the dev branch
git fetch origin dev
# If we have a local dev, reset it to remote; otherwise create it tracking origin/dev
if git show-ref --quiet refs/heads/dev; then
git checkout dev
git reset --hard origin/dev
else
git checkout -b dev origin/dev
fi
else
# No remote dev yet, branch off master
git checkout -b dev
fi
# Merge the latest master in
git merge origin/master --no-edit
continue-on-error: true
# 4. Push if merge succeeded
- name: Push changes if merge succeeded
if: steps.merge.outcome == 'success'
run: git push origin dev
# 5. Open a PR and request review if there were conflicts
- name: Open Pull Request on conflicts
if: steps.merge.outcome == 'failure'
uses: actions/github-script@v6
with:
github-token: ${{ secrets.PAT_PR }}
script: |
// 1) Create the PR from master → dev
const pr = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
head: 'master',
base: 'dev',
title: '🔀 Merge master → dev (conflicts)',
body: 'Automatic merge from **master** into **dev** failed due to conflicts. Please resolve and merge.',
draft: false
});