-
-
Notifications
You must be signed in to change notification settings - Fork 0
353 lines (296 loc) · 10.8 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
name: CI
on:
push:
branches:
- main
pull_request:
workflow_call:
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
check-ci-runs:
name: Check previous runs
if: ${{ github.event_name != 'workflow_call' }}
runs-on: ubuntu-latest
outputs:
ci_required: ${{ steps.check-ci-runs.outputs.ci_required }}
steps:
- name: Check CI runs
id: check-ci-runs
uses: lkrms/check-ci-runs@v1
with:
ci_workflows: "CI,Release"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
format:
name: Check generated files and formatting
needs:
- check-ci-runs
if: ${{ (github.event_name == 'workflow_call' || needs.check-ci-runs.outputs.ci_required == 1) && !cancelled() && !failure() }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get Composer cache directory
id: get-composer-cache
shell: bash
run: printf 'cache_dir=%s\n' "$(composer config cache-files-dir)" >>"$GITHUB_OUTPUT"
- name: Cache PHP dependencies
uses: actions/cache@v4
with:
path: ${{ steps.get-composer-cache.outputs.cache_dir }}
key: composer-cache-${{ runner.os }}-${{ hashFiles('**/composer.json', '**/composer.lock') }}
restore-keys: composer-cache-${{ runner.os }}-
- name: Install PHP dependencies
run: composer install --no-interaction --no-progress
- name: Check generated files
run: scripts/generate.sh --check
- name: Run PHP CS Fixer
run: tools/php-cs-fixer check --diff --verbose
- name: Run pretty-php
run: bin/pretty-php --diff
phpstan:
name: PHPStan
needs:
- check-ci-runs
if: ${{ (github.event_name == 'workflow_call' || needs.check-ci-runs.outputs.ci_required == 1) && !cancelled() && !failure() }}
strategy:
fail-fast: false
matrix:
php-version:
- "8.4"
- "7.4"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup PHP and Composer
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
coverage: none
- name: Get Composer cache directory
id: get-composer-cache
shell: bash
run: printf 'cache_dir=%s\n' "$(composer config cache-files-dir)" >>"$GITHUB_OUTPUT"
- name: Cache PHP dependencies
uses: actions/cache@v4
with:
path: ${{ steps.get-composer-cache.outputs.cache_dir }}
key: composer-cache-${{ runner.os }}-${{ hashFiles('**/composer.json', '**/composer.lock') }}
restore-keys: composer-cache-${{ runner.os }}-
- name: Persist PHPStan cache
uses: actions/cache@v4
with:
path: build/cache/phpstan
key: phpstan-cache-${{ runner.os }}-${{ matrix.php-version }}-${{ github.run_id }}
restore-keys: phpstan-cache-${{ runner.os }}-${{ matrix.php-version }}-
- name: Install PHP dependencies
run: composer install --no-interaction --no-progress
- name: Run PHPStan
run: vendor/bin/phpstan
unit-tests:
name: PHPUnit tests
needs:
- check-ci-runs
if: ${{ (github.event_name == 'workflow_call' || needs.check-ci-runs.outputs.ci_required == 1) && !cancelled() && !failure() }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-latest
php-version:
- "8.4"
include:
- os: ubuntu-latest
php-version: "8.3"
- os: ubuntu-latest
php-version: "8.2"
- os: ubuntu-latest
php-version: "8.1"
- os: ubuntu-latest
php-version: "8.0"
- os: ubuntu-latest
php-version: "7.4"
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup PHP and Composer
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: none, ctype, dom, json, mbstring, openssl, tokenizer, xml, xmlwriter
coverage: pcov
- name: Get Composer cache directory
id: get-composer-cache
shell: bash
run: printf 'cache_dir=%s\n' "$(composer config cache-files-dir)" >>"$GITHUB_OUTPUT"
- name: Cache PHP dependencies
uses: actions/cache@v4
with:
path: ${{ steps.get-composer-cache.outputs.cache_dir }}
key: composer-cache-${{ runner.os }}-${{ hashFiles('**/composer.json', '**/composer.lock') }}
restore-keys: composer-cache-${{ runner.os }}-
- name: Install PHP dependencies
run: composer install --no-interaction --no-progress
- name: Run PHPUnit tests and generate code coverage report
id: run-phpunit-tests
shell: bash
run: |
php -dshort_open_tag=On vendor/bin/phpunit ${RUNNER_DEBUG+--debug} --no-coverage --coverage-clover=coverage.xml --log-junit=junit.xml && status=0 || status=$?
printf 'coverage_generated=%d\n' "$([[ -s coverage.xml ]] && echo 1 || echo 0)" >>"$GITHUB_OUTPUT"
printf 'results_generated=%d\n' "$([[ -s junit.xml ]] && echo 1 || echo 0)" >>"$GITHUB_OUTPUT"
(exit $status)
- name: Upload coverage to Codecov
if: ${{ !cancelled() && steps.run-phpunit-tests.outputs.coverage_generated == 1 }}
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: Upload test results to Codecov
if: ${{ !cancelled() && steps.run-phpunit-tests.outputs.results_generated == 1 }}
uses: codecov/test-results-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
build:
name: Build phar and man page
needs:
- check-ci-runs
- phpstan
- unit-tests
if: ${{ (github.event_name == 'workflow_call' || needs.check-ci-runs.outputs.ci_required == 1) && !cancelled() && !failure() }}
runs-on: ubuntu-latest
outputs:
artifact_name: ${{ steps.run-build-script.outputs.artifact_name }}
artifact_path: ${{ steps.run-build-script.outputs.artifact_path }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Pandoc
run: |
sudo apt-get update
sudo apt-get install pandoc
- name: Setup PHP and Composer
uses: shivammathur/setup-php@v2
with:
php-version: "8.3"
coverage: none
- name: Get Composer cache directory
id: get-composer-cache
shell: bash
run: printf 'cache_dir=%s\n' "$(composer config cache-files-dir)" >>"$GITHUB_OUTPUT"
- name: Cache PHP dependencies
uses: actions/cache@v4
with:
path: ${{ steps.get-composer-cache.outputs.cache_dir }}
key: composer-cache-${{ runner.os }}-${{ hashFiles('**/composer.json', '**/composer.lock') }}
restore-keys: composer-cache-${{ runner.os }}-
- name: Install PHP dependencies
run: composer install --no-interaction --no-progress
# Run the phar and man builds separately and together to test each code
# path in the build script
- name: Run build script
id: run-build-script
run: |
scripts/build.sh
scripts/build.sh man
scripts/build.sh man worktree
cd build/dist
{ printf 'artifact_name=%s-snapshot-phar\n' "${GITHUB_REPOSITORY##*/}" &&
printf 'artifact_path=%s\n' *.phar | head -n1 &&
printf 'man_path=%s\n' *.[0-9] | head -n1; } | tee -a "$GITHUB_OUTPUT" >>"$GITHUB_ENV"
- name: Upload phar artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.artifact_name }}
path: build/dist/${{ env.artifact_path }}
- name: Upload man page artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.man_path }}
path: build/dist/${{ env.man_path }}
test-phar:
name: Test phar
needs:
- check-ci-runs
- build
if: ${{ (github.event_name == 'workflow_call' || needs.check-ci-runs.outputs.ci_required == 1) && !cancelled() && !failure() }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-latest
php-version:
- "8.4"
include:
- os: ubuntu-latest
php-version: "8.3"
- os: ubuntu-latest
php-version: "8.2"
- os: ubuntu-latest
php-version: "8.1"
- os: ubuntu-latest
php-version: "8.0"
- os: ubuntu-latest
php-version: "7.4"
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: none, json, mbstring, tokenizer
coverage: none
- name: Download phar artifact
uses: actions/download-artifact@v4
with:
name: ${{ needs.build.outputs.artifact_name }}
- name: Run pretty-php
env:
artifact_path: ${{ needs.build.outputs.artifact_path }}
run: php "$artifact_path" --verbose
shell: bash
integration-tests:
name: Integration tests
needs:
- check-ci-runs
- build
- test-phar
if: ${{ (github.event_name == 'workflow_call' || needs.check-ci-runs.outputs.ci_required == 1) && !cancelled() && !failure() }}
strategy:
fail-fast: false
matrix:
repository:
- laravel/framework
args:
- --include-if-php --preset laravel src tests bin
include:
- repository: drupal/drupal
args: --exclude '/\/(\.git|\.hg|\.svn|_?build|dist|vendor|core\/lib\/Drupal\/Component\/Transliteration\/data)\/$/' --include-if-php=/./ --preset drupal .
- repository: symfony/symfony
args: --include-if-php --preset symfony .
- repository: WordPress/WordPress
args: --include-if-php --preset wordpress .
runs-on: ubuntu-latest
steps:
- name: Checkout ${{ matrix.repository }}
uses: actions/checkout@v4
with:
repository: ${{ matrix.repository }}
- name: Download phar artifact
uses: actions/download-artifact@v4
with:
name: ${{ needs.build.outputs.artifact_name }}
- name: Run pretty-php
env:
artifact_path: ${{ needs.build.outputs.artifact_path }}
run: |
php "$artifact_path" --print-config ${{ matrix.args }} | tee .prettyphp
php "$artifact_path" --quiet --timers || { status=$? && [[ $status -eq 4 ]] || (exit $status); }