-
-
Notifications
You must be signed in to change notification settings - Fork 0
281 lines (228 loc) · 8.42 KB
/
Copy pathci.yml
File metadata and controls
281 lines (228 loc) · 8.42 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
281
name: CI
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
env:
MIN_COVERAGE: 95
jobs:
git-hygiene:
name: Git history (no Cursor co-author)
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Check for Cursor co-author trailers (REQ-GIT-001)
run: |
chmod +x .scripts/check-no-cursor-coauthor.sh
./.scripts/check-no-cursor-coauthor.sh HEAD
test:
name: PHP ${{ matrix.php }} - Symfony ${{ matrix.symfony }} - ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
php: ['8.2', '8.3', '8.4', '8.5']
symfony: ['7.0', '7.4', '8.0', '8.1']
exclude:
# PHP 8.2 and 8.3 don't support Symfony 8.0, 8.1 (requires PHP 8.4+)
- php: '8.2'
symfony: '8.0'
- php: '8.2'
symfony: '8.1'
- php: '8.3'
symfony: '8.0'
- php: '8.3'
symfony: '8.1'
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: json
coverage: pcov
tools: composer:v2
- name: Validate composer.json
run: composer validate --strict
- 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@v5
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-php-${{ matrix.php }}-symfony-${{ matrix.symfony }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
${{ runner.os }}-php-${{ matrix.php }}-symfony-${{ matrix.symfony }}-composer-
${{ runner.os }}-php-${{ matrix.php }}-composer-
- name: Install dependencies with Symfony ${{ matrix.symfony }}
run: |
echo "📦 Installing dependencies for Symfony ${{ matrix.symfony }}..."
composer require symfony/form:^${{ matrix.symfony }} symfony/framework-bundle:^${{ matrix.symfony }} symfony/twig-bundle:^${{ matrix.symfony }} --no-interaction --no-update
composer update --with-all-dependencies --no-interaction --prefer-dist --no-progress
- name: Run tests
run: |
echo "🧪 Running tests on PHP ${{ matrix.php }} with Symfony ${{ matrix.symfony }}..."
composer test
if [ $? -ne 0 ]; then
echo "❌ ERROR: Some tests failed"
exit 1
fi
echo "✅ All tests passed successfully"
- name: Validate coverage (PHP 8.2 with Symfony 7.0 only)
if: matrix.php == '8.2' && matrix.symfony == '7.0'
run: |
echo "📊 Generating coverage report..."
composer test-coverage
if [ $? -ne 0 ]; then
echo "❌ ERROR: Tests failed when generating coverage report"
exit 1
fi
echo "✅ All tests passed, validating minimum coverage (${MIN_COVERAGE}%)..."
MIN_COVERAGE=${MIN_COVERAGE} php -r "
\$minCoverage = (float) (getenv('MIN_COVERAGE') ?: 95);
if (!file_exists('coverage.xml')) {
echo 'ERROR: coverage.xml file was not generated\n';
exit(1);
}
\$coverage = simplexml_load_file('coverage.xml');
if (\$coverage === false) {
echo 'ERROR: Could not read coverage.xml\n';
exit(1);
}
\$metrics = \$coverage->project->metrics;
\$elements = (float)\$metrics['elements'];
\$coveredElements = (float)\$metrics['coveredelements'];
if (\$elements == 0) {
echo 'No elements to cover\n';
exit(0);
}
\$percentage = (\$coveredElements / \$elements) * 100;
echo \"Coverage: \$coveredElements/\$elements (\$percentage%)\n\";
if (\$percentage < \$minCoverage) {
echo \"ERROR: Coverage must be at least {\$minCoverage}%. Current: \$percentage%\n\";
exit(1);
}
echo \"✅ Coverage threshold met (>= {\$minCoverage}%)\n\";
"
code-style:
name: Code Style
runs-on: ubuntu-latest
# Only apply fixes automatically on push to main/master, not on PRs
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
tools: composer:v2, cs2pr
- name: Install dependencies
run: composer update --prefer-dist --no-progress --no-interaction
- name: Fix code style
run: composer cs-fix
- name: Check for changes
id: verify-changed-files
run: |
if [ -n "$(git status --porcelain)" ]; then
echo "changed=true" >> $GITHUB_OUTPUT
else
echo "changed=false" >> $GITHUB_OUTPUT
fi
- name: Commit changes
if: steps.verify-changed-files.outputs.changed == 'true'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add -A
git commit -m "Apply PHP CS Fixer fixes [skip ci]"
git push
code-style-check:
name: Code Style Check
runs-on: ubuntu-latest
# On PRs only check, don't apply changes
if: github.event_name == 'pull_request'
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
tools: composer:v2, cs2pr
- name: Install dependencies
run: composer update --prefer-dist --no-progress --no-interaction
- name: Check code style
run: composer cs-check
coverage:
name: Code Coverage
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
extensions: json
coverage: pcov
tools: composer:v2
- name: Install dependencies
run: composer update --prefer-dist --no-progress --no-interaction
- name: Run tests with coverage
run: |
echo "🧪 Running tests with coverage..."
composer test-coverage
if [ $? -ne 0 ]; then
echo "❌ ERROR: Tests failed"
exit 1
fi
echo "✅ All tests passed successfully"
- name: Validate coverage threshold
run: |
echo "📊 Validating minimum coverage (${MIN_COVERAGE}%)..."
MIN_COVERAGE=${MIN_COVERAGE} php -r "
\$minCoverage = (float) (getenv('MIN_COVERAGE') ?: 95);
if (!file_exists('coverage.xml')) {
echo 'ERROR: coverage.xml file was not generated\n';
exit(1);
}
\$coverage = simplexml_load_file('coverage.xml');
if (\$coverage === false) {
echo 'ERROR: Could not read coverage.xml\n';
exit(1);
}
\$metrics = \$coverage->project->metrics;
\$elements = (float)\$metrics['elements'];
\$coveredElements = (float)\$metrics['coveredelements'];
if (\$elements == 0) {
echo 'No elements to cover\n';
exit(0);
}
\$percentage = (\$coveredElements / \$elements) * 100;
echo \"Coverage: \$coveredElements/\$elements (\$percentage%)\n\";
if (\$percentage < \$minCoverage) {
echo \"ERROR: Coverage must be at least {\$minCoverage}%. Current: \$percentage%\n\";
exit(1);
}
echo \"✅ Coverage threshold met (>= {\$minCoverage}%)\n\";
"
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
files: coverage.xml
fail_ci_if_error: false
# Maintainer: Héctor Franco Aceituno (@HecFranco)
# Organization: nowo-tech (https://github.com/nowo-tech)