Skip to content

Commit 944874d

Browse files
committed
GH Actions: tweak the way the PHPCS/WPCS versions are set
VIPCS now doesn't just have PHPCS and WPCS as dependencies for the sniffs and ruleset tests, but also PHPCSUtils, PHPCSExtra and VariableAnalysis and for those last three, the different versions which may be supported are not (yet) taken into account. Now, it could be argued that every single combination of the different versions of each of these dependencies should be tested, but that would make the matrix _huge_ to little added benefit. So, instead I'm proposing a slightly different strategy, which should still allow us to verify that things work correctly with enough confidence, while making the workflow maintenance less involved. The change I'm proposed in this commit takes advantage of the Composer `--prefer-lowest` option to achieve this. It basically sets the matrix up to test against a combination of all CS dependencies on their lowest supported version + on their stable/highest supported version. While at this time, the lowest and the stable versions are the same, this will not always be the case, so having the matrix set up this way allows for new releases of these CS dependencies automatically. In the original setup, the highest/stable version combi wasn't tested. Instead a combi using the `dev` version of the dependencies was used. To me, it makes sense to test against the `dev` versions as well, but I don't believe this needs to be done for the whole range of supported PHP versions. To that end, I've set up four extra jobs against select high/low PHP versions in the `test` workflow to test against a combination of all CS dependencies on their latest `dev` version. Note: I have not added the setup for testing against `dev` versions to the `quicktest` workflow. Also note that the workflows currently contain a toggle for installing the `lowest` versions with/without ignoring platform requirement. This toggle is needed for PHP 8.x due to the max supported PHPUnit version being PHPUnit 7.x. This toggle can be removed once upstream PR squizlabs/PHP_CodeSniffer 3803 has been merged.
1 parent 5f34bbe commit 944874d

File tree

2 files changed

+77
-46
lines changed

2 files changed

+77
-46
lines changed

.github/workflows/quicktest.yml

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,49 +27,30 @@ jobs:
2727
matrix:
2828
include:
2929
- php: '5.4'
30-
phpcs_version: 'dev-master'
31-
wpcs_version: '3.0.*'
30+
dependencies: 'stable'
3231
- php: '5.4'
33-
phpcs_version: '3.7.2'
34-
wpcs_version: '3.0.*'
32+
dependencies: 'lowest'
3533

3634
- php: 'latest'
37-
phpcs_version: 'dev-master'
38-
wpcs_version: '3.0.*'
35+
dependencies: 'stable'
3936
- php: 'latest'
40-
phpcs_version: '3.7.2'
41-
wpcs_version: '3.0.*'
37+
dependencies: 'lowest'
4238

43-
name: "QTest${{ matrix.phpcs_version == 'dev-master' && ' + Lint' || '' }}: PHP ${{ matrix.php }} - PHPCS ${{ matrix.phpcs_version }}"
39+
name: "QTest${{ matrix.dependencies == 'stable' && ' + Lint' || '' }}: PHP ${{ matrix.php }} - PHPCS ${{ matrix.dependencies }}"
4440

4541
steps:
4642
- name: Checkout code
4743
uses: actions/checkout@v3
4844

49-
# On stable PHPCS versions, allow for PHP deprecation notices.
50-
# Unit tests don't need to fail on those for stable releases where those issues won't get fixed anymore.
51-
- name: Setup ini config
52-
id: set_ini
53-
run: |
54-
if [[ "${{ matrix.phpcs_version }}" != "dev-master" ]]; then
55-
echo 'PHP_INI=error_reporting=E_ALL & ~E_DEPRECATED, display_errors=On' >> $GITHUB_OUTPUT
56-
else
57-
echo 'PHP_INI=error_reporting=-1, display_errors=On' >> $GITHUB_OUTPUT
58-
fi
59-
6045
- name: Set up PHP
6146
uses: shivammathur/setup-php@v2
6247
with:
6348
php-version: ${{ matrix.php }}
64-
ini-values: ${{ steps.set_ini.outputs.PHP_INI }}
49+
# With stable PHPCS dependencies, allow for PHP deprecation notices.
50+
# Unit tests shouldn't fail on those for stable releases where those issues won't get fixed anymore.
51+
ini-values: error_reporting=E_ALL & ~E_DEPRECATED, display_errors=On
6552
coverage: none
6653

67-
- name: 'Composer: set PHPCS version for tests'
68-
run: composer require squizlabs/php_codesniffer:"${{ matrix.phpcs_version }}" --no-update --no-scripts --no-interaction
69-
70-
- name: 'Composer: set WPCS version for tests'
71-
run: composer require wp-coding-standards/wpcs:"${{ matrix.wpcs_version }}" --no-update --no-scripts --no-interaction
72-
7354
# Install dependencies and handle caching in one go.
7455
# @link https://github.com/marketplace/actions/install-composer-dependencies
7556
- name: Install Composer dependencies - normal
@@ -88,11 +69,31 @@ jobs:
8869
composer-options: --ignore-platform-req=php+
8970
custom-cache-suffix: $(date -u "+%Y-%m")
9071

72+
- name: "Composer: downgrade PHPCS dependencies for tests (lowest)"
73+
if: ${{ matrix.php == '5.4' && matrix.dependencies == 'lowest' }}
74+
run: >
75+
composer update --prefer-lowest --no-scripts --no-interaction
76+
squizlabs/php_codesniffer
77+
phpcsstandards/phpcsutils
78+
phpcsstandards/phpcsextra
79+
sirbrillig/phpcs-variable-analysis
80+
wp-coding-standards/wpcs
81+
82+
- name: "Composer: downgrade PHPCS dependencies for tests (lowest) - with ignore platform"
83+
if: ${{ matrix.php == 'latest' && matrix.dependencies == 'lowest' }}
84+
run: >
85+
composer update --prefer-lowest --no-scripts --no-interaction --ignore-platform-req=php+
86+
squizlabs/php_codesniffer
87+
phpcsstandards/phpcsutils
88+
phpcsstandards/phpcsextra
89+
sirbrillig/phpcs-variable-analysis
90+
wp-coding-standards/wpcs
91+
9192
- name: Display PHPCS installed standards
9293
run: ./vendor/bin/phpcs -i
9394

9495
- name: Lint against parse errors
95-
if: matrix.phpcs_version == 'dev-master'
96+
if: matrix.dependencies == 'stable'
9697
run: ./bin/php-lint
9798

9899
- name: Run the unit tests

.github/workflows/test.yml

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -62,41 +62,47 @@ jobs:
6262
strategy:
6363
# Keys:
6464
# - php: The PHP versions to test against.
65-
# - phpcs_version: The PHPCS versions to test against.
65+
# - dependencies: The PHPCS dependencies versions to test against.
6666
# IMPORTANT: test runs shouldn't fail because of PHPCS being incompatible with a PHP version.
6767
# - PHPCS will run without errors on PHP 5.4 - 7.4 on any supported version.
6868
# - PHP 8.0 needs PHPCS 3.5.7+ to run without errors, and we require a higher minimum version.
6969
# - PHP 8.1 needs PHPCS 3.6.1+ to run without errors, but works best with 3.7.1+, and we require at least this minimum version.
70-
# - The `wpcs_version` key is added to allow additional test builds when multiple WPCS versions
71-
# would be supported. As, at this time, only the latest stable release of WPCS is supported,
72-
# no additional versions are included in the array.
7370
matrix:
7471
php: ['5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2']
75-
phpcs_version: ['3.7.2', 'dev-master']
76-
wpcs_version: ['3.0.*']
72+
dependencies: ['lowest', 'stable']
7773

7874
include:
75+
# Test against dev versions of all dependencies with select PHP versions for early detection of issues.
76+
- php: '5.4'
77+
dependencies: 'dev'
78+
- php: '7.0'
79+
dependencies: 'dev'
80+
- php: '7.4'
81+
dependencies: 'dev'
82+
- php: '8.2'
83+
dependencies: 'dev'
84+
85+
# Test against upcoming PHP version.
7986
- php: '8.3'
80-
phpcs_version: 'dev-master'
81-
wpcs_version: '3.0.*'
87+
dependencies: 'dev'
8288

83-
name: "Test: PHP ${{ matrix.php }} - PHPCS ${{ matrix.phpcs_version }} - WPCS ${{ matrix.wpcs_version }}"
89+
name: "Test: PHP ${{ matrix.php }} - PHPCS ${{ matrix.dependencies }}"
8490

8591
continue-on-error: ${{ matrix.php == '8.3' }}
8692

8793
steps:
8894
- name: Checkout code
8995
uses: actions/checkout@v3
9096

91-
# On stable PHPCS versions, allow for PHP deprecation notices.
97+
# With stable PHPCS dependencies, allow for PHP deprecation notices.
9298
# Unit tests don't need to fail on those for stable releases where those issues won't get fixed anymore.
9399
- name: Setup ini config
94100
id: set_ini
95101
run: |
96-
if [[ "${{ matrix.phpcs_version }}" != "dev-master" ]]; then
97-
echo 'PHP_INI=error_reporting=E_ALL & ~E_DEPRECATED' >> $GITHUB_OUTPUT
102+
if [[ "${{ matrix.dependencies }}" != "dev" ]]; then
103+
echo 'PHP_INI=error_reporting=E_ALL & ~E_DEPRECATED, display_errors=On' >> $GITHUB_OUTPUT
98104
else
99-
echo 'PHP_INI=error_reporting=-1' >> $GITHUB_OUTPUT
105+
echo 'PHP_INI=error_reporting=-1, display_errors=On' >> $GITHUB_OUTPUT
100106
fi
101107
102108
- name: Install PHP
@@ -106,11 +112,15 @@ jobs:
106112
ini-values: ${{ steps.set_ini.outputs.PHP_INI }}
107113
coverage: none
108114

109-
- name: 'Composer: set PHPCS version for tests'
110-
run: composer require squizlabs/php_codesniffer:"${{ matrix.phpcs_version }}" --no-update --no-scripts --no-interaction
111-
112-
- name: 'Composer: set WPCS version for tests'
113-
run: composer require wp-coding-standards/wpcs:"${{ matrix.wpcs_version }}" --no-update --no-scripts --no-interaction
115+
- name: "Composer: set PHPCS dependencies for tests (dev)"
116+
if: ${{ matrix.dependencies == 'dev' }}
117+
run: >
118+
composer require --no-update --no-scripts --no-interaction
119+
squizlabs/php_codesniffer:"dev-master"
120+
phpcsstandards/phpcsutils:"dev-develop"
121+
phpcsstandards/phpcsextra:"dev-develop"
122+
sirbrillig/phpcs-variable-analysis:"2.x"
123+
wp-coding-standards/wpcs:"dev-develop"
114124
115125
# Install dependencies and handle caching in one go.
116126
# @link https://github.com/marketplace/actions/install-composer-dependencies
@@ -130,6 +140,26 @@ jobs:
130140
composer-options: --ignore-platform-req=php+
131141
custom-cache-suffix: $(date -u "+%Y-%m")
132142

143+
- name: "Composer: downgrade PHPCS dependencies for tests (lowest)"
144+
if: ${{ ! startsWith( matrix.php, '8' ) && matrix.dependencies == 'lowest' }}
145+
run: >
146+
composer update --prefer-lowest --no-scripts --no-interaction
147+
squizlabs/php_codesniffer
148+
phpcsstandards/phpcsutils
149+
phpcsstandards/phpcsextra
150+
sirbrillig/phpcs-variable-analysis
151+
wp-coding-standards/wpcs
152+
153+
- name: "Composer: downgrade PHPCS dependencies for tests (lowest) - with ignore platform"
154+
if: ${{ startsWith( matrix.php, '8' ) && matrix.dependencies == 'lowest' }}
155+
run: >
156+
composer update --prefer-lowest --no-scripts --no-interaction --ignore-platform-req=php+
157+
squizlabs/php_codesniffer
158+
phpcsstandards/phpcsutils
159+
phpcsstandards/phpcsextra
160+
sirbrillig/phpcs-variable-analysis
161+
wp-coding-standards/wpcs
162+
133163
- name: Run the unit tests
134164
run: ./bin/unit-tests
135165

0 commit comments

Comments
 (0)