Skip to content

Commit b0880cd

Browse files
authored
Use and recommend !cancelled() instead of always() (#659)
GitHub docs recommend `!cancelled()` over `always()`.
1 parent 8113100 commit b0880cd

File tree

5 files changed

+23
-22
lines changed

5 files changed

+23
-22
lines changed

.github/actions/test/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ runs:
149149
shell: bash
150150

151151
- name: Upload Test Results
152-
if: always()
152+
if: (!cancelled())
153153
uses: actions/upload-artifact@v4
154154
with:
155155
name: Test Results (python-${{ inputs.python-version }}, ${{ inputs.os }})

.github/workflows/publish.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ jobs:
8787

8888
- name: Publish Test Results
8989
id: test-results
90-
if: always()
90+
if: (!cancelled())
9191
env:
9292
INPUT_GITHUB_TOKEN: ${{ github.token }}
9393
INPUT_CHECK_NAME: Test Results (Docker Image ${{ matrix.arch }})
@@ -214,7 +214,7 @@ jobs:
214214
name: SARIF ${{ matrix.arch }}
215215
path: ${{ steps.scan.outputs.sarif }}
216216
- name: Upload SARIF file
217-
if: always() && steps.scan.outputs.sarif != ''
217+
if: (!cancelled() && steps.scan.outputs.sarif != '')
218218
uses: github/codeql-action/upload-sarif@v3
219219
with:
220220
sarif_file: ${{ steps.scan.outputs.sarif }}
@@ -413,7 +413,7 @@ jobs:
413413

414414
- name: Publish Test Results (Bash)
415415
id: test-results-bash
416-
if: always() && steps.test-results.outcome != 'skipped'
416+
if: (!cancelled() && steps.test-results.outcome != 'skipped')
417417
uses: ./windows/bash
418418
with:
419419
check_name: Test Results (${{ matrix.os-label }} bash python ${{ matrix.python }})

.github/workflows/test-results.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ permissions: {}
1010
jobs:
1111
test-results:
1212
name: Test Results (reference)
13-
if: github.event.workflow_run.conclusion != 'skipped'
13+
if: github.event.workflow_run.conclusion == 'success' || github.event.workflow_run.conclusion == 'failure'
1414
runs-on: ubuntu-latest
1515
permissions:
1616
checks: write

README.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ or ![ARM Linux](misc/badge-arm.svg) self-hosted runners that support Docker:
2626
```yaml
2727
- name: Publish Test Results
2828
uses: EnricoMi/publish-unit-test-result-action@v2
29-
if: always()
29+
if: (!cancelled())
3030
with:
3131
files: |
3232
test-results/**/*.xml
@@ -40,7 +40,7 @@ Use this for ![macOS](misc/badge-macos.svg) (e.g. `runs-on: macos-latest`) runne
4040
```yaml
4141
- name: Publish Test Results
4242
uses: EnricoMi/publish-unit-test-result-action/macos@v2
43-
if: always()
43+
if: (!cancelled())
4444
with:
4545
files: …
4646
```
@@ -49,7 +49,7 @@ Use this for ![macOS](misc/badge-macos.svg) (e.g. `runs-on: macos-latest`) runne
4949
```yaml
5050
- name: Publish Test Results
5151
uses: EnricoMi/publish-unit-test-result-action/windows@v2
52-
if: always()
52+
if: (!cancelled())
5353
with:
5454
files: …
5555
```
@@ -58,7 +58,7 @@ For Windows **without PowerShell** installed, there is the Bash shell variant:
5858
```yaml
5959
- name: Publish Test Results
6060
uses: EnricoMi/publish-unit-test-result-action/windows/bash@v2
61-
if: always()
61+
if: (!cancelled())
6262
with:
6363
files: …
6464
```
@@ -67,7 +67,7 @@ For **self-hosted** Linux GitHub Actions runners **without Docker** installed, p
6767
```yaml
6868
- name: Publish Test Results
6969
uses: EnricoMi/publish-unit-test-result-action/linux@v2
70-
if: always()
70+
if: (!cancelled())
7171
with:
7272
files: …
7373
```
@@ -77,7 +77,8 @@ See the [notes on running this action as a non-Docker action](#running-as-a-non-
7777
If you see the `"Resource not accessible by integration"` error, you have to grant additional [permissions](#permissions), or
7878
[setup the support for pull requests from fork repositories and branches created by Dependabot](#support-fork-repositories-and-dependabot-branches).
7979

80-
The `if: always()` clause guarantees that this action always runs, even if earlier steps (e.g., the test step) in your workflow fail.
80+
The `if: (!cancelled())` clause guarantees that this action always runs, even if earlier steps (e.g., the test step) in your workflow fail,
81+
but not if the workflow was cancelled.
8182

8283
When run multiple times in one workflow, the [option](#configuration) `check_name` has to be set to a unique value for each instance.
8384
Otherwise, the multiple runs overwrite each other's results.
@@ -368,7 +369,7 @@ The `json` output of the action can be accessed through the expression `steps.<i
368369
- name: Publish Test Results
369370
uses: EnricoMi/publish-unit-test-result-action@v2
370371
id: test-results
371-
if: always()
372+
if: (!cancelled())
372373
with:
373374
files: "test-results/**/*.xml"
374375
@@ -548,7 +549,7 @@ jobs:
548549
run: python -m pytest test --junit-xml pytest.xml
549550
550551
- name: Upload Test Results
551-
if: always()
552+
if: (!cancelled())
552553
uses: actions/upload-artifact@v4
553554
with:
554555
name: Test Results (Python ${{ matrix.python-version }})
@@ -569,7 +570,7 @@ jobs:
569570
570571
# only needed for private repository
571572
issues: read
572-
if: always()
573+
if: (!cancelled())
573574
574575
steps:
575576
- name: Download Artifacts
@@ -625,7 +626,7 @@ Adjust the value of `path` to fit your setup:
625626

626627
```yaml
627628
- name: Upload Test Results
628-
if: always()
629+
if: (!cancelled())
629630
uses: actions/upload-artifact@v4
630631
with:
631632
name: Test Results
@@ -665,7 +666,7 @@ jobs:
665666
test-results:
666667
name: Test Results
667668
runs-on: ubuntu-latest
668-
if: github.event.workflow_run.conclusion != 'skipped'
669+
if: github.event.workflow_run.conclusion == 'success' || github.event.workflow_run.conclusion == 'failure'
669670
670671
permissions:
671672
checks: write
@@ -724,7 +725,7 @@ Add the event name to `check_name` to avoid different event types overwriting ea
724725
```yaml
725726
- name: Publish Test Results
726727
uses: EnricoMi/publish-unit-test-result-action@v2
727-
if: always()
728+
if: (!cancelled())
728729
with:
729730
check_name: "Test Results (${{ github.event.workflow_run.event || github.event_name }})"
730731
files: "test-results/**/*.xml"
@@ -737,7 +738,7 @@ Disabling the pull request comment mode (`"off"`) for events other than `pull_re
737738
```yaml
738739
- name: Publish Test Results
739740
uses: EnricoMi/publish-unit-test-result-action@v2
740-
if: always()
741+
if: (!cancelled())
741742
with:
742743
# set comment_mode to "always" for pull_request event, set to "off" for all other event types
743744
comment_mode: ${{ (github.event.workflow_run.event == 'pull_request' || github.event_name == 'pull_request') && 'always' || 'off' }}
@@ -759,7 +760,7 @@ steps:
759760
- name: Publish Test Results
760761
uses: EnricoMi/publish-unit-test-result-action@v2
761762
id: test-results
762-
if: always()
763+
if: (!cancelled())
763764
with:
764765
files: "test-results/**/*.xml"
765766
@@ -820,14 +821,14 @@ you have to copy files to a relative path first, and then use the relative path:
820821

821822
```yaml
822823
- name: Copy Test Results
823-
if: always()
824+
if: (!cancelled())
824825
run: |
825826
cp -Lpr /tmp/test-results test-results
826827
shell: bash
827828
828829
- name: Publish Test Results
829830
uses: EnricoMi/publish-unit-test-result-action@v2
830-
if: always()
831+
if: (!cancelled())
831832
with:
832833
files: |
833834
test-results/**/*.xml

misc/action/json-output/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ runs:
2020
jq .conclusion "${{ inputs.json_file }}"
2121
2222
- name: JSON output
23-
if: always()
23+
if: (!cancelled())
2424
env:
2525
TITLE: ${{ fromJSON( inputs.json ).title }}
2626
SUMMARY: ${{ fromJSON( inputs.json ).summary }}

0 commit comments

Comments
 (0)