-
Notifications
You must be signed in to change notification settings - Fork 56
353 lines (288 loc) · 10.6 KB
/
continuous-integration.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: "Continuous Integration"
on:
push:
paths-ignore:
- '**.md'
- 'img/**'
pull_request:
paths-ignore:
- '**.md'
- 'img/**'
# Allow manually triggering the workflow
workflow_dispatch:
jobs:
tests:
name: "CI"
runs-on: ${{ matrix.os }}
# We want to run on external PRs, but not on our own internal PRs as they'll be run by the push to the branch.
if: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) }}
strategy:
matrix:
php-version:
- "7.1"
- "7.2"
- "7.3"
- "7.4"
- "8.0"
- "8.1"
- "8.2"
- "8.3"
os:
- ubuntu-latest
- windows-latest
steps:
- name: "Checkout"
uses: "actions/checkout@v3"
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
ini-values: "error_reporting=-1, display_errors=On, display_startup_errors=On, zend.assertions=1"
php-version: "${{ matrix.php-version }}"
tools: composer:v2
- name: Get composer cache directory
id: composercache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
shell: bash
- name: Cache composer dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composercache.outputs.dir }}
key: composer-${{ runner.os }}-${{ matrix.php-version }}-${{ hashFiles('composer.*') }}
restore-keys: |
composer-${{ runner.os }}-${{ matrix.php-version }}-
composer-${{ runner.os }}-
composer-
- name: "Install dependencies"
run: |
composer update --no-interaction --no-scripts --no-progress
composer bin php-parallel-lint update --no-interaction --no-progress
- name: "Check PHP syntax"
run: "vendor/bin/parallel-lint src tests"
- name: "Run tests"
run: "vendor/bin/simple-phpunit --colors=always --testdox"
- name: "Run Churn"
run: "php bin/churn run src -p -vvv"
test-vcs:
name: "Test VCS"
runs-on: ubuntu-latest
# We want to run on external PRs, but not on our own internal PRs as they'll be run by the push to the branch.
if: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) }}
strategy:
matrix:
vcs:
- fossil
- mercurial
- subversion
steps:
- name: "Checkout"
uses: "actions/checkout@v3"
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
ini-values: "error_reporting=-1, display_errors=On, display_startup_errors=On, zend.assertions=1"
php-version: "8.1"
tools: composer:v2
- uses: "ramsey/composer-install@v2"
with:
dependency-versions: "highest"
composer-options: "--no-scripts"
- name: "Build Docker image"
run: "docker build -t ${{ matrix.vcs }} -f tests/docker/${{ matrix.vcs }}/Dockerfile tests/docker/${{ matrix.vcs }}"
- name: "Run tests"
run: |
vcs=${{ matrix.vcs }}
docker run -i --rm -v $PWD:/churn ${{ matrix.vcs }} /churn/vendor/bin/simple-phpunit -c /churn/phpunit.xml.dist /churn/tests/EndToEnd/${vcs^}Test.php --coverage-clover=/churn/coverage-${{ matrix.vcs }}.xml
sed -i 's/\/churn\/src/\/home\/runner\/work\/${{ github.event.repository.name }}\/${{ github.event.repository.name }}\/src/g' coverage-${{ matrix.vcs }}.xml
- uses: actions/upload-artifact@v3
with:
name: coverage
path: ./coverage-${{ matrix.vcs }}.xml
coverage:
name: "Code coverage"
runs-on: ubuntu-latest
# Run after "test-vcs" to gather all code coverage reports
needs: [test-vcs]
steps:
- name: "Checkout"
uses: "actions/checkout@v3"
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "pcov"
ini-values: "error_reporting=-1, display_errors=On, display_startup_errors=On, zend.assertions=1"
php-version: "8.1"
tools: composer:v2
- uses: "ramsey/composer-install@v2"
with:
dependency-versions: "highest"
composer-options: "--no-scripts"
- name: "Calculate code coverage"
run: "vendor/bin/simple-phpunit --colors=always --testdox --testsuite churn-tests --coverage-clover=coverage.xml"
- name: "Download other code coverage reports"
uses: actions/[email protected]
with:
name: coverage
path: ./coverage
- name: "List all coverage reports"
run: echo coverage_reports=./coverage/$(ls -m coverage/ | sed "s/, */,.\/coverage\//g") >> $GITHUB_ENV
- name: "Upload coverage to Codecov"
uses: codecov/codecov-action@v4
# No need to run this step on forks.
if: ${{ 'bmitch/churn-php' == github.repository }}
with:
files: ./coverage.xml,${{ env.coverage_reports }}
fail_ci_if_error: true
verbose: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
analysis:
name: "Static Analysis"
runs-on: ubuntu-latest
# We want to run on external PRs, but not on our own internal PRs as they'll be run by the push to the branch.
if: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) }}
steps:
- name: "Checkout"
uses: "actions/checkout@v3"
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
ini-values: "error_reporting=-1, display_errors=On, display_startup_errors=On, zend.assertions=1"
php-version: "8.1"
tools: composer:v2, composer-normalize, composer-require-checker
- name: "Validate composer.json"
run: "composer validate --strict"
- uses: "ramsey/composer-install@v2"
with:
dependency-versions: "highest"
- name: "Check for PSR-4 violations"
run: "composer dump-autoload --optimize --strict-psr --no-scripts"
- name: "Run PHP Mess Detector"
run: "vendor/bin/phpmd src text phpmd.xml"
- name: "Run PHPLOC"
run: "vendor/bin/phploc src"
- name: "Run PHP Copy/Paste Detector"
run: "vendor/bin/phpcpd src"
- name: "Install PHPUnit"
run: "vendor/bin/simple-phpunit --version"
- name: "Run Psalm"
run: "vendor/bin/psalm --show-info=true"
- name: "Run PHPStan"
run: "vendor/bin/phpstan"
- name: "Run PHP_CodeSniffer"
run: |
vendor/bin/phpcs
vendor/bin/phpcs --standard=phpcs-tests.xml
- name: "Normalize composer.json"
run: "composer-normalize --dry-run --no-check-lock --no-update-lock"
- name: "Analyze Composer dependencies"
run: "composer-require-checker check ./composer.json"
build:
name: "Build Phar"
runs-on: ubuntu-latest
# Build when everything else is ok
needs: [tests, analysis, coverage]
steps:
- name: "Checkout"
uses: "actions/checkout@v3"
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
ini-values: "error_reporting=-1, display_errors=On, display_startup_errors=On, zend.assertions=1"
php-version: "8.1"
tools: composer:v2
- name: Get composer cache directory
id: composercache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
shell: bash
- name: Cache composer dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composercache.outputs.dir }}
key: composer-${{ runner.os }}-7.1-${{ hashFiles('composer.*') }}
restore-keys: |
composer-${{ runner.os }}-7.1-
composer-${{ runner.os }}-
composer-
- name: "Build Phar"
run: |
make build
mv build/churn.phar .
- name: "Test Version"
run: |
diff -u <(build/bin/churn -V) <(./churn.phar -V)
./churn.phar --version | grep -E '^churn-php .+@[0-9a-z]{7}$'
- name: "Test Phar"
run: diff -u <(build/bin/churn --format=csv | sort) <(./churn.phar --format=csv | sort)
- name: "Save Phar"
uses: actions/upload-artifact@v3
with:
name: churn.phar
path: ./churn.phar
if-no-files-found: error
tests-phar-oldphp:
name: "Test Phar error message with PHP ${{ matrix.php-version }}"
runs-on: ubuntu-latest
# We need the phar file
needs: [build]
strategy:
matrix:
php-version:
- "7.0"
- "5.6"
- "5.5"
- "5.4"
- "5.3"
steps:
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
ini-values: "error_reporting=-1, display_errors=On, display_startup_errors=On, zend.assertions=1"
php-version: ${{ matrix.php-version }}
tools: none
- name: Download churn.phar
uses: actions/[email protected]
with:
name: churn.phar
- name: Make churn.phar executable
run: chmod +x churn.phar
- name: Test churn.phar error message
run: |
php -r "passthru('./churn.phar', \$code); if (\$code !== 1) exit('Invalid error code. Expected 1, got ' . \$code);" &> error
echo "Error code is OK. Now testing error message..."
grep 'The application requires the version ">=7.1.3" or greater' error
echo "Everything is OK."
tests-phar:
name: "Test Phar with PHP ${{ matrix.php-version }}"
runs-on: ubuntu-latest
# We need the phar file
needs: [build]
strategy:
matrix:
php-version:
- "7.1"
- "8.1"
steps:
- name: "Checkout"
uses: "actions/checkout@v3"
with:
fetch-depth: 0
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
ini-values: "error_reporting=-1, display_errors=On, display_startup_errors=On, zend.assertions=1"
php-version: ${{ matrix.php-version }}
tools: none
- name: Download churn.phar
uses: actions/[email protected]
with:
name: churn.phar
- name: Make churn.phar executable
run: chmod +x churn.phar
- name: "Run Phar"
run: ./churn.phar --format=markdown >> $GITHUB_STEP_SUMMARY