-
Notifications
You must be signed in to change notification settings - Fork 6
380 lines (334 loc) · 13.1 KB
/
Copy pathci-linux.yml
File metadata and controls
380 lines (334 loc) · 13.1 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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
name: Linux
on:
push:
branches:
- main
- develop
tags:
- '*'
pull_request:
# Enable manual run
workflow_dispatch:
concurrency:
group: "${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: true
jobs:
setup-phpunit-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.gen.outputs.matrix }}
steps:
- uses: actions/checkout@v7
- id: gen
uses: galette/.github/actions/matrix-generator@main
with:
all-jobs: ${{ github.event_name != 'pull_request' && github.repository == 'galette-plugins/galette-oauth2' && (github.event_name == 'workflow_dispatch' || github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/tags')) }}
setup-lint-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.gen.outputs.matrix }}
steps:
- uses: actions/checkout@v7
- id: gen
uses: galette/.github/actions/matrix-generator@main
with:
target: lint
all-jobs: ${{ github.event_name != 'pull_request' && github.repository == 'galette-plugins/galette-oauth2' && (github.event_name == 'workflow_dispatch' || github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/tags')) }}
lint:
runs-on: ubuntu-latest
needs: setup-lint-matrix
name: "Lint on PHP ${{ matrix.php-version }}"
strategy:
matrix: ${{ fromJSON(needs.setup-lint-matrix.outputs.matrix) }}
fail-fast: false
steps:
- name: PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
tools: composer
coverage: ${{ matrix.coverage }}
- name: Checkout Galette core
uses: actions/checkout@v7
with:
repository: galette/galette
path: galette-core
fetch-depth: 1
ref: develop
- name: Checkout plugin
uses: actions/checkout@v7
with:
path: galette-core/galette/plugins/plugin-oauth2
- name: Install dependencies
run: |
cd galette-core
composer install --ignore-platform-reqs
cd galette/plugins/plugin-oauth2
composer install --ignore-platform-reqs
- name: CS
run: |
cd galette-core/galette/plugins/plugin-oauth2
../../vendor/bin/phpcs lib/ ./*.php
- name: CS Fixer
if: matrix.php-is-min
run: |
cd galette-core/galette/plugins/plugin-oauth2
../../vendor/bin/php-cs-fixer check --show-progress=dots --verbose --diff
- name: Twig CS
run: |
cd galette-core/galette/plugins/plugin-oauth2
../../vendor/bin/twigcs templates/default --severity error --display blocking
- name: PHPStan checks
run: |
cd galette-core/galette/plugins/plugin-oauth2
../../vendor/bin/phpstan analyze --ansi --memory-limit=2G --no-interaction --no-progress
- name: Headers checks
run: |
cd galette-core
./bin/console galette:headers:check \
--project-name="Galette OAuth2 plugin" \
--start-year="2021" \
--project-url="https://galette-plugins.github.io/plugin-oauth2/" \
--directory="galette/plugins/plugin-oauth2"
unit-tests:
runs-on: ubuntu-latest
needs: setup-phpunit-matrix
strategy:
matrix: ${{ fromJSON(needs.setup-phpunit-matrix.outputs.matrix) }}
fail-fast: false
env:
DB: ${{ matrix.db-image }}
services:
# Label used to access the service container
db:
# Docker Hub image
image: ${{ matrix.db-image }}
# Provide env variables for both mysql and pgsql
env:
POSTGRES_USER: galette_tests
POSTGRES_PASSWORD: g@l3tte
POSTGRES_DB: galette_tests
MYSQL_USER: galette_tests
MYSQL_PASSWORD: g@l3tte
MYSQL_ROOT_PASSWORD: g@l3tte
MYSQL_DATABASE: galette_tests
# Open network ports for both mysql and pgsql
ports:
- 3306:3306
- 5432:5432
# Set health checks to wait until postgres has started
options: >-
--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'"
--health-interval=10s
--health-timeout=5s
--health-retries=10
name: PHP ${{ matrix.php-version }} ${{ matrix.db-image }} ${{ (matrix.always == false && (github.event_name == 'pull_request' || github.repository != 'galette/plugin-oauth2' || !(github.event_name == 'workflow_dispatch' || github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/tags')))) && ' (skipped)' || matrix.coverage == 'xdebug' && ' (with coverage)' || ''}}
steps:
- name: PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
tools: composer, pecl
coverage: ${{ matrix.coverage }}
extensions: apcu
ini-values: apc.enable_cli=1
- name: Show database version
run: |
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"
- name: Build Galette
uses: galette/.github/actions/build-galette@main
with:
php-version: ${{ matrix.php-version }}
- name: Checkout plugin
uses: actions/checkout@v7
with:
path: galette-core/galette/plugins/plugin-oauth2
- name: Install plugin dependencies
run: |
cd galette-core/galette/plugins/plugin-oauth2
composer install --ignore-platform-reqs
- name: Generate keys
run: |
cd galette-core/galette/plugins/plugin-oauth2/tests/config
openssl genrsa -out private.key 2048
openssl rsa -in private.key -pubout -out public.key
chmod 660 *.key
DEFUSE_KEY=$(../../vendor/bin/generate-defuse-key)
cat > encryption-key.php << 'EOFKEY'
<?php
declare(strict_types=1);
EOFKEY
echo "\$encryptionKey = '${DEFUSE_KEY}';" >> encryption-key.php
cat encryption-key.php
- name: Init for PostgreSQL
env:
POSTGRES_HOST: localhost
POSTGRES_PORT: 5432
run: |
cd galette-core
bin/console galette:install -v --dbtype=pgsql --dbhost=localhost --dbname=galette_tests --dbuser=galette_tests --dbpass=g@l3tte --admin=admin --password=admin --no-interaction -w
bin/console galette:plugins:enable --all
bin/console galette:plugins:list --enabled --complete
if: env.skip != 'true' && startsWith(matrix.db-image, 'postgres')
- name: Init for MariaDB
run: |
cd galette-core
mysql -e 'create database IF NOT EXISTS galette_tests;' -u galette_tests --password=g@l3tte -h 127.0.0.1 -P 3306
bin/console galette:install -v --dbtype=mysql --dbhost=127.0.0.1 --dbname=galette_tests --dbuser=galette_tests --dbpass=g@l3tte --admin=admin --password=admin --no-interaction -w
bin/console galette:plugins:enable --all
bin/console galette:plugins:list --enabled --complete
if: startsWith(matrix.db-image, 'mysql') || startsWith(matrix.db-image, 'mariadb')
- name: Unit tests
run: |
cd galette-core/galette/webroot
DB=${{ env.DB }} php -S localhost:8888 ../plugins/plugin-oauth2/tests/router.php &
cd ../plugins/plugin-oauth2
../../vendor/bin/phpunit --test-suffix=.php --bootstrap tests/TestsBootstrap.php --no-coverage --process-isolation tests/GaletteOAuth2/
- name: Sanitize ref name for artifact upload
if: failure()
id: sanitize
run: |
db_image=$(echo -n "${{ matrix.db-image }}" | sed 's/[\\\/'"'"':<>|*?]/-/g')
echo "db_image=$db_image" >> $GITHUB_OUTPUT
- name: Upload test data (logs, photos, etc.)
uses: actions/upload-artifact@v7
if: failure()
with:
name: test-data-${{ matrix.php-version }}-${{ steps.sanitize.outputs.db_image }}
path: |
galette-core/tests/tests-data/
galette-core/galette/data/logs/
galette-core/galette/data/photos/
retention-days: 7
if-no-files-found: ignore
e2e-tests:
runs-on: ubuntu-latest
name: "E2E Playwright — ${{ github.event_name == 'schedule' && 'all browsers' || 'chromium' }} (postgres:17)"
env:
DB: pgsql
GALETTE_TESTS: 1
services:
db:
image: postgres:17
env:
POSTGRES_USER: galette_tests
POSTGRES_PASSWORD: g@l3tte
POSTGRES_DB: galette_tests
ports:
- 5432:5432
options: >-
--health-cmd="pg_isready"
--health-interval=10s
--health-timeout=5s
--health-retries=10
steps:
- name: PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.5"
tools: composer, pecl
coverage: none
extensions: apcu, pdo_pgsql
ini-values: apc.enable_cli=1
- name: Build Galette
uses: galette/.github/actions/build-galette@main
with:
php-version: "8.5"
enable-assets-cache: true
- name: Checkout plugin
uses: actions/checkout@v7
with:
path: galette-core/galette/plugins/plugin-oauth2
- name: Install plugin dependencies
run: |
cd galette-core/galette/plugins/plugin-oauth2
composer install --ignore-platform-reqs
- name: Generate OAuth2 keys
run: |
cd galette-core/galette/plugins/plugin-oauth2
# Generate keys for production config path (used by E2E tests)
openssl genrsa -out config/private.key 2048
openssl rsa -in config/private.key -pubout -out config/public.key
chmod 660 config/*.key
# Generate encryption key
DEFUSE_KEY=$(vendor/bin/generate-defuse-key)
cat > config/encryption-key.php << 'EOFKEY'
<?php
declare(strict_types=1);
EOFKEY
echo "\$encryptionKey = '${DEFUSE_KEY}';" >> config/encryption-key.php
# Create a minimal config.yml for E2E tests
cp tests/config/config.yml config/config.yml
cat config/encryption-key.php
- name: Initialize test data
run: |
cd galette-core
php tests/init_test_data.php
- name: Initialize Galette database
run: |
cd galette-core
bin/console galette:install -v \
--dbtype=pgsql \
--dbhost=localhost \
--dbname=galette_tests \
--dbuser=galette_tests \
--dbpass=g@l3tte \
--admin=admin \
--password=admin \
--no-interaction
env:
POSTGRES_HOST: localhost
POSTGRES_PORT: 5432
- name: Seed E2E fixtures
run: |
cd galette-core
bin/console galette:seed-fixtures -v
- name: Start PHP built-in server
run: |
cd galette-core
GALETTE_PLUGINS_PATH=$(pwd)/galette/plugins DB=${{ env.DB }} GALETTE_TESTS=1 php -S 0.0.0.0:8090 -t galette/webroot tests/router_e2e.php &
timeout 15 bash -c 'until curl -sf http://127.0.0.1:8090/login > /dev/null; do sleep 1; done'
CODE=$(curl -s -o /dev/null -w "%{http_code}" "http://127.0.0.1:8090/plugins/oauth2/authorize?response_type=code&client_id=galette_cli&redirect_uri=http://127.0.0.1:8090/plugins/oauth2/test-callback&scope=member&state=ci-check")
if [ "$CODE" = "404" ]; then
echo "OAuth2 route returned 404 (plugin not initialized/active)."
exit 1
fi
echo "PHP server started"
- name: Install Playwright browsers
run: |
cd galette-core
if [ "${{ github.event_name }}" == "schedule" ]; then
npx playwright install --with-deps chromium firefox
else
npx playwright install --with-deps chromium
fi
- name: Run OAuth2 E2E tests
run: |
cd galette-core
if [ "${{ github.event_name }}" == "schedule" ]; then
npm run test:plugins:all
else
npm run test:plugins
fi
env:
E2E_BASE_URL: http://127.0.0.1:8090
E2E_ADMIN_USER: admin
E2E_ADMIN_PASS: admin
- name: Upload Playwright report
uses: actions/upload-artifact@v7
if: failure()
with:
name: playwright-report-oauth2
path: galette-core/playwright-report/
retention-days: 7
- name: Upload test data (logs, photos, etc.)
uses: actions/upload-artifact@v7
if: failure()
with:
name: test-data-e2e-oauth2
path: |
galette-core/tests/tests-data/
galette-core/galette/data/logs/
galette-core/galette/data/photos/
retention-days: 7
if-no-files-found: ignore