Skip to content

Commit cfd45b1

Browse files
committed
Requirements check: use new exit code
Includes safeguarding the exit code via the `test-requirements-check.yml` workflow.
1 parent 547890b commit cfd45b1

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

.github/workflows/test-requirements-check.yml

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,14 @@ jobs:
142142
- name: Run the test
143143
id: check
144144
continue-on-error: true
145-
run: php "bin/${{ matrix.cmd }}" --version
145+
shell: bash
146+
run: |
147+
set +e
148+
php "bin/${{ matrix.cmd }}" --version
149+
exitcode="$?"
150+
echo "EXITCODE=$exitcode" >> "$GITHUB_OUTPUT"
151+
echo "Exitcode is: $exitcode"
152+
exit "$exitcode"
146153
147154
- name: Check the result of a successful test against expectation
148155
if: ${{ steps.check.outcome == 'success' && matrix.expect == 'fail' }}
@@ -152,6 +159,14 @@ jobs:
152159
if: ${{ steps.check.outcome != 'success' && matrix.expect == 'success' }}
153160
run: exit 1
154161

162+
- name: Verify the exit code is 0 when requirements are met
163+
if: ${{ matrix.expect == 'success' && steps.check.outputs.EXITCODE != 0 }}
164+
run: exit 1
165+
166+
- name: Verify the exit code is 64 when requirements are not met
167+
if: ${{ matrix.expect == 'fail' && steps.check.outputs.EXITCODE != 64 }}
168+
run: exit 1
169+
155170
build-phars:
156171
needs: lint
157172

@@ -199,7 +214,14 @@ jobs:
199214
- name: Run the test
200215
id: check
201216
continue-on-error: true
202-
run: php ${{ matrix.cmd }}.phar --version
217+
shell: bash
218+
run: |
219+
set +e
220+
php ${{ matrix.cmd }}.phar --version
221+
exitcode="$?"
222+
echo "EXITCODE=$exitcode" >> "$GITHUB_OUTPUT"
223+
echo "Exitcode is: $exitcode"
224+
exit "$exitcode"
203225
204226
- name: Check the result of a successful test against expectation
205227
if: ${{ steps.check.outcome == 'success' && matrix.expect == 'fail' }}
@@ -208,3 +230,11 @@ jobs:
208230
- name: Check the result of a failed test against expectation
209231
if: ${{ steps.check.outcome != 'success' && matrix.expect == 'success' }}
210232
run: exit 1
233+
234+
- name: Verify the exit code is 0 when requirements are met
235+
if: ${{ matrix.expect == 'success' && steps.check.outputs.EXITCODE != 0 }}
236+
run: exit 1
237+
238+
- name: Verify the exit code is 64 when requirements are not met
239+
if: ${{ matrix.expect == 'fail' && steps.check.outputs.EXITCODE != 64 }}
240+
run: exit 1

requirements.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
*/
3030
function checkRequirements()
3131
{
32-
$exitCode = 3;
32+
// IMPORTANT: Must stay in sync with the value of the `PHP_CodeSniffer\Util\ExitCode::REQUIREMENTS_NOT_MET` constant!
33+
$exitCode = 64;
3334

3435
// Check the PHP version.
3536
if (PHP_VERSION_ID < 70200) {

0 commit comments

Comments
 (0)