Skip to content

Commit d33a0e9

Browse files
committed
otp: add ruleset check in main.yaml
gh rulesets allow owners of the project to set which checks (jobs) must have completed successfully before allowing merging of a pull request. however, the current ruleset contains jobs that are optionally executed, meaning that they depend on a `if:` condition. Jobs in a ruleset are supposed to always be executed. This means that there are (at times) pull requests where one needs to skip the ruleset constraint because the job in the ruleset was simply skipped. To overcome this limitation, we write in `main.yaml` a new job that considers all jobs that should be checked for success, and consider skipped jobs as successful as well. Failed or cancelled jobs will be consider a failure.
1 parent ade6efa commit d33a0e9

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

.github/workflows/main.yaml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,50 @@ jobs:
321321
persist-credentials: false
322322
- name: Run zizmor
323323
uses: zizmorcore/zizmor-action@71321a20a9ded102f6e9ce5718a2fcec2c4f70d8 # ratchet:zizmorcore/zizmor-action@v0.5.2
324+
325+
# This job checks that the most important jobs are successful.
326+
# the use of conditionals, e.g., `if:` at the job level makes
327+
# the jobs included in the GH Settngs Ruleset to fail.
328+
# Instead of removing those jobs from being tested or letting
329+
# them fail, the script below marks as OK a skipped job.
330+
# a failed job is a failure, and an success job is success.
331+
ruleset-checker:
332+
name: Ruleset Checker
333+
runs-on: ubuntu-latest
334+
if: always()
335+
needs:
336+
- pack
337+
- build-macos
338+
- build-ios
339+
- build-windows
340+
- build-flavors
341+
- build
342+
- freebsd
343+
- openbsd
344+
- solaris
345+
- documentation
346+
- static
347+
- test
348+
- system-test
349+
- sbom
350+
- zizmor
351+
steps:
352+
- name: Check Ruleset Results
353+
shell: bash
354+
env:
355+
RESULTS: ${{ toJSON(needs) }}
356+
run: |
357+
failed=false
358+
while IFS= read -r entry; do
359+
name=$(echo "$entry" | jq -r '.[0]')
360+
result=$(echo "$entry" | jq -r '.[1]')
361+
if [[ "$result" == "failure" || "$result" == "cancelled" ]]; then
362+
echo "❌ Job '$name' was: $result"
363+
failed=true
364+
else
365+
echo "✅ Job '$name' was: $result"
366+
fi
367+
done < <(echo "$RESULTS" | jq -c 'to_entries[] | [.key, .value.result]')
368+
if [[ "$failed" == "true" ]]; then
369+
exit 1
370+
fi

0 commit comments

Comments
 (0)