Skip to content

Commit cae20bb

Browse files
committed
Adjusted pr-supervisor
1 parent 7ec8a4e commit cae20bb

1 file changed

Lines changed: 29 additions & 14 deletions

File tree

‎.github/workflows/pr-supervisor.yaml‎

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# We are using https://cli.github.com/manual/gh_pr_checks
33
# The aim is to ensure that conditionally triggered Yamato jobs are completed successfully before allowing merges
44

5-
# This job will be required in branch protection rules for develop, develop-2.0.0, develop-3.x.x, and release/* branches. It's only goal will be to ensure that Yamato jobs are completed successfully before allowing Pr to merge.
6-
# Note that conditional jobs will have 30s to show which is always the cas since they are showing up as soon as in distribution stage.
5+
# This job will be required in branch protection rules for develop and release/* branches. It's only goal will be to ensure that Yamato jobs are completed successfully before allowing Pr to merge.
6+
# Note that conditional jobs will have 30s to show which is always the case since they are showing up as soon as in distribution stage.
77

88
name: Yamato PR Supervisor
99

@@ -24,43 +24,58 @@ jobs:
2424
yamato-supervisor:
2525
runs-on: ubuntu-latest
2626
timeout-minutes: 720
27+
permissions:
28+
actions: read
29+
checks: read
30+
statuses: read
31+
pull-requests: read
32+
contents: read
2733
steps:
2834
- name: Checkout repository
29-
uses: actions/checkout@v7
35+
uses: actions/checkout@v4
36+
37+
3038
- name: Wait and Verify Yamato Job Status
3139
env:
32-
GH_TOKEN: ${{ secrets.GH_TOKEN }}
40+
GH_TOKEN: ${{ github.token }}
3341
PR_NUMBER: ${{ github.event.pull_request.number }}
3442
run: |
3543
set -e
36-
37-
44+
45+
3846
MAX_ATTEMPTS=$((12*60))
3947
INTERVAL=60
40-
48+
4149
sleep $INTERVAL
4250
for ((i=1;i<=MAX_ATTEMPTS;i++)); do
4351
echo "Polling PR checks (attempt $i/$MAX_ATTEMPTS)..."
52+
53+
# gh pr checks exits non-zero while checks are pending (8) or failing (1); we evaluate state ourselves, so don't let that abort the loop.
54+
checks=$(gh pr checks $PR_NUMBER --json name,state --jq '[ .[] | select(.name != "yamato-supervisor") ]') || true
4455
45-
# We want to watch for pending checks beside this check
46-
checks=$(gh pr checks $PR_NUMBER --json name,state --jq '[ .[] | select(.name != "yamato-supervisor") ]')
56+
if [[ -z "$checks" ]]; then
57+
echo "No non-supervisor checks reported yet; waiting..."
58+
sleep $INTERVAL
59+
continue
60+
fi
4761
4862
pending=$(echo "$checks" | jq '[.[] | select(.state == "PENDING")] | length')
4963
skipping=$(echo "$checks" | jq '[.[] | select(.state == "SKIPPED")] | length')
5064
passed=$(echo "$checks" | jq '[.[] | select(.state == "SUCCESS")] | length')
5165
failed=$(echo "$checks" | jq '[.[] | select(.state == "FAILURE")] | length')
52-
53-
echo "Pending checks: $pending, Skipping checks: $skipping", Passed checks: $passed, Failed checks: $failed
54-
66+
67+
echo "Pending checks: $pending; Skipping checks: $skipping, Passed checks: $passed, Failed checks: $failed"
68+
5569
if [[ "$failed" -gt 0 ]]; then
5670
echo "A check has failed! Failing fast."
71+
echo "If you rerun the job and everything is green then just rerun this job as well."
5772
exit 1
5873
fi
5974
6075
if [[ "$pending" -eq 0 ]] && [[ "$passed" -gt 0 ]]; then
6176
echo "All non-supervisor checks are completed!"
6277
exit 0
6378
fi
64-
79+
6580
sleep $INTERVAL
66-
done
81+
done

0 commit comments

Comments
 (0)