Skip to content

Commit a96e946

Browse files
committed
Update update-from-template.yml
Split into 2 jobs to help with expected executor starvation
1 parent dbbac68 commit a96e946

File tree

1 file changed

+36
-13
lines changed

1 file changed

+36
-13
lines changed

.github/workflows/update-from-template.yml

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ permissions:
3131
jobs:
3232
update:
3333
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 }}
3537
steps:
3638
- uses: actions/checkout@v4
3739
with:
@@ -169,20 +171,41 @@ jobs:
169171
gh_pr_up -B "${{ steps.manage-branches.outputs.base_branch }}" \
170172
--title "Update from template (auto-merged)" \
171173
--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"
172196
173197
- name: Checking if auto-merge for PR update_branch_merged can be done
174198
id: auto-merge-check
175-
if: steps.manage-branches.outputs.create_update_branch_merged_pr == 1
176199
env:
177200
GH_TOKEN: ${{ secrets.UPDATE_FROM_TEMPLATE_PAT }}
178201
run: |
179202
not_failed_conclusion="skipped|neutral|success"
180203
not_relevant_app_slug="dependabot|github-pages"
181204
182-
echo "Waiting for workflows to start..."
183-
sleep 60s
205+
echo "Waiting for checks to start..."
206+
sleep 40s
184207
185-
for i in {1..15}; do
208+
for i in {1..20}; do
186209
echo "Checking if PR can be auto-merged. Try: $i"
187210
188211
echo "Fetching checks"
@@ -193,7 +216,7 @@ jobs:
193216
-H "Accept: application/vnd.github+json" \
194217
-H "Authorization: Bearer $GH_TOKEN" \
195218
-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)
197220
198221
cs_data=$(echo $cs_response | jq '.check_suites[] | { conclusion: .conclusion, slug: .app.slug, check_runs_url: .check_runs_url }')
199222
echo $cs_data
@@ -228,7 +251,7 @@ jobs:
228251
fi
229252
230253
echo "Waiting before next run..."
231-
sleep 60s
254+
sleep 30s
232255
done
233256
234257
echo "Timed out"
@@ -237,14 +260,14 @@ jobs:
237260
- name: Auto-merge update_branch_merged
238261
if: steps.auto-merge-check.outputs.perform == 1
239262
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"
243266
244267
echo "Fetching..."
245268
git fetch
246269
247-
expected_commit="${{ steps.manage-branches.outputs.update_branch_merged_commit }}"
270+
expected_commit="${{ needs.update.outputs.update_branch_merged_commit }}"
248271
actual_commit=$(git rev-parse origin/${{ env.UPDATE_BRANCH_MERGED }})
249272
if [[ "$expected_commit" != "$actual_commit" ]]; then
250273
echo "Branch ${{ env.UPDATE_BRANCH_MERGED }} contains unexpected commit $actual_commit"
@@ -256,8 +279,8 @@ jobs:
256279
echo "Ensuring that current branch $base_branch is up-to-date"
257280
git pull
258281
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=$?
261284
if [ $merge_exit_code -ne 0 ]; then
262285
echo "Unexpected merge failure $merge_exit_code - Requires manual resolution"
263286

0 commit comments

Comments
 (0)