@@ -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,22 +171,50 @@ 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 "111048771+xdev-gh-bot@users.noreply.github.com"
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
- not_relevant_app_slug="dependabot|github-pages"
203
+ not_relevant_app_slug="dependabot|github-pages|sonarcloud "
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
211
+ echo "Checking if update-branch-merged exists"
212
+ git fetch
213
+ if [[ $(git rev-parse origin/${{ env.UPDATE_BRANCH_MERGED }}) ]]; then
214
+ echo "Branch origin/${{ env.UPDATE_BRANCH_MERGED }} is missing"
215
+ exit 0
216
+ fi
217
+
188
218
echo "Fetching checks"
189
219
cs_response=$(curl -sL \
190
220
--fail-with-body \
@@ -193,7 +223,7 @@ jobs:
193
223
-H "Accept: application/vnd.github+json" \
194
224
-H "Authorization: Bearer $GH_TOKEN" \
195
225
-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)
226
+ https://api.github.com/repos/${{ github.repository }}/commits/${{ needs.update .outputs.update_branch_merged_commit }}/check-suites)
197
227
198
228
cs_data=$(echo $cs_response | jq '.check_suites[] | { conclusion: .conclusion, slug: .app.slug, check_runs_url: .check_runs_url }')
199
229
echo $cs_data
@@ -228,23 +258,27 @@ jobs:
228
258
fi
229
259
230
260
echo "Waiting before next run..."
231
- sleep 60s
261
+ sleep 30s
232
262
done
233
263
234
- echo "Timed out"
235
- echo "perform=0 " >> $GITHUB_OUTPUT
264
+ echo "Timed out - Assuming executor starvation - Forcing merge "
265
+ echo "perform=1 " >> $GITHUB_OUTPUT
236
266
237
267
- name : Auto-merge update_branch_merged
238
268
if : steps.auto-merge-check.outputs.perform == 1
239
269
run : |
240
- base_branch="${{ steps.manage-branches.outputs.base_branch }} "
241
- echo "Restoring base branch $base_branch"
242
- git checkout $base_branch
270
+ echo "Getting base branch "
271
+ base_branch=$(git branch --show-current)
272
+ echo "Base branch is $base_branch"
243
273
244
274
echo "Fetching..."
245
275
git fetch
276
+ if [[ $(git rev-parse origin/${{ env.UPDATE_BRANCH_MERGED }}) ]]; then
277
+ echo "Branch origin/${{ env.UPDATE_BRANCH_MERGED }} is missing"
278
+ exit 0
279
+ fi
246
280
247
- expected_commit="${{ steps.manage-branches .outputs.update_branch_merged_commit }}"
281
+ expected_commit="${{ needs.update .outputs.update_branch_merged_commit }}"
248
282
actual_commit=$(git rev-parse origin/${{ env.UPDATE_BRANCH_MERGED }})
249
283
if [[ "$expected_commit" != "$actual_commit" ]]; then
250
284
echo "Branch ${{ env.UPDATE_BRANCH_MERGED }} contains unexpected commit $actual_commit"
@@ -256,8 +290,8 @@ jobs:
256
290
echo "Ensuring that current branch $base_branch is up-to-date"
257
291
git pull
258
292
259
- echo "Merging ${{ env.UPDATE_BRANCH_MERGED }} into $base_branch"
260
- git merge ${{ env.UPDATE_BRANCH_MERGED }} && merge_exit_code=$? || merge_exit_code=$?
293
+ echo "Merging origin/ ${{ env.UPDATE_BRANCH_MERGED }} into $base_branch"
294
+ git merge origin/ ${{ env.UPDATE_BRANCH_MERGED }} && merge_exit_code=$? || merge_exit_code=$?
261
295
if [ $merge_exit_code -ne 0 ]; then
262
296
echo "Unexpected merge failure $merge_exit_code - Requires manual resolution"
263
297
0 commit comments