]> git.agnieray.net Git - galette.git/blob - .github/workflows/ci-linux.yml
Try to boost code coverage with pcov
[galette.git] / .github / workflows / ci-linux.yml
1 name: Galette CI
2
3 on:
4 push:
5 branches:
6 - master
7 - develop
8 - 'feature/*'
9 - 'hotfix/*'
10 - 'release/*'
11 tags:
12 - '*'
13 pull_request:
14 # Enable manual run
15 workflow_dispatch:
16
17 concurrency:
18 group: "${{ github.workflow }}-${{ github.ref }}"
19 cancel-in-progress: true
20
21 jobs:
22 unit-tests:
23 runs-on: ubuntu-latest
24
25 strategy:
26 matrix:
27 include:
28 #always tests higher stable php version with lower db version
29 #enable coverage on higher stable php version with higher PostgreSQL version
30 #higher stable php version
31 - { php-version: "8.3", db-image: "postgres:11", coverage: none, always: true }
32 - { php-version: "8.3", db-image: "postgres:16", coverage: 'pcov', always: true }
33 - { php-version: "8.3", db-image: "mysql:5.7", coverage: none, always: true }
34 - { php-version: "8.3", db-image: "mysql:8.1", coverage: none, always: false }
35 - { php-version: "8.3", db-image: "mariadb:10.4", coverage: none, always: true }
36 - { php-version: "8.3", db-image: "mariadb:11.3", coverage: none, always: false }
37 #lower php version
38 - { php-version: "8.1", db-image: "postgres:11", coverage: none, always: false }
39 - { php-version: "8.1", db-image: "postgres:16", coverage: none, always: false }
40 - { php-version: "8.1", db-image: "mysql:5.7", coverage: none, always: false }
41 - { php-version: "8.1", db-image: "mysql:8.1", coverage: none, always: false }
42 - { php-version: "8.1", db-image: "mariadb:10.4", coverage: none, always: false }
43 - { php-version: "8.1", db-image: "mariadb:11.3", coverage: none, always: false }
44 fail-fast: false
45
46 env:
47 skip: ${{ matrix.always == false && (github.event_name == 'pull_request' || github.repository != 'galette/galette' || !(github.event_name == 'workflow_dispatch' || github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/tags'))) }}
48 DB: ${{ matrix.db-image }}
49
50 services:
51 # Label used to access the service container
52 db:
53 # Docker Hub image
54 image: ${{ matrix.db-image }}
55 # Provide env variables for both mysql and pgsql
56 env:
57 POSTGRES_USER: galette_tests
58 POSTGRES_PASSWORD: g@l3tte
59 POSTGRES_DB: galette_tests
60 MYSQL_USER: galette_tests
61 MYSQL_PASSWORD: g@l3tte
62 MYSQL_ROOT_PASSWORD: g@l3tte
63 MYSQL_DATABASE: galette_tests
64 # Open network ports for both mysql and pgsql
65 ports:
66 - 3306:3306
67 - 5432:5432
68 # Set health checks to wait until postgres has started
69 options: >-
70 --health-cmd="bash -c 'if [[ -n $(command -v pg_isready) ]]; then pg_isready; else if [[ -n $(command -v mysqladmin) ]]; then mysqladmin ping; else mariadb-admin ping; fi fi'"
71 --health-interval=10s
72 --health-timeout=5s
73 --health-retries=10
74
75 name: PHP ${{ matrix.php-version }} ${{ matrix.db-image }} ${{ (matrix.always == false && (github.event_name == 'pull_request' || github.repository != 'galette/galette' || !(github.event_name == 'workflow_dispatch' || github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/tags')))) && ' (skipped)' || matrix.coverage == 'pcov' && ' (with coverage)' || ''}}
76
77 steps:
78 - name: PHP
79 if: env.skip != 'true'
80 uses: shivammathur/setup-php@v2
81 with:
82 php-version: ${{ matrix.php-versions }}
83 tools: composer, pecl
84 coverage: ${{ matrix.coverage }}
85 extensions: apcu
86 ini-values: apc.enable_cli=1
87
88 - name: "Show versions"
89 if: env.skip != 'true'
90 run: |
91 php --version
92 composer --version
93 echo "node $(node --version)"
94 echo "npm $(npm --version)"
95 docker exec ${{ job.services.db.id }} bash -c "if [[ -n \$(command -v psql) ]]; then psql --version; else if [[ -n \$(command -v mysql) ]]; then mysql --version; else mariadb --version; fi fi"
96
97 - name: Checkout
98 if: env.skip != 'true'
99 uses: actions/checkout@v4
100 with:
101 fetch-depth: 2
102
103 - name: "Restore dependencies cache"
104 if: env.skip != 'true'
105 uses: actions/cache@v4
106 with:
107 path: |
108 ~/.composer/cache/
109 ~/.npm/_cacache/
110 key: "${{ runner.os }}-galette-${{ matrix.php-version }}-${{ hashFiles('galette/composer.lock', 'package-lock.json') }}"
111 restore-keys: |
112 ${{ runner.os }}-galette-${{ matrix.php-version }}-
113
114 - name: Install dependencies
115 if: env.skip != 'true'
116 run: bin/install_deps
117
118 - name: Init for PostgreSQL (update)
119 env:
120 POSTGRES_HOST: localhost
121 POSTGRES_PORT: 5432
122 run: |
123 PGPASSWORD=g@l3tte psql -d galette_tests -a -f tests/pgsql_06.sql -U galette_tests -h localhost
124 if: env.skip != 'true' && startsWith(matrix.db-image, 'postgres')
125
126 - name: Init for MariaDB (update)
127 run: |
128 mysql -e 'create database IF NOT EXISTS galette_tests;' -u galette_tests --password=g@l3tte -h 127.0.0.1 -P 3306
129 mysql -e 'use galette_tests; source tests/mysql_06.sql;' -u galette_tests --password=g@l3tte -h 127.0.0.1 -P 3306
130 if: env.skip != 'true' && (startsWith(matrix.db-image, 'mysql') || startsWith(matrix.db-image, 'mariadb'))
131
132 - name: Update database tests
133 run: TESTENV=UPDATE galette/vendor/bin/phpunit --test-suffix=.php --bootstrap tests/TestsBootstrap.php --no-coverage --process-isolation tests/GaletteUpdate/
134 if: env.skip != 'true' && matrix.coverage != 'pcov'
135
136 - name: Init for PostgreSQL
137 env:
138 POSTGRES_HOST: localhost
139 POSTGRES_PORT: 5432
140 run: |
141 PGPASSWORD=g@l3tte psql -d galette_tests -a -f galette/install/scripts/pgsql.sql -U galette_tests -h localhost
142 if: env.skip != 'true' && startsWith(matrix.db-image, 'postgres')
143
144 - name: Init for MariaDB
145 run: |
146 mysql -e 'create database IF NOT EXISTS galette_tests;' -u galette_tests --password=g@l3tte -h 127.0.0.1 -P 3306
147 mysql -e 'use galette_tests; source galette/install/scripts/mysql.sql;' -u galette_tests --password=g@l3tte -h 127.0.0.1 -P 3306
148 if: env.skip != 'true' && (startsWith(matrix.db-image, 'mysql') || startsWith(matrix.db-image, 'mariadb'))
149
150 - name: Unit tests
151 run: galette/vendor/bin/phpunit --test-suffix=.php --bootstrap tests/TestsBootstrap.php --no-coverage --process-isolation tests/Galette/
152 if: env.skip != 'true' && matrix.coverage != 'pcov'
153
154 - name: Unit tests (with coverage)
155 run: galette/vendor/bin/phpunit --test-suffix=.php --bootstrap tests/TestsBootstrap.php --process-isolation --coverage-filter galette/lib --coverage-clover tests/clover.xml tests/Galette/
156 if: env.skip != 'true' && matrix.coverage == 'pcov'
157
158 - name: Upload code coverage (scrutinizer)
159 run: |
160 cd galette
161 composer require scrutinizer/ocular --ignore-platform-reqs
162 cd ..
163 php galette/vendor/bin/ocular code-coverage:upload --format=php-clover tests/clover.xml
164 if: env.skip != 'true' && matrix.coverage == 'pcov'
165
166 - name: Upload code coverage (codecov)
167 uses: codecov/codecov-action@v4
168 env:
169 CODECOV_TOKEN: 2d9dd954-bed8-4628-a267-28cd0108771b
170 with:
171 file: tests/clover.xml
172 if: env.skip != 'true' && matrix.coverage == 'pcov'
173
174 unsupported-dbs:
175 runs-on: ubuntu-latest
176 name: DB Fail on ${{ matrix.php-versions }} ${{ matrix.db-image }} ${{ (matrix.always == false && (github.event_name == 'pull_request' || github.repository != 'galette/galette' || !(github.event_name == 'workflow_dispatch' || github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/tags')))) && ' (skipped)' || ''}}
177
178 strategy:
179 matrix:
180 include:
181 - { php-version: "8.3", db-image: "postgres:10", always: true}
182 - { php-version: "8.3", db-image: "mysql:5.6", always: false}
183 - { php-version: "8.3", db-image: "mariadb:10.3", always: false}
184 fail-fast: false
185
186 env:
187 skip: ${{ matrix.always == false && (github.event_name == 'pull_request' || github.repository != 'galette/galette' || !(github.event_name == 'workflow_dispatch' || github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/tags'))) }}
188 DB: ${{ matrix.db-image }}
189
190 services:
191 # Label used to access the service container
192 db:
193 # Docker Hub image
194 image: ${{ matrix.db-image }}
195 # Provide env variables for both mysql and pgsql
196 env:
197 POSTGRES_USER: galette_tests
198 POSTGRES_PASSWORD: g@l3tte
199 POSTGRES_DB: galette_fail_tests
200 MYSQL_USER: galette_tests
201 MYSQL_PASSWORD: g@l3tte
202 MYSQL_ROOT_PASSWORD: g@l3tte
203 MYSQL_DATABASE: galette_fail_tests
204 # Open network ports for both mysql and pgsql
205 ports:
206 - 3306:3306
207 - 5432:5432
208 # Set health checks to wait until postgres has started
209 options: >-
210 --health-cmd="bash -c 'if [[ -n $(command -v pg_isready) ]]; then pg_isready; else if [[ -n $(command -v mysqladmin) ]]; then mysqladmin ping; else mariadb-admin ping; fi fi'"
211 --health-interval=10s
212 --health-timeout=5s
213 --health-retries=10
214
215 steps:
216 - name: PHP
217 if: env.skip != 'true'
218 uses: shivammathur/setup-php@v2
219 with:
220 php-version: ${{ matrix.php-versions }}
221 tools: composer, pecl
222 extensions: apcu
223 ini-values: apc.enable_cli=1
224
225 - name: "Show versions"
226 if: env.skip != 'true'
227 run: |
228 php --version
229 composer --version
230 echo "node $(node --version)"
231 echo "npm $(npm --version)"
232 docker exec ${{ job.services.db.id }} bash -c "if [[ -n \$(command -v psql) ]]; then psql --version; else if [[ -n \$(command -v mysql) ]]; then mysql --version; else mariadb --version; fi fi"
233
234 - name: Checkout
235 if: env.skip != 'true'
236 uses: actions/checkout@v4
237 with:
238 fetch-depth: 2
239
240 - name: "Restore dependencies cache"
241 if: env.skip != 'true'
242 uses: actions/cache@v4
243 with:
244 path: |
245 ~/.composer/cache/
246 ~/.npm/_cacache/
247 key: "${{ runner.os }}-galette-${{ matrix.php-version }}-${{ hashFiles('galette/composer.lock', 'package-lock.json') }}"
248 restore-keys: |
249 ${{ runner.os }}-galette-${{ matrix.php-version }}-
250
251 - name: Install dependencies
252 if: env.skip != 'true'
253 run: bin/install_deps
254
255 - name: Fail database tests
256 if: env.skip != 'true'
257 run: TESTENV=FAIL DB=${{ matrix.db-image }} galette/vendor/bin/phpunit --test-suffix=.php --bootstrap tests/TestsBootstrap.php --no-coverage --process-isolation tests/GaletteDbFails/
258
259 lint:
260 runs-on: ubuntu-latest
261 name: "Lint on PHP ${{ matrix.php-versions }}"
262
263 strategy:
264 fail-fast: false
265 matrix:
266 php-versions: [ '8.1', '8.3' ]
267
268 steps:
269 - name: PHP
270 uses: shivammathur/setup-php@v2
271 with:
272 php-version: ${{ matrix.php-versions }}
273 tools: composer, pecl
274 coverage: ${{ matrix.coverage }}
275 extensions: apcu
276 ini-values: apc.enable_cli=1
277
278 - name: "Show versions"
279 run: |
280 php --version
281 composer --version
282
283 - name: Checkout
284 uses: actions/checkout@v4
285 with:
286 fetch-depth: 2
287
288 - name: "Restore dependencies cache"
289 uses: actions/cache@v4
290 with:
291 path: |
292 ~/.composer/cache/
293 ~/.npm/_cacache/
294 key: "${{ runner.os }}-galette-${{ matrix.php-version }}-${{ hashFiles('galette/composer.lock', 'package-lock.json') }}"
295 restore-keys: |
296 ${{ runner.os }}-galette-${{ matrix.php-version }}-
297
298 - name: Install dependencies
299 run: |
300 cd galette
301 composer install --optimize-autoloader --ignore-platform-reqs
302
303 - name: CS
304 run: |
305 galette/vendor/bin/phpcs
306
307 - name: Twig CS
308 run: |
309 galette/vendor/bin/twigcs galette/templates/default --severity error --display blocking
310
311 - name: Install checker
312 working-directory: galette
313 run: composer require maglnet/composer-require-checker -W --optimize-autoloader --ignore-platform-reqs
314
315 - name: Check missing symbols
316 run: |
317 galette/vendor/bin/composer-require-checker check --config-file=.composer-require-checker.config.json galette/composer.json
318
319 - name: PHPStan checks
320 run: |
321 galette/vendor/bin/phpstan analyze --ansi --memory-limit=2G --no-interaction --no-progress
322
323 - name: Headers checks
324 run: |
325 ./galette/vendor/bin/docheader check galette/config galette/lib galette/includes galette/install galette/webroot test