Repository navigation
248 lines (216 loc) · 8.12 KB
/
Copy pathci.yml
File metadata and controls
248 lines (216 loc) · 8.12 KB
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
name: PHP CI
on:
pull_request:
push:
branches: [master]
workflow_dispatch:
permissions:
contents: read
concurrency:
group: php-ci-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
COMPOSER_PROCESS_TIMEOUT: '600'
defaults:
run:
shell: bash
jobs:
quality:
name: Quality / PHP ${{ matrix.php }}
runs-on: ubuntu-latest
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
php: ['8.3', '8.4', '8.5']
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
- name: Isolate Composer state
run: |
echo "COMPOSER_HOME=$RUNNER_TEMP/composer-home" >> "$GITHUB_ENV"
echo "COMPOSER_CACHE_DIR=$RUNNER_TEMP/composer-cache" >> "$GITHUB_ENV"
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, mbstring, xml, xmlwriter
ini-values: error_reporting=E_ALL
coverage: none
tools: composer:v2
- name: Resolve the development graph on the actual runtime
run: composer update --no-plugins --no-scripts --no-interaction --prefer-dist --no-progress
- name: Record and validate the resolved platform
run: |
php --version
php -r 'echo "error_reporting=" . error_reporting() . PHP_EOL;'
composer --version
composer validate --strict --no-check-publish
composer check-platform-reqs
composer show --locked
- name: Run formatting, PHPCS, PHPUnit and maximum src-plus-tests analysis
run: composer --no-plugins check
production:
name: Production / PHP ${{ matrix.php }} / ${{ matrix.dependencies }}
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
php: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5']
dependencies: [highest]
include:
- php: '7.4'
dependencies: lowest
- php: '8.5'
dependencies: lowest
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
- name: Isolate Composer state
run: |
echo "COMPOSER_HOME=$RUNNER_TEMP/composer-home" >> "$GITHUB_ENV"
echo "COMPOSER_CACHE_DIR=$RUNNER_TEMP/composer-cache" >> "$GITHUB_ENV"
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none
tools: composer:v2
- name: Lint all tracked PHP on the actual runtime
run: git ls-files -z -- '*.php' | xargs -0 -n1 php -l
- name: Verify the committed distribution and create a clean consumer
run: |
mkdir -p "$RUNNER_TEMP/package" "$RUNNER_TEMP/consumer"
git archive --format=tar --output="$RUNNER_TEMP/package.tar" HEAD
php tests/Production/archive.php "$RUNNER_TEMP/package.tar"
tar -xf "$RUNNER_TEMP/package.tar" -C "$RUNNER_TEMP/package"
jq -n --arg path "$RUNNER_TEMP/package" '{
name: "coisa/production-fixture",
repositories: [{
type: "path",
url: $path,
options: {symlink: false, versions: {"coisa/error-handler": "dev-ci"}}
}],
require: {"coisa/error-handler": "dev-ci"},
config: {"allow-plugins": false}
}' > "$RUNNER_TEMP/consumer/composer.json"
- name: Resolve runtime dependencies without development packages
env:
DEPENDENCIES: ${{ matrix.dependencies }}
run: |
options=()
if [ "$DEPENDENCIES" = lowest ]; then
options+=(--prefer-lowest --prefer-stable)
fi
composer --working-dir="$RUNNER_TEMP/consumer" update \
--no-dev --no-plugins --no-scripts --no-interaction --prefer-dist --no-progress \
"${options[@]}"
- name: Record and check the production platform
run: |
php --version
composer --version
composer --working-dir="$RUNNER_TEMP/consumer" check-platform-reqs --no-dev
composer --working-dir="$RUNNER_TEMP/consumer" show --locked
- name: Exercise the public container and alias factories
run: |
php tests/Production/container.php "$RUNNER_TEMP/consumer/vendor/autoload.php"
php tests/Production/alias-factory.php "$RUNNER_TEMP/consumer/vendor/autoload.php"
coverage:
name: PHPUnit coverage / PHP 8.5
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
- name: Isolate Composer state
run: |
echo "COMPOSER_HOME=$RUNNER_TEMP/composer-home" >> "$GITHUB_ENV"
echo "COMPOSER_CACHE_DIR=$RUNNER_TEMP/composer-cache" >> "$GITHUB_ENV"
- uses: shivammathur/setup-php@v2
with:
php-version: '8.5'
extensions: dom, mbstring, xml, xmlwriter
ini-values: error_reporting=E_ALL
coverage: xdebug
tools: composer:v2
- name: Resolve and record the actual coverage toolchain
run: |
composer update --no-plugins --no-scripts --no-interaction --prefer-dist --no-progress
php --version
composer --version
composer check-platform-reqs
composer show --locked
- name: Run PHPUnit with Clover and line-coverage reports
env:
XDEBUG_MODE: coverage
run: composer --no-plugins test-coverage -- --coverage-cobertura tests/cobertura.xml
- name: Upload the raw PHPUnit coverage
if: ${{ !cancelled() }}
uses: actions/upload-artifact@v7
with:
name: coverage-report-php
path: |
tests/clover.xml
tests/cobertura.xml
if-no-files-found: error
retention-days: 14
overwrite: true
coverage-report:
name: Coverage report
needs: coverage
if: ${{ !cancelled() && needs.coverage.result == 'success' }}
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: read
actions: read
pull-requests: write
steps:
- name: Download this run's coverage artifact
uses: actions/download-artifact@v8
with:
name: coverage-report-php
path: tests
- name: Create the baseline or check coverage
id: coverage-diff
uses: clearlyip/code-coverage-report-action@v7
with:
filename: tests/cobertura.xml
artifact_download_workflow_names: PHP CI
artifact_name: phpunit-coverage-%name%
retention_days: '90'
overall_coverage_fail_threshold: ${{ vars.MINIMUM_COVERAGE_THRESHOLD || '80' }}
fail_on_negative_difference: 'false'
negative_difference_by: overall
only_list_changed_files: 'true'
- name: Identify the tested head and run
if: ${{ !cancelled() && steps.coverage-diff.outputs.file != '' }}
env:
HEAD_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
TESTED_SHA: ${{ github.sha }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
printf '\n\nHead: %s. Tested commit: %s. [PHP CI run](%s).\n' \
"$HEAD_SHA" "$TESTED_SHA" "$RUN_URL" >> code-coverage-results.md
- name: Upload the Markdown report
if: ${{ !cancelled() && steps.coverage-diff.outputs.file != '' }}
uses: actions/upload-artifact@v7
with:
name: coverage-pr-comment
path: ${{ steps.coverage-diff.outputs.file }}
if-no-files-found: error
retention-days: 14
overwrite: true
- name: Update the PR coverage note
if: >-
!cancelled() &&
github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.full_name == github.repository &&
!startsWith(github.head_ref, 'dependabot/') &&
steps.coverage-diff.outputs.file != ''
uses: marocchino/sticky-pull-request-comment@v3
with:
header: phpunit-coverage
path: ${{ steps.coverage-diff.outputs.file }}