-
Notifications
You must be signed in to change notification settings - Fork 0
230 lines (191 loc) · 6.93 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
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-24.04
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
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
check:
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-24.04
steps:
- name: Checkout
uses: actions/checkout@v4
# PHP 8.3 is needed to parse DNF types in test fixtures, and
# php-cs-fixer doesn't support PHP 8.4
- 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
- name: Check generated files
run: scripts/generate.php --check
- name: Run PHP CS Fixer
run: tools/php-cs-fixer check --diff --verbose
- name: Run pretty-php
run: tools/pretty-php --diff
phpstan:
name: PHPStan
needs:
- check
- 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-24.04
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
- 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-24.04
- windows-latest
- macos-latest
php-version:
- "8.4"
include:
- os: ubuntu-24.04
php-version: "8.3"
- os: ubuntu-24.04
php-version: "8.2"
- os: ubuntu-24.04
php-version: "8.1"
- os: ubuntu-24.04
php-version: "8.0"
- os: ubuntu-24.04
php-version: "7.4"
- os: windows-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: fileinfo, sqlite3
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: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18.x
cache: npm
cache-dependency-path: tools/*/package-lock.json
- name: Install PHP dependencies
run: composer install --no-interaction --no-progress
- name: Install Node.js dependencies
shell: bash
run: |
for file in tools/*/package-lock.json; do
(cd "${file%/*}" && npm install)
done
- name: Start Mockoon CLI
id: start-mockoon
shell: bash
run: scripts/start-mockoon.sh
- name: Run PHPUnit tests and generate code coverage report
id: run-phpunit-tests
shell: bash
run: |
scripts/delete-covers.php --force
vendor/bin/phpunit ${RUNNER_DEBUG+--debug} ${RUNNER_DEBUG+--no-extensions} --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 }}
- name: Upload Mockoon CLI log files artifact
if: ${{ !cancelled() && steps.start-mockoon.conclusion == 'success' }}
uses: actions/upload-artifact@v4
with:
name: mockoon-cli-logs-${{ matrix.os }}-${{ matrix.php-version }}
path: ~/.mockoon-cli/logs/*.log