Skip to content

Commit 2334150

Browse files
committed
Unify outcome jobs
1 parent e27af29 commit 2334150

File tree

2 files changed

+26
-51
lines changed

2 files changed

+26
-51
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -152,49 +152,25 @@ jobs:
152152
AWS_ACCESS_KEY_ID: "${{ env.ARTIFACTS_AWS_ACCESS_KEY_ID }}"
153153
AWS_SECRET_ACCESS_KEY: "${{ secrets[format('AWS_SECRET_ACCESS_KEY_{0}', env.ARTIFACTS_AWS_ACCESS_KEY_ID)] }}"
154154
if: "success() && (github.event_name == 'push' || env.DEPLOY == '1' || env.DEPLOY_ALT == '1')"
155-
try-success:
156-
needs:
157-
- job
158-
if: "success() && github.event_name == 'push' && (github.ref == 'refs/heads/try' || github.ref == 'refs/heads/try-perf') && github.repository == 'rust-lang-ci/rust'"
159-
steps:
160-
- name: mark the job as a success
161-
run: exit 0
162-
shell: bash
163-
name: bors build finished
164-
runs-on: ubuntu-latest
165-
try-failure:
166-
needs:
167-
- job
168-
if: "!success() && github.event_name == 'push' && (github.ref == 'refs/heads/try' || github.ref == 'refs/heads/try-perf') && github.repository == 'rust-lang-ci/rust'"
169-
steps:
170-
- name: mark the job as a failure
171-
run: exit 1
172-
shell: bash
155+
outcome:
173156
name: bors build finished
174157
runs-on: ubuntu-latest
175-
auto-success:
176158
needs:
177159
- job
178-
if: "success() && github.event_name == 'push' && github.ref == 'refs/heads/auto' && github.repository == 'rust-lang-ci/rust'"
160+
if: "!cancelled() && github.event_name == 'push'"
179161
steps:
180162
- name: checkout the source code
181163
uses: actions/checkout@v4
182164
with:
183165
fetch-depth: 2
166+
- name: calculate the correct exit status
167+
id: status
168+
run: "jq --exit-status 'all(.result == \"success\" or .result == \"skipped\")' <<< '${{ toJson(needs) }}'\necho \"status=$?\" >> $GITHUB_OUTPUT\n"
184169
- name: publish toolstate
185170
run: src/ci/publish_toolstate.sh
186171
shell: bash
172+
if: "steps.outputs.status == 0 && github.event_name == 'push' && github.ref == 'refs/heads/auto' && github.repository == 'rust-lang-ci/rust'"
187173
env:
188174
TOOLSTATE_REPO_ACCESS_TOKEN: "${{ secrets.TOOLSTATE_REPO_ACCESS_TOKEN }}"
189-
name: bors build finished
190-
runs-on: ubuntu-latest
191-
auto-failure:
192-
needs:
193-
- job
194-
if: "!success() && github.event_name == 'push' && github.ref == 'refs/heads/auto' && github.repository == 'rust-lang-ci/rust'"
195-
steps:
196-
- name: mark the job as a failure
197-
run: exit 1
198-
shell: bash
199-
name: bors build finished
200-
runs-on: ubuntu-latest
175+
- name: set the correct exit status
176+
run: "exit ${{ steps.outputs.status == 0 }}"

src/ci/github-actions/ci.yml

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -270,33 +270,32 @@ jobs:
270270
# erroring about invalid credentials instead.
271271
if: success() && (github.event_name == 'push' || env.DEPLOY == '1' || env.DEPLOY_ALT == '1')
272272

273-
# These jobs don't actually test anything, but they're used to tell bors the
274-
# build completed, as there is no practical way to detect when a workflow is
275-
# successful listening to webhooks only.
276-
try-success:
277-
needs: [ job ]
278-
if: "success() && github.event_name == 'push' && (github.ref == 'refs/heads/try' || github.ref == 'refs/heads/try-perf') && github.repository == 'rust-lang-ci/rust'"
279-
<<: *base-success-job
280-
try-failure:
281-
needs: [ job ]
282-
if: "!success() && github.event_name == 'push' && (github.ref == 'refs/heads/try' || github.ref == 'refs/heads/try-perf') && github.repository == 'rust-lang-ci/rust'"
283-
<<: *base-failure-job
284-
auto-success:
273+
# This job isused to tell bors the final status of the build, as there is no practical way to detect
274+
# when a workflow is successful listening to webhooks only in our current bors implementation (homu).
275+
outcome:
276+
name: bors build finished
277+
runs-on: ubuntu-latest
285278
needs: [ job ]
286-
if: "success() && github.event_name == 'push' && github.ref == 'refs/heads/auto' && github.repository == 'rust-lang-ci/rust'"
287-
<<: *base-outcome-job
279+
# !cancelled() executes the job regardless of whether the previous jobs passed or failed
280+
if: "!cancelled() && github.event_name == 'push'"
288281
steps:
289282
- name: checkout the source code
290283
uses: actions/checkout@v4
291284
with:
292285
fetch-depth: 2
286+
# Calculate the exit status of the whole CI workflow (0 if all dependent jobs were either successful
287+
# or skipped, otherwise 1).
288+
- name: calculate the correct exit status
289+
id: status
290+
run: |
291+
jq --exit-status 'all(.result == "success" or .result == "skipped")' <<< '${{ toJson(needs) }}'
292+
echo "status=$?" >> $GITHUB_OUTPUT
293+
# Publish the toolstate if an auto build succeeds (just before push to master)
293294
- name: publish toolstate
294295
run: src/ci/publish_toolstate.sh
295296
shell: bash
297+
if: steps.outputs.status == 0 && github.event_name == 'push' && github.ref == 'refs/heads/auto' && github.repository == 'rust-lang-ci/rust'
296298
env:
297299
TOOLSTATE_REPO_ACCESS_TOKEN: ${{ secrets.TOOLSTATE_REPO_ACCESS_TOKEN }}
298-
299-
auto-failure:
300-
needs: [ job ]
301-
if: "!success() && github.event_name == 'push' && github.ref == 'refs/heads/auto' && github.repository == 'rust-lang-ci/rust'"
302-
<<: *base-failure-job
300+
- name: set the correct exit status
301+
run: exit ${{ steps.outputs.status }}

0 commit comments

Comments
 (0)