-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
78 lines (73 loc) · 2.88 KB
/
sync_branches.yml
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
77
78
name: Sync Branches
on:
push:
branches:
- "2.4"
- "2.5"
workflow_dispatch:
permissions: {}
jobs:
sync-branches:
strategy:
matrix:
include:
- from_branch: "2.4"
to_branch: "2.5"
- from_branch: "2.5"
to_branch: "main"
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
env:
SYNC_COMMITTER: github-actions[bot]
steps:
- name: "Check out repository"
uses: actions/checkout@v4.1.7
with:
persist-credentials: true
- name: "Configure Git"
run: |
git config --global merge.ours.driver true
git config --global pull.rebase false
- name: "Check if merge branch already exists"
id: check_sync
run: |
if git fetch origin "${SYNC_BRANCH}"; then
echo "Branch ${SYNC_BRANCH} already exists, checking if the branch was modified..."
COMMITTER="$(git show --pretty=format:"%cn <%ce>" --no-patch "origin/${SYNC_BRANCH}")"
if [ "${COMMITTER}" = "${SYNC_COMMITTER}" ]; then
echo "Branch ${SYNC_BRANCH} was not modified."
else
echo "Branch ${SYNC_BRANCH} was modified, either delete it or update it yourself."
echo "skip_sync=true" >> $GITHUB_OUTPUT
fi
else
echo "Branch ${SYNC_BRANCH} does not exist yet."
fi
env:
SYNC_BRANCH: sync-branch-${{ matrix.from_branch}}-to-${{ matrix.to_branch }}
- name: "Merge Changes"
if: steps.check_sync.outputs.skip_sync != 'true'
run: |
git checkout -b "${SYNC_BRANCH}"
git fetch origin "${TO_BRANCH}"
git reset --hard "origin/${TO_BRANCH}"
git pull --no-edit origin "${FROM_BRANCH}"
COMMIT_ORIGINAL="$(git show --no-patch --format="%h" "origin/${TO_BRANCH}")"
COMMIT_MERGE="$(git show --no-patch --format="%h" "origin/${TO_BRANCH}")"
if [ "${COMMIT_ORIGINAL}" = "${COMMIT_MERGE}" ]; then
git status
echo "No changes (or merge conflict), skipping push and PR creation."
else
git push --force origin "${SYNC_BRANCH}"
gh pr create -B "${FROM_BRANCH}" -H "${SYNC_BRANCH}" --title "${PULL_REQUEST_TITLE}" --body "${PULL_REQUEST_BODY}" --labels "sync-branches"
fi
env:
FROM_BRANCH: ${{ matrix.from_branch}}
TO_BRANCH: ${{ matrix.to_branch }}
SYNC_BRANCH: sync-branch-${{ matrix.from_branch}}-to-${{ matrix.to_branch }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PULL_REQUEST_TITLE: Merge changes from `${{ matrix.from_branch }}` into `${{ matrix.to_branch }}`
PULL_REQUEST_BODY: |
New content has landed in the `${{ matrix.from_branch }}` branch, so let's merge the changes into `${{ matrix.to_branch }}`.