-
Notifications
You must be signed in to change notification settings - Fork 0
280 lines (237 loc) · 9.56 KB
/
ci.yml
File metadata and controls
280 lines (237 loc) · 9.56 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
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
name: CI Pipeline
on:
push:
branches:
- main
- develop
- feature/*
pull_request:
branches:
- main
- develop
schedule:
# Run daily at 2 AM UTC
- cron: "0 2 * * *"
jobs:
# ============================================================================
# TEST JOB - Run tests across multiple PHP versions
# ============================================================================
test:
name: Tests (PHP ${{ matrix.php }})
runs-on: ubuntu-latest
permissions:
# Required for codecov/codecov-action to get an OIDC token.
id-token: write
# Required for actions/checkout to fetch code.
contents: read
strategy:
fail-fast: false
matrix:
php:
- "8.4"
- "8.3"
include:
- php: "8.4"
coverage: true
services:
redis:
image: redis:7-alpine
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
memcached:
image: memcached:1.6-alpine
ports:
- 11211:11211
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: redis, memcached, mbstring, xml, ctype, json, tokenizer, opcache
coverage: xdebug
tools: composer:v2
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Get Composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Validate composer.json and composer.lock
run: composer validate --strict --no-check-lock
- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-interaction
- name: Check PHP syntax
run: find src tests -name "*.php" -print0 | xargs -0 -n1 php -l
- name: Run tests
if: matrix.coverage != true
run: vendor/bin/phpunit --no-coverage
env:
REDIS_HOST: localhost
REDIS_PORT: 6379
MEMCACHED_HOST: localhost
MEMCACHED_PORT: 11211
- name: Run tests with coverage
if: matrix.coverage == true
run: vendor/bin/phpunit --coverage-clover=coverage.xml --coverage-text
env:
XDEBUG_MODE: coverage
REDIS_HOST: localhost
REDIS_PORT: 6379
MEMCACHED_HOST: localhost
MEMCACHED_PORT: 11211
- name: Upload coverage to Codecov
if: matrix.coverage == true
uses: codecov/codecov-action@v4
with:
files: ./coverage.xml
flags: unittests
name: codecov-php-${{ matrix.php }}
fail_ci_if_error: false
- name: Archive code coverage results
if: matrix.coverage == true
uses: actions/upload-artifact@v4
with:
name: code-coverage-report
path: coverage.xml
retention-days: 30
# ============================================================================
# CODE QUALITY JOB - Run all quality checks
# ============================================================================
code-quality:
name: Code Quality
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.4"
extensions: mbstring, xml, ctype, json, tokenizer
coverage: none
tools: composer:v2, cs2pr
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Get Composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-interaction
- name: Check code style (PHP CS Fixer)
run: vendor/bin/php-cs-fixer fix --dry-run --diff --format=checkstyle | cs2pr
continue-on-error: true
- name: Run static analysis (PHPStan)
run: vendor/bin/phpstan analyse --error-format=github --no-progress
- name: Run mess detector (PHPMD)
run: vendor/bin/phpmd src github devkit/.config/phpmd/ruleset.xml
continue-on-error: true
- name: Check for security vulnerabilities
run: composer audit --format=plain
# ============================================================================
# MUTATION TESTING JOB (Optional - runs on schedule)
# ============================================================================
mutation:
name: Mutation Testing
runs-on: ubuntu-latest
if: github.event_name == 'schedule' || contains(github.event.head_commit.message, '[mutation]')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.4"
extensions: mbstring, xml, ctype, json
coverage: xdebug
tools: composer:v2
- name: Install dependencies
run: composer install --prefer-dist --no-progress
- name: Run Infection (Mutation Testing)
run: |
composer require --dev infection/infection
vendor/bin/infection --threads=4 --min-msi=70 --min-covered-msi=80
continue-on-error: true
# ============================================================================
# DOCUMENTATION JOB
# ============================================================================
documentation:
name: Documentation
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.4"
tools: composer:v2
- name: Install dependencies
run: composer install --prefer-dist --no-progress
- name: Generate API documentation
run: |
composer require --dev phpdocumentor/phpdocumentor
vendor/bin/phpdoc -d src -t docs/api
continue-on-error: true
- name: Deploy documentation to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
if: success()
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/api
publish_branch: gh-pages
# ============================================================================
# COMPATIBILITY CHECK JOB
# ============================================================================
compatibility:
name: Backward Compatibility Check
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- name: Checkout current code
uses: actions/checkout@v4
with:
path: current
- name: Checkout base code
uses: actions/checkout@v4
with:
ref: ${{ github.base_ref }}
path: base
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.4"
tools: composer:v2
- name: Install roave/backward-compatibility-check
run: |
cd current
composer require --dev roave/backward-compatibility-check
- name: Check backward compatibility
run: |
cd current
vendor/bin/roave-backward-compatibility-check --from=../base
continue-on-error: true