@@ -16,16 +16,54 @@ jobs:
16
16
- from_branch : " 2.5"
17
17
to_branch : " main"
18
18
runs-on : ubuntu-latest
19
+ env :
20
+ SYNC_COMMITTER : github-actions[bot]
19
21
steps :
20
- - name : Merge ${{ matrix.from_branch }} into ${{ matrix.to_branch }}
21
- if : github.event_name == 'workflow_dispatch' || github.ref_name == matrix.from_branch
22
- # Commit is pinned due to low popularity of the action repo.
23
- uses : tretuna/sync-branches@ea58ab6e406fd3ad016a064b31270bbb41127f41
24
- with :
25
- GITHUB_TOKEN : ${{secrets.GITHUB_TOKEN}}
26
- FROM_BRANCH : ${{ matrix.from_branch }}
22
+ - name : " Check out repository"
23
+
24
+
25
+ - name : " Install merge driver"
26
+ run : |
27
+ git config --global merge.ours.driver true
28
+
29
+ - name : " Check if merge branch already exists"
30
+ id : check_sync
31
+ run : |
32
+ if git fetch origin "${SYNC_BRANCH}"; then
33
+ echo "Branch ${SYNC_BRANCH} already exists, checking if the branch was modified..."
34
+ COMMITTER="$(git show --pretty=format:"%cn <%ce>" --no-patch "origin/${SYNC_BRANCH}")"
35
+ if [ "${COMMITTER}" = "${SYNC_COMMITTER}" ]; then
36
+ echo "Branch ${SYNC_BRANCH} was not modified."
37
+ else
38
+ echo "Branch ${SYNC_BRANCH} was modified, either delete it or update it yourself."
39
+ echo "skip_sync=true" >> $GITHUB_OUTPUT
40
+ fi
41
+ else
42
+ echo "Branch ${SYNC_BRANCH} does not exist yet."
43
+ fi
44
+ env:
45
+ SYNC_BRANCH: sync-branches/${{ matrix.from_branch}}-to-${{ matrix.to_branch }}
46
+
47
+ - name: "Merge Changes"
48
+ if: steps.check_sync.outputs.skip_sync != 'true'
49
+ run: |
50
+ git checkout -b "${SYNC_BRANCH}"
51
+ git reset --hard "origin/${TO_BRANCH}"
52
+ git pull --no-edit origin "${FROM_BRANCH}"
53
+ COMMIT_ORIGINAL="$(git show --no-patch --format="%h" "origin/${TO_BRANCH}")"
54
+ COMMIT_MERGE="$(git show --no-patch --format="%h" "origin/${TO_BRANCH}")"
55
+ if [ "${COMMIT_ORIGINAL}" = "${COMMIT_MERGE}" ]; then
56
+ git status
57
+ echo "No changes (or merge conflict), skipping push and PR creation."
58
+ else
59
+ git push --force origin "${SYNC_BRANCH}"
60
+ gh pr create -B "${FROM_BRANCH}" -H "${SYNC_BRANCH}" --title "${PULL_REQUEST_TITLE}" --body "${PULL_REQUEST_BODY}" --labels "sync-branches"
61
+ fi
62
+ env:
63
+ FROM_BRANCH: ${{ matrix.from_branch}}
27
64
TO_BRANCH: ${{ matrix.to_branch }}
28
- CONTENT_COMPARISON : true # Prevent empty PRs
65
+ SYNC_BRANCH: sync-branches/${{ matrix.from_branch}}-to-${{ matrix.to_branch }}
66
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29
67
PULL_REQUEST_TITLE: Merge changes from `${{ matrix.from_branch }}` into `${{ matrix.to_branch }}`
30
68
PULL_REQUEST_BODY: |
31
69
New content has landed in the `${{ matrix.from_branch }}` branch, so let's merge the changes into `${{ matrix.to_branch }}`.
0 commit comments