-
-
Notifications
You must be signed in to change notification settings - Fork 0
227 lines (206 loc) · 9.72 KB
/
tests.yml
File metadata and controls
227 lines (206 loc) · 9.72 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
name: Run PHPUnit Tests
on:
workflow_call:
inputs:
min-coverage:
description: Minimum line coverage percentage enforced by dev-tools tests.
required: false
type: number
default: 80
max-outdated:
description: Maximum number of outdated packages allowed by the dependencies command.
required: false
type: string
default: '-1'
publish-required-statuses:
description: Mirror required test matrix checks as commit statuses for workflow-dispatched runs.
required: false
type: boolean
default: false
workflow_dispatch:
inputs:
min-coverage:
description: Minimum line coverage percentage enforced by dev-tools tests.
required: false
type: number
default: 80
max-outdated:
description: Maximum number of outdated packages allowed by the dependencies command.
required: false
type: string
default: '-1'
publish-required-statuses:
description: Mirror required test matrix checks as commit statuses for workflow-dispatched runs.
required: false
type: boolean
default: false
pull_request:
types: [opened, synchronize, reopened]
push:
branches: [ "main" ]
permissions:
contents: read
statuses: write
concurrency:
group: ${{ github.event_name == 'pull_request' && format('tests-pr-{0}', github.event.pull_request.number) || format('tests-{0}', github.ref) }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
env:
FORCE_COLOR: '1'
jobs:
resolve_php:
name: Resolve PHP Version
runs-on: ubuntu-latest
outputs:
php-version: ${{ steps.resolve.outputs.php-version }}
php-version-source: ${{ steps.resolve.outputs.php-version-source }}
test-matrix: ${{ steps.resolve.outputs.test-matrix }}
steps:
- uses: actions/checkout@v6
- name: Checkout dev-tools workflow action source
uses: actions/checkout@v6
with:
repository: php-fast-forward/dev-tools
ref: ${{ github.repository == 'php-fast-forward/dev-tools' && (github.event_name == 'pull_request_target' && github.event.pull_request.base.sha || github.sha) || 'main' }}
path: .dev-tools-actions
sparse-checkout: |
.github/actions
- name: Resolve workflow PHP version
id: resolve
uses: ./.dev-tools-actions/.github/actions/php/resolve-version
tests:
needs: resolve_php
name: Run Tests
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.resolve_php.outputs.test-matrix) }}
env:
TESTS_ROOT_VERSION: ${{ github.event_name == 'pull_request' && format('dev-{0}', github.event.pull_request.head.ref) || 'dev-main' }}
steps:
- uses: actions/checkout@v6
- name: Checkout dev-tools workflow action source
uses: actions/checkout@v6
with:
repository: php-fast-forward/dev-tools
ref: ${{ github.repository == 'php-fast-forward/dev-tools' && (github.event_name == 'pull_request_target' && github.event.pull_request.base.sha || github.sha) || 'main' }}
path: .dev-tools-actions
- name: Setup PHP and install dependencies
uses: ./.dev-tools-actions/.github/actions/php/setup-composer
with:
php-version: ${{ matrix.php-version }}
extensions: pcov, pcntl
coverage: pcov
root-version: ${{ env.TESTS_ROOT_VERSION }}
install-options: --prefer-dist --no-progress --no-interaction --no-plugins --no-scripts
- name: Composer Audit
env:
COMPOSER_ROOT_VERSION: ${{ env.TESTS_ROOT_VERSION }}
run: composer audit
- name: Resolve minimum coverage
id: minimum-coverage
run: echo "value=${INPUT_MIN_COVERAGE:-80}" >> "$GITHUB_OUTPUT"
env:
INPUT_MIN_COVERAGE: ${{ inputs.min-coverage }}
- name: Run PHPUnit tests
env:
COMPOSER_ROOT_VERSION: ${{ env.TESTS_ROOT_VERSION }}
run: dev-tools tests --coverage=.dev-tools/coverage --min-coverage=${{ steps.minimum-coverage.outputs.value }}
- name: Publish required test status
if: ${{ always() && inputs.publish-required-statuses }}
env:
GH_TOKEN: ${{ github.token }}
TARGET_SHA: ${{ github.sha }}
TARGET_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
TEST_CONTEXT: Run Tests (${{ matrix.php-version }})
TEST_RESULT: ${{ job.status }}
run: |
if [ "${TEST_RESULT}" = "success" ]; then
state="success"
description="Workflow-dispatched PHPUnit job passed."
else
state="failure"
description="Workflow-dispatched PHPUnit job result: ${TEST_RESULT}."
fi
gh api \
--method POST \
"repos/${GITHUB_REPOSITORY}/statuses/${TARGET_SHA}" \
-f state="${state}" \
-f context="${TEST_CONTEXT}" \
-f description="${description}" \
-f target_url="${TARGET_URL}"
dependency-health:
needs: resolve_php
name: Dependency Health
runs-on: ubuntu-latest
env:
TESTS_ROOT_VERSION: ${{ github.event_name == 'pull_request' && format('dev-{0}', github.event.pull_request.head.ref) || 'dev-main' }}
steps:
- uses: actions/checkout@v6
- name: Checkout dev-tools workflow action source
uses: actions/checkout@v6
with:
repository: php-fast-forward/dev-tools
ref: ${{ github.repository == 'php-fast-forward/dev-tools' && (github.event_name == 'pull_request_target' && github.event.pull_request.base.sha || github.sha) || 'main' }}
path: .dev-tools-actions
- name: Setup PHP and install dependencies
uses: ./.dev-tools-actions/.github/actions/php/setup-composer
with:
php-version: ${{ needs.resolve_php.outputs.php-version }}
root-version: ${{ env.TESTS_ROOT_VERSION }}
install-options: --prefer-dist --no-progress --no-interaction --no-plugins --no-scripts
- name: Run dependency health check
env:
COMPOSER_ROOT_VERSION: ${{ env.TESTS_ROOT_VERSION }}
run: dev-tools dependencies --max-outdated=${{ inputs.max-outdated || -1 }}
summarize:
if: ${{ always() }}
name: Summarize Test Workflow
needs:
- resolve_php
- tests
- dependency-health
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Checkout dev-tools workflow action source
uses: actions/checkout@v6
with:
repository: php-fast-forward/dev-tools
ref: ${{ github.repository == 'php-fast-forward/dev-tools' && (github.event_name == 'pull_request_target' && github.event.pull_request.base.sha || github.sha) || 'main' }}
path: .dev-tools-actions
sparse-checkout: |
.github/actions
- uses: ./.dev-tools-actions/.github/actions/summary/write
with:
markdown: |
## Tests Workflow Summary
- Workflow PHP version: `${{ needs.resolve_php.outputs.php-version }}`
- PHP version source: `${{ needs.resolve_php.outputs.php-version-source }}`
- Test matrix: `${{ needs.resolve_php.outputs.test-matrix }}`
- Minimum coverage threshold: `${{ inputs.min-coverage || 80 }}`
- Dependency health `max-outdated`: `${{ inputs.max-outdated || -1 }}`
- Tests job result: `${{ needs.tests.result }}`
- Dependency health result: `${{ needs.dependency-health.result }}`
publish_required_statuses:
if: ${{ always() && inputs.publish-required-statuses }}
name: Publish Required Test Statuses
needs:
- resolve_php
runs-on: ubuntu-latest
steps:
- name: Publish pending required test statuses
env:
GH_TOKEN: ${{ github.token }}
TARGET_SHA: ${{ github.sha }}
TARGET_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
TEST_MATRIX: ${{ needs.resolve_php.outputs.test-matrix }}
run: |
php -r "foreach (json_decode(getenv('TEST_MATRIX'), true, 512, JSON_THROW_ON_ERROR)['php-version'] as \$version) { echo \$version, PHP_EOL; }" | while IFS= read -r php_version; do
gh api \
--method POST \
"repos/${GITHUB_REPOSITORY}/statuses/${TARGET_SHA}" \
-f state="pending" \
-f context="Run Tests (${php_version})" \
-f description="Workflow-dispatched PHPUnit job is pending." \
-f target_url="${TARGET_URL}"
done