Skip to content

Commit 10674c0

Browse files
authored
Merge pull request #251 from jrchamp/gha_use_cancelled
ci examples: use !cancelled() instead of always()
2 parents 288c8da + 8407184 commit 10674c0

File tree

4 files changed

+34
-24
lines changed

4 files changed

+34
-24
lines changed

docs/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ This project adheres to [Semantic Versioning](http://semver.org/).
99
The format of this change log follows the advice given at [Keep a CHANGELOG](http://keepachangelog.com).
1010

1111
## [Unreleased]
12+
### Changed
13+
- ACTION SUGGESTED: If you are using GitHub Actions, it's recomended to use `!cancelled()` instead of `always()` for moodle-plugin-ci tests. Adding a final step that always returns failure when the workflow is cancelled will ensure that cancelled workflows are not marked as successful. For a working example, please reference the updated `gha.dist.yml` file.
14+
1215
## [4.1.8] - 2023-10-20
1316
### Changed
1417
- Updated project dependencies to current [moodle-cs](https://github.com/moodlehq/moodle-cs) version.
1518

1619
### Added
1720
- Added back the `selfupdate` command, that enables easy updates of the PHAR package. Note this is experimental and may show some warnings with PHP 8.x.
1821

19-
2022
## [4.1.7] - 2023-10-11
2123
### Changed
2224
- Updated project dependencies to current [moodle-local_ci](https://github.com/moodlehq/moodle-local_ci) version.

docs/CodeCoverage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Some examples follow:
5151
<!-- {% raw %} -->
5252
```yaml
5353
- name: PHPUnit tests
54-
if: ${{ always() }}
54+
if: ${{ !cancelled() }}
5555
run: |
5656
moodle-plugin-ci phpunit --coverage-clover
5757
moodle-plugin-ci coveralls-upload

docs/GHAFileExplained.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,49 +135,53 @@ jobs:
135135
# can be re-ordered or removed to your liking. And of course, you can
136136
# add any of your own custom steps.
137137
- name: PHP Lint
138-
if: ${{ always() }} # prevents CI run stopping if step failed.
138+
if: ${{ !cancelled() }} # prevents CI run stopping if step failed.
139139
run: moodle-plugin-ci phplint
140140

141141
- name: PHP Copy/Paste Detector
142142
continue-on-error: true # This step will show errors but will not fail
143-
if: ${{ always() }}
143+
if: ${{ !cancelled() }}
144144
run: moodle-plugin-ci phpcpd
145145

146146
- name: PHP Mess Detector
147147
continue-on-error: true
148-
if: ${{ always() }}
148+
if: ${{ !cancelled() }}
149149
run: moodle-plugin-ci phpmd
150150

151151
- name: Moodle Code Checker
152-
if: ${{ always() }}
152+
if: ${{ !cancelled() }}
153153
run: moodle-plugin-ci phpcs --max-warnings 0
154154

155155
- name: Moodle PHPDoc Checker
156-
if: ${{ always() }}
156+
if: ${{ !cancelled() }}
157157
run: moodle-plugin-ci phpdoc --max-warnings 0
158158

159159
- name: Validating
160-
if: ${{ always() }}
160+
if: ${{ !cancelled() }}
161161
run: moodle-plugin-ci validate
162162

163163
- name: Check upgrade savepoints
164-
if: ${{ always() }}
164+
if: ${{ !cancelled() }}
165165
run: moodle-plugin-ci savepoints
166166

167167
- name: Mustache Lint
168-
if: ${{ always() }}
168+
if: ${{ !cancelled() }}
169169
run: moodle-plugin-ci mustache
170170

171171
- name: Grunt
172-
if: ${{ always() }}
172+
if: ${{ !cancelled() }}
173173
run: moodle-plugin-ci grunt --max-lint-warnings 0
174174

175175
- name: PHPUnit tests
176-
if: ${{ always() }}
176+
if: ${{ !cancelled() }}
177177
run: moodle-plugin-ci phpunit
178178

179179
- name: Behat features
180-
if: ${{ always() }}
180+
if: ${{ !cancelled() }}
181181
run: moodle-plugin-ci behat --profile chrome
182+
183+
- name: Mark cancelled jobs as failed.
184+
if: ${{ cancelled() }}
185+
run: exit 1
182186
```
183187
<!-- {% endraw %} -->

gha.dist.yml

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,47 +66,51 @@ jobs:
6666
MOODLE_BRANCH: ${{ matrix.moodle-branch }}
6767

6868
- name: PHP Lint
69-
if: ${{ always() }}
69+
if: ${{ !cancelled() }}
7070
run: moodle-plugin-ci phplint
7171

7272
- name: PHP Copy/Paste Detector
7373
continue-on-error: true # This step will show errors but will not fail
74-
if: ${{ always() }}
74+
if: ${{ !cancelled() }}
7575
run: moodle-plugin-ci phpcpd
7676

7777
- name: PHP Mess Detector
7878
continue-on-error: true # This step will show errors but will not fail
79-
if: ${{ always() }}
79+
if: ${{ !cancelled() }}
8080
run: moodle-plugin-ci phpmd
8181

8282
- name: Moodle Code Checker
83-
if: ${{ always() }}
83+
if: ${{ !cancelled() }}
8484
run: moodle-plugin-ci phpcs --max-warnings 0
8585

8686
- name: Moodle PHPDoc Checker
87-
if: ${{ always() }}
87+
if: ${{ !cancelled() }}
8888
run: moodle-plugin-ci phpdoc --max-warnings 0
8989

9090
- name: Validating
91-
if: ${{ always() }}
91+
if: ${{ !cancelled() }}
9292
run: moodle-plugin-ci validate
9393

9494
- name: Check upgrade savepoints
95-
if: ${{ always() }}
95+
if: ${{ !cancelled() }}
9696
run: moodle-plugin-ci savepoints
9797

9898
- name: Mustache Lint
99-
if: ${{ always() }}
99+
if: ${{ !cancelled() }}
100100
run: moodle-plugin-ci mustache
101101

102102
- name: Grunt
103-
if: ${{ always() }}
103+
if: ${{ !cancelled() }}
104104
run: moodle-plugin-ci grunt --max-lint-warnings 0
105105

106106
- name: PHPUnit tests
107-
if: ${{ always() }}
107+
if: ${{ !cancelled() }}
108108
run: moodle-plugin-ci phpunit --fail-on-warning
109109

110110
- name: Behat features
111-
if: ${{ always() }}
111+
if: ${{ !cancelled() }}
112112
run: moodle-plugin-ci behat --profile chrome
113+
114+
- name: Mark cancelled jobs as failed.
115+
if: ${{ cancelled() }}
116+
run: exit 1

0 commit comments

Comments
 (0)