Skip to content

Commit fb53225

Browse files
committed
Use a better merge-queue success check.
1 parent 337c404 commit fb53225

File tree

1 file changed

+9
-32
lines changed

1 file changed

+9
-32
lines changed

.github/workflows/main.yml

+9-32
Original file line numberDiff line numberDiff line change
@@ -45,42 +45,19 @@ jobs:
4545
run: rustup update stable && rustup default stable && rustup component add rustfmt
4646
- run: cargo fmt -- --check
4747

48-
# These success/failure jobs are here to consolidate the total
49-
# success/failure state of all other jobs. These jobs are then included in
50-
# the GitHub branch protection rule which prevents merges unless all other
51-
# jobs are passing. This makes it easier to manage the list of jobs via this
52-
# yml file and to prevent accidentally adding new jobs without also updating
53-
# the branch protections.
54-
#
55-
# Unfortunately this requires two jobs because the branch protection
56-
# considers skipped jobs as successful. The status check functions like
57-
# success() can only be in an `if` condition.
58-
#
59-
# Beware that success() is false if any dependent job is skipped. See
60-
# https://github.com/orgs/community/discussions/45058. This means there
61-
# cannot be optional jobs. One workaround is to check for all other
62-
# statuses:
63-
# (contains(needs.*.result, 'cancelled') || contains(needs.*.result, 'skipped') || contains(needs.*.result, 'failure'))
64-
# but that is a mess.
48+
# The success job is here to consolidate the total success/failure state of
49+
# all other jobs. This job is then included in the GitHub branch protection
50+
# rule which prevents merges unless all other jobs are passing. This makes
51+
# it easier to manage the list of jobs via this yml file and to prevent
52+
# accidentally adding new jobs without also updating the branch protections.
6553
success:
6654
name: Success gate
67-
runs-on: ubuntu-latest
55+
if: always()
6856
needs:
6957
- test
7058
- rustfmt
71-
if: "success()"
72-
steps:
73-
- name: mark the job as a success
74-
run: echo success
75-
failure:
76-
name: Failure gate
7759
runs-on: ubuntu-latest
78-
needs:
79-
- test
80-
- rustfmt
81-
if: "!success()"
8260
steps:
83-
- name: mark the job as a failure
84-
run: |
85-
echo One or more jobs failed
86-
exit 1
61+
- run: jq --exit-status 'all(.result == "success")' <<< '${{ toJson(needs) }}'
62+
- name: Done
63+
run: exit 0

0 commit comments

Comments
 (0)