@@ -31,7 +31,9 @@ permissions:
3131jobs :
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,22 +171,50 @@ 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"
180- not_relevant_app_slug="dependabot|github-pages"
203+ not_relevant_app_slug="dependabot|github-pages|sonarcloud "
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
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+
188218 echo "Fetching checks"
189219 cs_response=$(curl -sL \
190220 --fail-with-body \
@@ -193,7 +223,7 @@ jobs:
193223 -H "Accept: application/vnd.github+json" \
194224 -H "Authorization: Bearer $GH_TOKEN" \
195225 -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)
197227
198228 cs_data=$(echo $cs_response | jq '.check_suites[] | { conclusion: .conclusion, slug: .app.slug, check_runs_url: .check_runs_url }')
199229 echo $cs_data
@@ -228,23 +258,27 @@ jobs:
228258 fi
229259
230260 echo "Waiting before next run..."
231- sleep 60s
261+ sleep 30s
232262 done
233263
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
236266
237267 - name : Auto-merge update_branch_merged
238268 if : steps.auto-merge-check.outputs.perform == 1
239269 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"
243273
244274 echo "Fetching..."
245275 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
246280
247- expected_commit="${{ steps.manage-branches .outputs.update_branch_merged_commit }}"
281+ expected_commit="${{ needs.update .outputs.update_branch_merged_commit }}"
248282 actual_commit=$(git rev-parse origin/${{ env.UPDATE_BRANCH_MERGED }})
249283 if [[ "$expected_commit" != "$actual_commit" ]]; then
250284 echo "Branch ${{ env.UPDATE_BRANCH_MERGED }} contains unexpected commit $actual_commit"
@@ -256,8 +290,8 @@ jobs:
256290 echo "Ensuring that current branch $base_branch is up-to-date"
257291 git pull
258292
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=$?
261295 if [ $merge_exit_code -ne 0 ]; then
262296 echo "Unexpected merge failure $merge_exit_code - Requires manual resolution"
263297
0 commit comments