@@ -31,7 +31,9 @@ permissions:
31
31
jobs :
32
32
update :
33
33
runs-on : ubuntu-latest
34
-
34
+ outputs :
35
+ update_branch_merged_commit : ${{ steps.manage-branches.outputs.update_branch_merged_commit }}
36
+ create_update_branch_merged_pr : ${{ steps.manage-branches.outputs.create_update_branch_merged_pr }}
35
37
steps :
36
38
- uses : actions/checkout@v4
37
39
with :
@@ -169,20 +171,41 @@ jobs:
169
171
gh_pr_up -B "${{ steps.manage-branches.outputs.base_branch }}" \
170
172
--title "Update from template (auto-merged)" \
171
173
--body "An automated PR to sync changes from the template into this repo"
174
+
175
+ # Wait a moment so that checks of PR have higher prio than following job
176
+ sleep 3
177
+
178
+ # Split into two jobs to help with executor starvation
179
+ auto-merge :
180
+ needs : [update]
181
+ if : needs.update.outputs.create_update_branch_merged_pr == 1
182
+ runs-on : ubuntu-latest
183
+ steps :
184
+ - uses : actions/checkout@v4
185
+ with :
186
+ # Required because otherwise there are always changes detected when executing diff/rev-list
187
+ fetch-depth : 0
188
+ # If no PAT is used the following error occurs on a push:
189
+ # refusing to allow a GitHub App to create or update workflow `.github/workflows/xxx.yml` without `workflows` permission
190
+ token : ${{ secrets.UPDATE_FROM_TEMPLATE_PAT }}
191
+
192
+ - name : Init Git
193
+ run : |
194
+ git config --global user.email "[email protected] "
195
+ git config --global user.name "XDEV Bot"
172
196
173
197
- name : Checking if auto-merge for PR update_branch_merged can be done
174
198
id : auto-merge-check
175
- if : steps.manage-branches.outputs.create_update_branch_merged_pr == 1
176
199
env :
177
200
GH_TOKEN : ${{ secrets.UPDATE_FROM_TEMPLATE_PAT }}
178
201
run : |
179
202
not_failed_conclusion="skipped|neutral|success"
180
203
not_relevant_app_slug="dependabot|github-pages"
181
204
182
- echo "Waiting for workflows to start..."
183
- sleep 60s
205
+ echo "Waiting for checks to start..."
206
+ sleep 40s
184
207
185
- for i in {1..15 }; do
208
+ for i in {1..20 }; do
186
209
echo "Checking if PR can be auto-merged. Try: $i"
187
210
188
211
echo "Fetching checks"
@@ -193,7 +216,7 @@ jobs:
193
216
-H "Accept: application/vnd.github+json" \
194
217
-H "Authorization: Bearer $GH_TOKEN" \
195
218
-H "X-GitHub-Api-Version: 2022-11-28" \
196
- https://api.github.com/repos/${{ github.repository }}/commits/${{ steps.manage-branches .outputs.update_branch_merged_commit }}/check-suites)
219
+ https://api.github.com/repos/${{ github.repository }}/commits/${{ needs.update .outputs.update_branch_merged_commit }}/check-suites)
197
220
198
221
cs_data=$(echo $cs_response | jq '.check_suites[] | { conclusion: .conclusion, slug: .app.slug, check_runs_url: .check_runs_url }')
199
222
echo $cs_data
@@ -228,7 +251,7 @@ jobs:
228
251
fi
229
252
230
253
echo "Waiting before next run..."
231
- sleep 60s
254
+ sleep 30s
232
255
done
233
256
234
257
echo "Timed out"
@@ -237,14 +260,14 @@ jobs:
237
260
- name : Auto-merge update_branch_merged
238
261
if : steps.auto-merge-check.outputs.perform == 1
239
262
run : |
240
- base_branch="${{ steps.manage-branches.outputs.base_branch }} "
241
- echo "Restoring base branch $base_branch"
242
- git checkout $base_branch
263
+ echo "Getting base branch "
264
+ base_branch=$(git branch --show-current)
265
+ echo "Base branch is $base_branch"
243
266
244
267
echo "Fetching..."
245
268
git fetch
246
269
247
- expected_commit="${{ steps.manage-branches .outputs.update_branch_merged_commit }}"
270
+ expected_commit="${{ needs.update .outputs.update_branch_merged_commit }}"
248
271
actual_commit=$(git rev-parse origin/${{ env.UPDATE_BRANCH_MERGED }})
249
272
if [[ "$expected_commit" != "$actual_commit" ]]; then
250
273
echo "Branch ${{ env.UPDATE_BRANCH_MERGED }} contains unexpected commit $actual_commit"
@@ -256,8 +279,8 @@ jobs:
256
279
echo "Ensuring that current branch $base_branch is up-to-date"
257
280
git pull
258
281
259
- echo "Merging ${{ env.UPDATE_BRANCH_MERGED }} into $base_branch"
260
- git merge ${{ env.UPDATE_BRANCH_MERGED }} && merge_exit_code=$? || merge_exit_code=$?
282
+ echo "Merging origin/ ${{ env.UPDATE_BRANCH_MERGED }} into $base_branch"
283
+ git merge origin/ ${{ env.UPDATE_BRANCH_MERGED }} && merge_exit_code=$? || merge_exit_code=$?
261
284
if [ $merge_exit_code -ne 0 ]; then
262
285
echo "Unexpected merge failure $merge_exit_code - Requires manual resolution"
263
286
0 commit comments