Skip to content

Commit 7fca842

Browse files
authored
Merge pull request #971 from ehuss/merge-queue-workflow
Prepare CI workflows to support merge queues.
2 parents 3cc9c3c + ac827bb commit 7fca842

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

.github/workflows/main.yml

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
name: CI
2-
on: [push, pull_request]
2+
on:
3+
pull_request:
4+
merge_group:
35

46
jobs:
57
test:
@@ -42,3 +44,43 @@ jobs:
4244
- name: Install Rust
4345
run: rustup update stable && rustup default stable && rustup component add rustfmt
4446
- run: cargo fmt -- --check
47+
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.
65+
success:
66+
name: Success gate
67+
runs-on: ubuntu-latest
68+
needs:
69+
- test
70+
- rustfmt
71+
if: "success()"
72+
steps:
73+
- name: mark the job as a success
74+
run: echo success
75+
failure:
76+
name: Failure gate
77+
runs-on: ubuntu-latest
78+
needs:
79+
- test
80+
- rustfmt
81+
if: "!success()"
82+
steps:
83+
- name: mark the job as a failure
84+
run: |
85+
echo One or more jobs failed
86+
exit 1

0 commit comments

Comments
 (0)