Skip to content

Commit eeff7b6

Browse files
ci: cancel in-progress jobs immediately when a sibling fails
GitHub does not automatically abort running parallel jobs when one fails — they keep running until completion, which wastes runner time on long builds and tests. Add a cancel sentinel job for each workflow job. Each sentinel depends only on its paired job (`needs: [invoke-X]`) and runs `if: failure()`, so it starts the moment that job fails. It then calls the GitHub API to cancel the entire workflow run, stopping all other in-progress jobs. Fixes #5534
1 parent 8b52257 commit eeff7b6

File tree

1 file changed

+155
-0
lines changed

1 file changed

+155
-0
lines changed

.github/workflows/ci.yml

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,161 @@ jobs:
7070
environment: ci
7171
secrets: inherit
7272

73+
# GitHub doesn't cancel in-progress sibling jobs when one job fails — they keep running
74+
# until they finish, which wastes runner time when a build or test fails early.
75+
# The jobs below work around this: each one watches a single upstream job and, if that
76+
# job fails, immediately cancels the entire workflow run so everything else stops too.
77+
78+
cancel-if-build-rust-failed:
79+
name: Cancel if Rust Build Failed
80+
needs: [invoke-build-rust]
81+
if: failure()
82+
runs-on: ubuntu-latest-amd64
83+
permissions:
84+
actions: write
85+
steps:
86+
- name: Cancel workflow
87+
run: |
88+
curl -fsSL -X POST \
89+
-H "Authorization: Bearer ${{ github.token }}" \
90+
-H "Accept: application/vnd.github+json" \
91+
"https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/cancel"
92+
93+
cancel-if-build-java-failed:
94+
name: Cancel if Java Build Failed
95+
needs: [invoke-build-java]
96+
if: failure()
97+
runs-on: ubuntu-latest-amd64
98+
permissions:
99+
actions: write
100+
steps:
101+
- name: Cancel workflow
102+
run: |
103+
curl -fsSL -X POST \
104+
-H "Authorization: Bearer ${{ github.token }}" \
105+
-H "Accept: application/vnd.github+json" \
106+
"https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/cancel"
107+
108+
cancel-if-build-docs-failed:
109+
name: Cancel if Docs Build Failed
110+
needs: [invoke-build-docs]
111+
if: failure()
112+
runs-on: ubuntu-latest-amd64
113+
permissions:
114+
actions: write
115+
steps:
116+
- name: Cancel workflow
117+
run: |
118+
curl -fsSL -X POST \
119+
-H "Authorization: Bearer ${{ github.token }}" \
120+
-H "Accept: application/vnd.github+json" \
121+
"https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/cancel"
122+
123+
cancel-if-tests-unit-failed:
124+
name: Cancel if Unit Tests Failed
125+
needs: [invoke-tests-unit]
126+
if: failure()
127+
runs-on: ubuntu-latest-amd64
128+
permissions:
129+
actions: write
130+
steps:
131+
- name: Cancel workflow
132+
run: |
133+
curl -fsSL -X POST \
134+
-H "Authorization: Bearer ${{ github.token }}" \
135+
-H "Accept: application/vnd.github+json" \
136+
"https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/cancel"
137+
138+
cancel-if-tests-adapter-failed:
139+
name: Cancel if Adapter Tests Failed
140+
needs: [invoke-tests-adapter]
141+
if: failure()
142+
runs-on: ubuntu-latest-amd64
143+
permissions:
144+
actions: write
145+
steps:
146+
- name: Cancel workflow
147+
run: |
148+
curl -fsSL -X POST \
149+
-H "Authorization: Bearer ${{ github.token }}" \
150+
-H "Accept: application/vnd.github+json" \
151+
"https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/cancel"
152+
153+
cancel-if-build-docker-failed:
154+
name: Cancel if Docker Build Failed
155+
needs: [invoke-build-docker]
156+
if: failure()
157+
runs-on: ubuntu-latest-amd64
158+
permissions:
159+
actions: write
160+
steps:
161+
- name: Cancel workflow
162+
run: |
163+
curl -fsSL -X POST \
164+
-H "Authorization: Bearer ${{ github.token }}" \
165+
-H "Accept: application/vnd.github+json" \
166+
"https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/cancel"
167+
168+
cancel-if-tests-integration-platform-failed:
169+
name: Cancel if Platform Integration Tests Failed
170+
needs: [invoke-tests-integration-platform]
171+
if: failure()
172+
runs-on: ubuntu-latest-amd64
173+
permissions:
174+
actions: write
175+
steps:
176+
- name: Cancel workflow
177+
run: |
178+
curl -fsSL -X POST \
179+
-H "Authorization: Bearer ${{ github.token }}" \
180+
-H "Accept: application/vnd.github+json" \
181+
"https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/cancel"
182+
183+
cancel-if-tests-integration-runtime-failed:
184+
name: Cancel if Runtime Integration Tests Failed
185+
needs: [invoke-tests-integration-runtime]
186+
if: failure()
187+
runs-on: ubuntu-latest-amd64
188+
permissions:
189+
actions: write
190+
steps:
191+
- name: Cancel workflow
192+
run: |
193+
curl -fsSL -X POST \
194+
-H "Authorization: Bearer ${{ github.token }}" \
195+
-H "Accept: application/vnd.github+json" \
196+
"https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/cancel"
197+
198+
cancel-if-tests-java-failed:
199+
name: Cancel if Java Tests Failed
200+
needs: [invoke-tests-java]
201+
if: failure()
202+
runs-on: ubuntu-latest-amd64
203+
permissions:
204+
actions: write
205+
steps:
206+
- name: Cancel workflow
207+
run: |
208+
curl -fsSL -X POST \
209+
-H "Authorization: Bearer ${{ github.token }}" \
210+
-H "Accept: application/vnd.github+json" \
211+
"https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/cancel"
212+
213+
cancel-if-publish-crates-dry-run-failed:
214+
name: Cancel if Publish Crates Dry Run Failed
215+
needs: [invoke-publish-crates-dry-run]
216+
if: failure()
217+
runs-on: ubuntu-latest-amd64
218+
permissions:
219+
actions: write
220+
steps:
221+
- name: Cancel workflow
222+
run: |
223+
curl -fsSL -X POST \
224+
-H "Authorization: Bearer ${{ github.token }}" \
225+
-H "Accept: application/vnd.github+json" \
226+
"https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/cancel"
227+
73228
# This job needs to be called main (the same as the ci-pre-mergequeue.yml workflow)
74229
# because of how merge queues work: https://stackoverflow.com/a/78030618
75230
# and https://github.com/orgs/community/discussions/103114

0 commit comments

Comments
 (0)