-
Notifications
You must be signed in to change notification settings - Fork 80
111 lines (109 loc) · 4.17 KB
/
sync_develop_with_master.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
name: Sync develop with master
'on':
pull_request:
types:
- closed
branches:
- master
permissions:
contents: write
jobs:
start:
name: "Starting -🤞"
runs-on: ubuntu-latest
steps:
- name: Starting
id: init
run: |
echo "Starting branch synchronization of ${{ github.repository }}"
create_pr_for_nonplugin:
name: Synchronizing non-plugin PR
needs: start # This job now needs the 'start' job to complete first
if: >
github.event.pull_request.merged == true &&
!(startsWith(github.event.pull_request.head.ref, 'web_submission_') &&
contains(github.event.pull_request.title, 'brain-score.org submission'))
runs-on: ubuntu-latest
steps:
- name: Check out the develop branch
uses: actions/checkout@v3
with:
fetch-depth: 0 # Fetch full history
ref: develop
- name: Reset the develop branch
run: |
git fetch origin master
git reset --hard origin/master
- name: Create pull request in develop
uses: peter-evans/create-pull-request@v6
with:
token: '${{ secrets.PAT }}'
commit-message: Sync master into develop
title: Sync master into develop
body: >-
This PR syncs the latest changes from the master branch into the
develop branch.
base: develop
branch: 'developer-sync-pr-${{ github.event.pull_request.number }}'
auto_sync_for_plugin:
needs: start
if: >
github.event.pull_request.merged == true &&
startsWith(github.event.pull_request.head.ref, 'web_submission_') &&
contains(github.event.pull_request.title, 'brain-score.org submission')
runs-on: ubuntu-latest
steps:
- name: Checkout the develop branch
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: develop
- name: Configure Git user
run: |
git config --global user.name "Branch Synchronizer"
git config --global user.email "[email protected]"
- name: Ensure develop branch is updated
run: |
git fetch origin develop
git checkout develop
git merge origin/develop
# Fetch latest change from master, checkout develop, merge changes from master to develop.
# Includes conflict handling
- name: Merge master into develop
id: merge
run: |
git fetch origin master
git checkout develop
git merge origin/master || {
if git diff --name-only --diff-filter=U | grep -q '.'; then
echo "Merge conflict detected"
echo "::set-output name=merge_conflict::true"
else
echo "Merge failed due to another reason"
exit 1
fi
}
- name: Push changes to develop (if merge is successful)
if: steps.merge.conclusion == 'success'
run: | #Use force-with-lease to prevent accidental overwrite if branch has been updated. If fails, rebase the update and retry
git push origin develop --force-with-lease || {
echo "Push failed due to updates in develop. Attempting to rebase and retry..."
git fetch origin develop
git rebase origin/develop
git push origin develop --force-with-lease
}
- name: Create pull request for merge conflicts
if: steps.merge.outputs.merge_conflict == 'true'
uses: peter-evans/create-pull-request@v6
with:
token: '${{ secrets.PAT }}'
commit-message: Merge master into develop with conflict resolution
title: Resolve conflicts between master and develop
body: This PR resolves merge conflicts between master and develop.
base: develop
branch: 'developer-sync-pr-conflict-${{ github.event.pull_request.number }}'
- name: Handle other merge failures
if: failure() && steps.merge.outputs.merge_conflict != 'true'
run: >
echo "Handle non-conflict related failure, such as network issues or missing branches"
# Possibly incorporate additional handling logic here (e.g.,notifications or retries)