Skip to content

Commit 6edacd3

Browse files
committed
Unify outcome jobs
1 parent e82c28d commit 6edacd3

File tree

2 files changed

+26
-51
lines changed

2 files changed

+26
-51
lines changed

.github/workflows/ci.yml

+8-32
Original file line numberDiff line numberDiff line change
@@ -151,45 +151,21 @@ jobs:
151151
AWS_ACCESS_KEY_ID: "${{ env.ARTIFACTS_AWS_ACCESS_KEY_ID }}"
152152
AWS_SECRET_ACCESS_KEY: "${{ secrets[format('AWS_SECRET_ACCESS_KEY_{0}', env.ARTIFACTS_AWS_ACCESS_KEY_ID)] }}"
153153
if: "success() && (github.event_name == 'push' || env.DEPLOY == '1' || env.DEPLOY_ALT == '1')"
154-
try-success:
155-
needs:
156-
- job
157-
if: "success() && github.event_name == 'push' && (github.ref == 'refs/heads/try' || github.ref == 'refs/heads/try-perf') && github.repository == 'rust-lang-ci/rust'"
158-
steps:
159-
- name: mark the job as a success
160-
run: exit 0
161-
shell: bash
162-
name: bors build finished
163-
runs-on: ubuntu-latest
164-
try-failure:
165-
needs:
166-
- job
167-
if: "!success() && github.event_name == 'push' && (github.ref == 'refs/heads/try' || github.ref == 'refs/heads/try-perf') && github.repository == 'rust-lang-ci/rust'"
168-
steps:
169-
- name: mark the job as a failure
170-
run: exit 1
171-
shell: bash
154+
outcome:
172155
name: bors build finished
173156
runs-on: ubuntu-latest
174-
auto-success:
175157
needs:
176158
- job
177-
if: "success() && github.event_name == 'push' && github.ref == 'refs/heads/auto' && github.repository == 'rust-lang-ci/rust'"
159+
if: "!cancelled() && github.event_name == 'push'"
178160
steps:
161+
- name: calculate the correct exit status
162+
id: status
163+
run: "jq --exit-status 'all(.result == \"success\" or .result == \"skipped\")' <<< '${{ toJson(needs) }}'\necho \"status=$?\" >> $GITHUB_OUTPUT\n"
179164
- name: publish toolstate
180165
run: src/ci/publish_toolstate.sh
181166
shell: bash
167+
if: "steps.outputs.status == 0 && github.event_name == 'push' && github.ref == 'refs/heads/auto' && github.repository == 'rust-lang-ci/rust'"
182168
env:
183169
TOOLSTATE_REPO_ACCESS_TOKEN: "${{ secrets.TOOLSTATE_REPO_ACCESS_TOKEN }}"
184-
name: bors build finished
185-
runs-on: ubuntu-latest
186-
auto-failure:
187-
needs:
188-
- job
189-
if: "!success() && github.event_name == 'push' && github.ref == 'refs/heads/auto' && github.repository == 'rust-lang-ci/rust'"
190-
steps:
191-
- name: mark the job as a failure
192-
run: exit 1
193-
shell: bash
194-
name: bors build finished
195-
runs-on: ubuntu-latest
170+
- name: set the correct exit status
171+
run: "exit ${{ steps.outputs.status == 0 }}"

src/ci/github-actions/ci.yml

+18-19
Original file line numberDiff line numberDiff line change
@@ -268,29 +268,28 @@ jobs:
268268
# erroring about invalid credentials instead.
269269
if: success() && (github.event_name == 'push' || env.DEPLOY == '1' || env.DEPLOY_ALT == '1')
270270

271-
# These jobs don't actually test anything, but they're used to tell bors the
272-
# build completed, as there is no practical way to detect when a workflow is
273-
# successful listening to webhooks only.
274-
try-success:
275-
needs: [ job ]
276-
if: "success() && github.event_name == 'push' && (github.ref == 'refs/heads/try' || github.ref == 'refs/heads/try-perf') && github.repository == 'rust-lang-ci/rust'"
277-
<<: *base-success-job
278-
try-failure:
279-
needs: [ job ]
280-
if: "!success() && github.event_name == 'push' && (github.ref == 'refs/heads/try' || github.ref == 'refs/heads/try-perf') && github.repository == 'rust-lang-ci/rust'"
281-
<<: *base-failure-job
282-
auto-success:
271+
# This job isused to tell bors the final status of the build, as there is no practical way to detect
272+
# when a workflow is successful listening to webhooks only in our current bors implementation (homu).
273+
outcome:
274+
name: bors build finished
275+
runs-on: ubuntu-latest
283276
needs: [ job ]
284-
if: "success() && github.event_name == 'push' && github.ref == 'refs/heads/auto' && github.repository == 'rust-lang-ci/rust'"
285-
<<: *base-outcome-job
277+
# !cancelled() executes the job regardless of whether the previous jobs passed or failed
278+
if: "!cancelled() && github.event_name == 'push'"
286279
steps:
280+
# Calculate the exit status of the whole CI workflow (0 if all dependent jobs were either successful
281+
# or skipped, otherwise 1).
282+
- name: calculate the correct exit status
283+
id: status
284+
run: |
285+
jq --exit-status 'all(.result == "success" or .result == "skipped")' <<< '${{ toJson(needs) }}'
286+
echo "status=$?" >> $GITHUB_OUTPUT
287+
# Publish the toolstate if an auto build succeeds (just before push to master)
287288
- name: publish toolstate
288289
run: src/ci/publish_toolstate.sh
289290
shell: bash
291+
if: steps.outputs.status == 0 && github.event_name == 'push' && github.ref == 'refs/heads/auto' && github.repository == 'rust-lang-ci/rust'
290292
env:
291293
TOOLSTATE_REPO_ACCESS_TOKEN: ${{ secrets.TOOLSTATE_REPO_ACCESS_TOKEN }}
292-
293-
auto-failure:
294-
needs: [ job ]
295-
if: "!success() && github.event_name == 'push' && github.ref == 'refs/heads/auto' && github.repository == 'rust-lang-ci/rust'"
296-
<<: *base-failure-job
294+
- name: set the correct exit status
295+
run: exit ${{ steps.outputs.status == 0 }}

0 commit comments

Comments
 (0)