Skip to content

Commit 429ca06

Browse files
authored
Merge pull request #2140 from ehuss/merge-queue-workflow
Prepare CI workflows to support merge queues.
2 parents 581e502 + 0fbfc90 commit 429ca06

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

.github/workflows/main.yml

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
name: CI
22
on:
3-
push:
4-
branches-ignore: [master]
53
pull_request:
64
merge_group:
75

@@ -49,3 +47,43 @@ jobs:
4947
- name: Install Rust
5048
run: rustup update stable && rustup default stable && rustup component add rustfmt
5149
- run: cargo fmt --check
50+
51+
# These success/failure jobs are here to consolidate the total
52+
# success/failure state of all other jobs. These jobs are then included in
53+
# the GitHub branch protection rule which prevents merges unless all other
54+
# jobs are passing. This makes it easier to manage the list of jobs via this
55+
# yml file and to prevent accidentally adding new jobs without also updating
56+
# the branch protections.
57+
#
58+
# Unfortunately this requires two jobs because the branch protection
59+
# considers skipped jobs as successful. The status check functions like
60+
# success() can only be in an `if` condition.
61+
#
62+
# Beware that success() is false if any dependent job is skipped. See
63+
# https://github.com/orgs/community/discussions/45058. This means there
64+
# cannot be optional jobs. One workaround is to check for all other
65+
# statuses:
66+
# (contains(needs.*.result, 'cancelled') || contains(needs.*.result, 'skipped') || contains(needs.*.result, 'failure'))
67+
# but that is a mess.
68+
success:
69+
name: Success gate
70+
runs-on: ubuntu-latest
71+
needs:
72+
- test
73+
- rustfmt
74+
if: "success()"
75+
steps:
76+
- name: mark the job as a success
77+
run: echo success
78+
failure:
79+
name: Failure gate
80+
runs-on: ubuntu-latest
81+
needs:
82+
- test
83+
- rustfmt
84+
if: "!success()"
85+
steps:
86+
- name: mark the job as a failure
87+
run: |
88+
echo One or more jobs failed
89+
exit 1

0 commit comments

Comments
 (0)