Skip to content

Commit c0bc04b

Browse files
committed
Replace super-linter with a reusable workflow
1 parent 5b35ab7 commit c0bc04b

File tree

1 file changed

+133
-132
lines changed

1 file changed

+133
-132
lines changed

.github/workflows/php.yml

Lines changed: 133 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -13,51 +13,62 @@ on: # yamllint disable-line rule:truthy
1313
- '**.md'
1414

1515
jobs:
16+
phplinter:
17+
name: 'PHP-Linter'
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
php-version: ['8.1', '8.2', '8.3', '8.4']
22+
23+
uses: simplesamlphp/simplesamlphp-test-framework/.github/workflows/reusable_phplinter.yml@v1.9.2
24+
with:
25+
php-version: ${{ matrix.php-version }}
26+
1627
linter:
17-
name: Linter
18-
runs-on: ['ubuntu-latest']
28+
name: 'Linter'
29+
strategy:
30+
fail-fast: false
1931

20-
steps:
21-
- uses: actions/checkout@v4
22-
with:
23-
fetch-depth: 0
24-
25-
- name: Lint Code Base
26-
uses: super-linter/super-linter/slim@v7
27-
env:
28-
SAVE_SUPER_LINTER_OUTPUT: false
29-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30-
LINTER_RULES_PATH: 'tools/linters'
31-
LOG_LEVEL: NOTICE
32-
VALIDATE_ALL_CODEBASE: true
33-
VALIDATE_CSS: true
34-
VALIDATE_JAVASCRIPT_ES: true
35-
VALIDATE_JSON: true
36-
VALIDATE_PHP_BUILTIN: true
37-
VALIDATE_YAML: true
38-
VALIDATE_XML: true
39-
VALIDATE_GITHUB_ACTIONS: true
40-
FILTER_REGEX_EXCLUDE: 'public/**'
32+
uses: simplesamlphp/simplesamlphp-test-framework/.github/workflows/reusable_linter.yml@v1.9.2
33+
with:
34+
enable_eslinter: true
35+
enable_jsonlinter: true
36+
enable_stylelinter: false
37+
enable_yamllinter: true
4138

42-
quality:
43-
name: Quality control
44-
runs-on: [ubuntu-latest]
39+
unit-tests-linux:
40+
name: "Unit tests, PHP ${{ matrix.php-versions }}, ${{ matrix.operating-system }}"
41+
runs-on: ${{ matrix.operating-system }}
42+
needs: [phplinter, linter]
43+
44+
strategy:
45+
fail-fast: false
46+
matrix:
47+
operating-system: [ubuntu-latest]
48+
php-versions: ['8.1', '8.2', '8.3']
4549

4650
steps:
4751
- name: Setup PHP, with composer and extensions
48-
id: setup-php
4952
# https://github.com/shivammathur/setup-php
5053
uses: shivammathur/setup-php@v2
5154
with:
52-
# Should be the higest supported version, so we can use the newest tools
53-
php-version: '8.3'
54-
tools: composer, composer-require-checker, composer-unused, phpcs, psalm
55-
# optional performance gain for psalm: opcache
56-
extensions: ctype, date, dom, fileinfo, filter, hash, intl, mbstring, opcache, openssl, pcre, spl, xml
55+
php-version: ${{ matrix.php-versions }}
56+
extensions: ctype, date, dom, fileinfo, filter, hash, intl, mbstring, openssl, pcre, spl, xml
57+
tools: composer
58+
ini-values: error_reporting=E_ALL
59+
coverage: pcov
5760

5861
- name: Setup problem matchers for PHP
5962
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
6063

64+
- name: Setup problem matchers for PHPUnit
65+
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
66+
67+
- name: Set git to use LF
68+
run: |
69+
git config --global core.autocrlf false
70+
git config --global core.eol lf
71+
6172
- uses: actions/checkout@v4
6273

6374
- name: Get composer cache directory
@@ -70,64 +81,61 @@ jobs:
7081
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
7182
restore-keys: ${{ runner.os }}-composer-
7283

73-
- name: Validate composer.json and composer.lock
74-
run: composer validate
75-
7684
- name: Install Composer dependencies
7785
run: composer install --no-progress --prefer-dist --optimize-autoloader
7886

79-
- name: Check code for hard dependencies missing in composer.json
80-
run: composer-require-checker check --config-file=tools/composer-require-checker.json composer.json
81-
82-
- name: Check code for unused dependencies in composer.json
83-
run: composer-unused
87+
- name: Run unit tests with coverage
88+
if: ${{ matrix.php-versions == '8.3' }}
89+
run: vendor/bin/phpunit
8490

85-
- name: PHP Code Sniffer
86-
run: phpcs
91+
- name: Run unit tests (no coverage)
92+
if: ${{ matrix.php-versions != '8.3' }}
93+
run: vendor/bin/phpunit --no-coverage
8794

88-
- name: Psalm
89-
continue-on-error: true
90-
run: |
91-
psalm -c psalm.xml \
92-
--show-info=true \
93-
--shepherd \
94-
--php-version=${{ steps.setup-php.outputs.php-version }}
95+
- name: Save coverage data
96+
if: ${{ matrix.php-versions == '8.3' }}
97+
uses: actions/upload-artifact@v4
98+
with:
99+
name: coverage-data
100+
path: ${{ github.workspace }}/build
95101

96-
- name: Psalm (testsuite)
97-
run: |
98-
psalm -c psalm-dev.xml \
99-
--show-info=true \
100-
--shepherd \
101-
--php-version=${{ steps.setup-php.outputs.php-version }}
102+
unit-tests-windows:
103+
name: "Unit tests, PHP ${{ matrix.php-versions }}, ${{ matrix.operating-system }}"
104+
runs-on: ${{ matrix.operating-system }}
105+
needs: [phplinter, linter]
102106

103-
- name: Psalter
104-
run: |
105-
psalm --alter \
106-
--issues=UnnecessaryVarAnnotation \
107-
--dry-run \
108-
--php-version=${{ steps.setup-php.outputs.php-version }}
107+
strategy:
108+
fail-fast: true
109+
matrix:
110+
operating-system: [windows-latest]
111+
php-versions: ['8.1', '8.2', '8.3']
109112

110-
security:
111-
name: Security checks
112-
runs-on: [ubuntu-latest]
113113
steps:
114114
- name: Setup PHP, with composer and extensions
115115
# https://github.com/shivammathur/setup-php
116116
uses: shivammathur/setup-php@v2
117117
with:
118-
# Should be the lowest supported version
119-
php-version: '8.1'
118+
php-version: ${{ matrix.php-versions }}
120119
extensions: ctype, date, dom, fileinfo, filter, hash, intl, mbstring, openssl, pcre, spl, xml
121120
tools: composer
121+
ini-values: error_reporting=E_ALL
122122
coverage: none
123123

124124
- name: Setup problem matchers for PHP
125125
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
126126

127+
- name: Setup problem matchers for PHPUnit
128+
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
129+
130+
- name: Set git to use LF
131+
run: |
132+
git config --global core.autocrlf false
133+
git config --global core.eol lf
134+
127135
- uses: actions/checkout@v4
128136

129137
- name: Get composer cache directory
130-
run: echo COMPOSER_CACHE="$(composer config cache-files-dir)" >> "$GITHUB_ENV"
138+
run: echo COMPOSER_CACHE="$(composer config cache-files-dir)" >> "$env:GITHUB_ENV"
131139

132140
- name: Cache composer dependencies
133141
uses: actions/cache@v4
@@ -139,47 +147,28 @@ jobs:
139147
- name: Install Composer dependencies
140148
run: composer install --no-progress --prefer-dist --optimize-autoloader
141149

142-
- name: Security check for locked dependencies
143-
run: composer audit
144-
145-
- name: Update Composer dependencies
146-
run: composer update --no-progress --prefer-dist --optimize-autoloader
147-
148-
- name: Security check for updated dependencies
149-
run: composer audit
150-
151-
unit-tests-linux:
152-
name: "Unit tests, PHP ${{ matrix.php-versions }}, ${{ matrix.operating-system }}"
153-
runs-on: ${{ matrix.operating-system }}
154-
needs: [linter, quality, security]
155-
strategy:
156-
fail-fast: false
157-
matrix:
158-
operating-system: [ubuntu-latest]
159-
php-versions: ['8.1', '8.2', '8.3']
150+
- name: Run unit tests
151+
run: vendor/bin/phpunit --no-coverage
160152

153+
quality:
154+
name: Quality control
155+
runs-on: [ubuntu-latest]
156+
161157
steps:
162158
- name: Setup PHP, with composer and extensions
159+
id: setup-php
163160
# https://github.com/shivammathur/setup-php
164161
uses: shivammathur/setup-php@v2
165162
with:
166-
php-version: ${{ matrix.php-versions }}
167-
extensions: ctype, date, dom, fileinfo, filter, hash, intl, mbstring, openssl, pcre, spl, xml
168-
tools: composer
169-
ini-values: error_reporting=E_ALL
170-
coverage: pcov
163+
# Should be the higest supported version, so we can use the newest tools
164+
php-version: '8.3'
165+
tools: composer, composer-require-checker, composer-unused, phpcs, psalm
166+
# optional performance gain for psalm: opcache
167+
extensions: ctype, date, dom, fileinfo, filter, hash, intl, mbstring, opcache, openssl, pcre, spl, xml
171168

172169
- name: Setup problem matchers for PHP
173170
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
174171

175-
- name: Setup problem matchers for PHPUnit
176-
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
177-
178-
- name: Set git to use LF
179-
run: |
180-
git config --global core.autocrlf false
181-
git config --global core.eol lf
182-
183172
- uses: actions/checkout@v4
184173

185174
- name: Get composer cache directory
@@ -192,60 +181,66 @@ jobs:
192181
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
193182
restore-keys: ${{ runner.os }}-composer-
194183

184+
- name: Validate composer.json and composer.lock
185+
run: composer validate
186+
195187
- name: Install Composer dependencies
196188
run: composer install --no-progress --prefer-dist --optimize-autoloader
197189

198-
- name: Run unit tests with coverage
199-
if: ${{ matrix.php-versions == '8.3' }}
200-
run: vendor/bin/phpunit
190+
- name: Check code for hard dependencies missing in composer.json
191+
run: composer-require-checker check --config-file=tools/composer-require-checker.json composer.json
201192

202-
- name: Run unit tests (no coverage)
203-
if: ${{ matrix.php-versions != '8.3' }}
204-
run: vendor/bin/phpunit --no-coverage
193+
- name: Check code for unused dependencies in composer.json
194+
run: composer-unused
205195

206-
- name: Save coverage data
207-
if: ${{ matrix.php-versions == '8.3' }}
208-
uses: actions/upload-artifact@v4
209-
with:
210-
name: coverage-data
211-
path: ${{ github.workspace }}/build
196+
- name: PHP Code Sniffer
197+
run: phpcs
212198

213-
unit-tests-windows:
214-
name: "Unit tests, PHP ${{ matrix.php-versions }}, ${{ matrix.operating-system }}"
215-
runs-on: ${{ matrix.operating-system }}
216-
needs: [linter, quality, security]
217-
strategy:
218-
fail-fast: true
219-
matrix:
220-
operating-system: [windows-latest]
221-
php-versions: ['8.1', '8.2', '8.3']
199+
- name: Psalm
200+
continue-on-error: true
201+
run: |
202+
psalm -c psalm.xml \
203+
--show-info=true \
204+
--shepherd \
205+
--php-version=${{ steps.setup-php.outputs.php-version }}
206+
207+
- name: Psalm (testsuite)
208+
run: |
209+
psalm -c psalm-dev.xml \
210+
--show-info=true \
211+
--shepherd \
212+
--php-version=${{ steps.setup-php.outputs.php-version }}
213+
214+
- name: Psalter
215+
run: |
216+
psalm --alter \
217+
--issues=UnnecessaryVarAnnotation \
218+
--dry-run \
219+
--php-version=${{ steps.setup-php.outputs.php-version }}
220+
221+
security:
222+
name: Security checks
223+
runs-on: [ubuntu-latest]
224+
needs: [unit-tests-linux]
222225

223226
steps:
224227
- name: Setup PHP, with composer and extensions
225228
# https://github.com/shivammathur/setup-php
226229
uses: shivammathur/setup-php@v2
227230
with:
228-
php-version: ${{ matrix.php-versions }}
231+
# Should be the lowest supported version
232+
php-version: '8.1'
229233
extensions: ctype, date, dom, fileinfo, filter, hash, intl, mbstring, openssl, pcre, spl, xml
230234
tools: composer
231-
ini-values: error_reporting=E_ALL
232235
coverage: none
233236

234237
- name: Setup problem matchers for PHP
235238
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
236239

237-
- name: Setup problem matchers for PHPUnit
238-
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
239-
240-
- name: Set git to use LF
241-
run: |
242-
git config --global core.autocrlf false
243-
git config --global core.eol lf
244-
245240
- uses: actions/checkout@v4
246241

247242
- name: Get composer cache directory
248-
run: echo COMPOSER_CACHE="$(composer config cache-files-dir)" >> "$env:GITHUB_ENV"
243+
run: echo COMPOSER_CACHE="$(composer config cache-files-dir)" >> "$GITHUB_ENV"
249244

250245
- name: Cache composer dependencies
251246
uses: actions/cache@v4
@@ -257,8 +252,14 @@ jobs:
257252
- name: Install Composer dependencies
258253
run: composer install --no-progress --prefer-dist --optimize-autoloader
259254

260-
- name: Run unit tests
261-
run: vendor/bin/phpunit --no-coverage
255+
- name: Security check for locked dependencies
256+
run: composer audit
257+
258+
- name: Update Composer dependencies
259+
run: composer update --no-progress --prefer-dist --optimize-autoloader
260+
261+
- name: Security check for updated dependencies
262+
run: composer audit
262263

263264
coverage:
264265
name: Code coverage

0 commit comments

Comments
 (0)