-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathaction.yaml
More file actions
474 lines (413 loc) · 19.4 KB
/
action.yaml
File metadata and controls
474 lines (413 loc) · 19.4 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
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
name: "Build Sylius Test Application"
description: "Builds a Sylius plugin's test application with the given PHP, Sylius, Symfony, and database."
inputs:
# General
build_type:
required: false
description: "Build type to be used"
default: "app" # available options are "sylius" (to tests Sylius itself), "app" (to test Sylius-based application, e.g. Sylius-Standard), "plugin" (to test Sylius plugin)
application_root_dir:
required: false
description: "Working directory for composer"
default: "."
application_test_dir:
required: false
description: "The application test directory to be used (useful for monorepos with isolation tests)"
default: "" # If empty directory will be resolved based on the build type and application_root_dir
cache_key:
required: false
description: "Cache key to be used"
default: "" # If empty no cache is used
cache_restore_key:
required: false
description: "Cache restore key to be used"
default: "" # If empty no cache is used
e2e:
required: false
description: "Whether prepare the test application for e2e tests"
default: "no"
e2e_js:
required: false
description: "Whether prepare the test application for e2e tests with JS"
default: "no"
console_path:
required: false
description: "Relative path to Symfony's console binary (overrides auto-detection)"
default: ""
# Database
database:
required: false
description: "Database engine and version (e.g., 'mysql:8.4', 'postgres:16', 'mariadb:10.11')"
default: "mysql:8.4"
# PHP
php_version:
required: true
description: "PHP version to be used"
php_extensions:
required: false
description: "PHP extensions to be installed"
default: "intl, gd, opcache, mysql, pdo_mysql, pgsql, pdo_pgsql"
php_tools:
required: false
description: "PHP tools to be installed"
default: "symfony"
php_coverage:
required: false
description: "PHP coverage driver"
default: "none"
composer_ignore_platform_reqs:
required: false
description: "Whether to add --ignore-platform-reqs to composer install"
default: "no"
composer_minimum_stability:
required: false
description: "Set minimum-stability in composer.json (e.g., 'stable', 'RC', 'beta', 'alpha', 'dev')"
default: ""
composer_prefer_stable:
required: false
description: "Set prefer-stable in composer.json ('yes' or 'no')"
default: ""
# Symfony
symfony_version:
required: true
description: "Symfony version to be used"
# Sylius
sylius_version:
required: false
description: "Sylius version to be used"
default: "" # If empty no Sylius restriction is applied, also it allows to use this action while testing Sylius itself
sylius_integration:
required: false
description: "Sylius integration to be used"
default: "" # If empty no Sylius integration is applied
# Node.js (only when e2e_js is set to "yes")
node_version:
required: false
description: "Node.js version to be used"
default: "22.x"
# Chrome (only when e2e_js is set to "yes")
chrome_version:
required: false
description: "Chrome version to be used"
default: "stable"
load_fixtures:
required: false
description: "Whether to load Sylius fixtures"
default: "yes"
database_setup:
required: false
description: "Database setup strategy: 'migrations' runs doctrine:migrations:migrate, 'schema' runs doctrine:schema:create (useful for projects without migrations)"
default: "migrations"
opcache_enable:
required: false
description: "Control OPcache configuration (yes=enable with optimal settings, no=disable, empty=use system defaults)"
default: ""
runs:
using: "composite"
steps:
#####################################################################
# Set up a database #
#####################################################################
- name: Parse database input
id: db
run: |
DB_INPUT="${{ inputs.database }}"
if [[ ! "$DB_INPUT" =~ : ]]; then
echo "::error::Invalid format '$DB_INPUT'. Use 'type:version' (e.g., mysql:8.4, postgres:16, mariadb:10.11)"
exit 1
fi
DB_TYPE="${DB_INPUT%%:*}"
DB_VERSION="${DB_INPUT##*:}"
if [[ ! "$DB_TYPE" =~ ^(mysql|mariadb|postgres)$ ]]; then
echo "::error::Unsupported database type '$DB_TYPE'. Supported: mysql, mariadb, postgres"
exit 1
fi
if [[ ! "$DB_VERSION" =~ ^[0-9]+(\.[0-9]+)*$ ]]; then
echo "::error::Invalid version format '$DB_VERSION'. Version must be numeric (e.g., 8.4, 16, 10.11.13)"
exit 1
fi
if [ "$DB_TYPE" = "postgres" ]; then
DB_DRIVER="pgsql"
else
DB_DRIVER="mysql"
fi
echo "type=$DB_TYPE" >> $GITHUB_OUTPUT
echo "version=$DB_VERSION" >> $GITHUB_OUTPUT
echo "driver=$DB_DRIVER" >> $GITHUB_OUTPUT
shell: bash
- name: Shutdown default MySQL
run: sudo service mysql stop
shell: bash
- name: Setup MySQL
if: steps.db.outputs.type == 'mysql'
run: |
docker run -d \
--name mysql \
-e MYSQL_ROOT_PASSWORD=root \
-e MYSQL_USER=sylius \
-e MYSQL_PASSWORD=sylius \
-e MYSQL_DATABASE=sylius \
-p 3306:3306 \
--health-cmd="mysqladmin ping -h 127.0.0.1 --silent" \
--health-interval=5s \
--health-timeout=3s \
--health-retries=30 \
mysql:${{ steps.db.outputs.version }}
shell: bash
- name: Setup MariaDB
if: steps.db.outputs.type == 'mariadb'
run: |
docker run -d \
--name mariadb \
-e MYSQL_ROOT_PASSWORD=root \
-e MYSQL_USER=sylius \
-e MYSQL_PASSWORD=sylius \
-e MYSQL_DATABASE=sylius \
-p 3306:3306 \
--health-cmd="healthcheck.sh --connect --innodb_initialized" \
--health-interval=5s \
--health-timeout=3s \
--health-retries=30 \
mariadb:${{ steps.db.outputs.version }}
shell: bash
- name: Setup PostgreSQL
if: steps.db.outputs.type == 'postgres'
run: |
docker run -d \
--name postgres \
-e POSTGRES_USER=sylius \
-e POSTGRES_PASSWORD=sylius \
-e POSTGRES_DB=sylius \
-p 5432:5432 \
--health-cmd="pg_isready -U sylius" \
--health-interval=5s \
--health-timeout=3s \
--health-retries=30 \
postgres:${{ steps.db.outputs.version }}
shell: bash
- name: Wait for database to be ready
run: |
if [ "${{ steps.db.outputs.type }}" = "postgres" ]; then
CONTAINER="postgres"
elif [ "${{ steps.db.outputs.type }}" = "mariadb" ]; then
CONTAINER="mariadb"
else
CONTAINER="mysql"
fi
for i in {1..75}; do
STATUS=$(docker inspect --format='{{.State.Health.Status}}' "$CONTAINER" 2>/dev/null || echo "starting")
if [ "$STATUS" = "healthy" ]; then
echo "Database is ready!"
break
fi
if [ "$STATUS" = "unhealthy" ]; then
echo "::error::Database container is unhealthy"
docker logs "$CONTAINER"
exit 1
fi
echo "Waiting for database... ($i/75, status: $STATUS)"
sleep 2
done
if [ "$STATUS" != "healthy" ]; then
echo "::error::Database failed to become healthy within 150s"
docker logs "$CONTAINER"
exit 1
fi
shell: bash
- name: Optimize PostgreSQL for CI
if: steps.db.outputs.type == 'postgres'
run: |
export PGPASSWORD=sylius
psql -h 127.0.0.1 -U sylius -d sylius -c "ALTER SYSTEM SET fsync = 'off';"
psql -h 127.0.0.1 -U sylius -d sylius -c "ALTER SYSTEM SET synchronous_commit = 'off';"
psql -h 127.0.0.1 -U sylius -d sylius -c "ALTER SYSTEM SET full_page_writes = 'off';"
psql -h 127.0.0.1 -U sylius -d sylius -c "ALTER SYSTEM SET shared_buffers = '256MB';"
psql -h 127.0.0.1 -U sylius -d sylius -c "ALTER SYSTEM SET work_mem = '64MB';"
psql -h 127.0.0.1 -U sylius -d sylius -c "SELECT pg_reload_conf();"
shell: bash
- name: Set DATABASE_URL
run: echo "DATABASE_URL=${{ steps.db.outputs.driver }}://sylius:sylius@127.0.0.1/sylius?serverVersion=${{ steps.db.outputs.version }}" >> $GITHUB_ENV
shell: bash
#####################################################################
# Set up PHP & Symfony & Sylius #
#####################################################################
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "${{ inputs.php_version }}"
extensions: "${{ inputs.php_extensions }}"
tools: "${{ inputs.php_tools }}"
coverage: "${{ inputs.php_coverage }}"
ini-values: ${{ inputs.opcache_enable == 'yes' && 'opcache.enable=1, opcache.enable_cli=0, opcache.validate_timestamps=1, opcache.revalidate_freq=0' || inputs.opcache_enable == 'no' && 'opcache.enable=0, opcache.enable_cli=0' || '' }}
- name: Output PHP version for Symfony CLI
run: php -v | head -n 1 | awk '{ print $2 }' > .php-version
shell: bash
- name: Restrict Symfony version
run: |
composer global config --no-plugins allow-plugins.symfony/flex true
composer global require --no-progress --no-scripts --no-plugins "symfony/flex:^1.17 || ^2.0"
composer config extra.symfony.require "${{ inputs.symfony_version }}"
shell: bash
working-directory: "${{ inputs.application_root_dir }}"
- name: Restrict Sylius version
if: inputs.sylius_version != '' && inputs.build_type != 'sylius'
run: composer require "sylius/sylius:${{ inputs.sylius_version }}" --no-update --no-scripts --no-interaction
shell: bash
working-directory: "${{ inputs.application_root_dir }}"
- name: Set minimum-stability
if: inputs.composer_minimum_stability != ''
run: composer config minimum-stability "${{ inputs.composer_minimum_stability }}"
shell: bash
working-directory: "${{ inputs.application_root_dir }}"
- name: Set prefer-stable
if: inputs.composer_prefer_stable != ''
run: composer config prefer-stable "${{ inputs.composer_prefer_stable == 'yes' && 'true' || 'false' }}"
shell: bash
working-directory: "${{ inputs.application_root_dir }}"
- name: Get Composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
shell: bash
- name: "Restore dependencies"
if: inputs.cache_key != ''
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ inputs.cache_key }}
restore-keys: |
${{ inputs.cache_restore_key }}
- name: Install PHP dependencies
run: |
if [ "${{ inputs.composer_ignore_platform_reqs }}" = "yes" ]; then
composer install --no-interaction --ignore-platform-reqs
else
composer install --no-interaction
fi
env:
COMPOSER_ROOT_VERSION: dev-main
shell: bash
working-directory: "${{ inputs.application_root_dir }}"
- name: Install Sylius integration
if: inputs.sylius_integration != '' && inputs.build_type != 'sylius'
run: composer integration ${{ inputs.sylius_integration }}
env:
COMPOSER_ROOT_VERSION: dev-main
shell: bash
working-directory: "${{ inputs.application_root_dir }}"
#####################################################################
# Determine test application directory and console #
#####################################################################
-
name: Set test_dir environment variable
shell: bash
env:
BUILD_TYPE: ${{ inputs.build_type }}
APPLICATION_ROOT_DIR: ${{ inputs.application_root_dir }}
APPLICATION_TEST_DIR: ${{ inputs.application_test_dir }}
run: |
if [ "$APPLICATION_TEST_DIR" != "" ]; then
echo "test_dir=${APPLICATION_TEST_DIR}" >> $GITHUB_ENV
elif [ -d "vendor/sylius/test-application" ]; then
echo "test_dir=vendor/sylius/test-application" >> $GITHUB_ENV
elif [ "$BUILD_TYPE" = "plugin" ]; then
echo "test_dir=tests/Application" >> $GITHUB_ENV
else
echo "test_dir=${APPLICATION_ROOT_DIR}" >> $GITHUB_ENV
fi
- name: Determine which console to use
shell: bash
run: |
if [ -n "${{ inputs.console_path }}" ]; then
echo "CONSOLE=${{ inputs.console_path }}" >> $GITHUB_ENV
elif [ -f "${{ env.test_dir }}/../../bin/console" ]; then
echo "CONSOLE=../../bin/console" >> $GITHUB_ENV
elif [ -f "${{ env.test_dir }}/vendor/bin/console" ]; then
echo "CONSOLE=vendor/bin/console" >> $GITHUB_ENV
else
echo "CONSOLE=bin/console" >> $GITHUB_ENV
fi
#####################################################################
# Prepare for end-to-end tests #
#####################################################################
- name: Remove default Google Chrome installation
if: inputs.e2e_js == 'yes'
run: |
which google-chrome && google-chrome --version || echo "Google Chrome successfully removed"
sudo dpkg --remove google-chrome-stable
sudo apt-get purge -y google-chrome-stable
sudo rm -f /usr/bin/google-chrome /usr/bin/chromedriver
which google-chrome && google-chrome --version || echo "Google Chrome successfully removed"
which chromedriver || echo "Google Chromedriver successfully removed"
shell: bash
- name: Setup Chrome
if: inputs.e2e_js == 'yes'
uses: browser-actions/setup-chrome@v2
with:
chrome-version: "${{ inputs.chrome_version }}"
install-chromedriver: 'true'
- name: Run Chrome Headless
if: inputs.e2e_js == 'yes'
run: |
export DISPLAY=:99
chrome --enable-automation --disable-background-networking --no-default-browser-check --no-first-run --disable-popup-blocking --disable-default-apps --allow-insecure-localhost --disable-translate --remote-debugging-port=9222 --disable-extensions --no-sandbox --enable-features=Metal --headless --window-size=2880,1800 --proxy-server='direct://' --proxy-bypass-list='*' http://127.0.0.1 > /dev/null 2>&1 &
shell: bash
working-directory: "${{ env.test_dir }}"
- name: Run webserver
if: inputs.e2e == 'yes' || inputs.e2e_js == 'yes'
run: symfony server:start --port=8080 --dir=${{ env.test_dir }}/public --daemon --no-tls
shell: bash
- name: Configure Encore for non-JS end-to-end tests
if: inputs.e2e == 'yes' && inputs.e2e_js == 'no'
run: |
mkdir -p public/build/admin public/build/shop
echo "{}" > public/build/admin/manifest.json
echo "{}" > public/build/shop/manifest.json
shell: bash
working-directory: "${{ env.test_dir }}"
#####################################################################
# Set up Node.js #
#####################################################################
- name: Setup Node
if: inputs.e2e_js == 'yes' && inputs.node_version != ''
uses: actions/setup-node@v4
with:
node-version: "${{ inputs.node_version }}"
- name: Install JS dependencies
if: inputs.e2e_js == 'yes' && inputs.node_version != ''
run: yarn install
shell: bash
working-directory: "${{ env.test_dir }}"
- name: Build JS assets
if: inputs.e2e_js == 'yes' && inputs.node_version != ''
run: yarn build
shell: bash
working-directory: "${{ env.test_dir }}"
#####################################################################
# Prepare the application #
#####################################################################
- name: Prepare application database
run: |
$CONSOLE doctrine:database:create --if-not-exists -vvv
if [ "${{ inputs.database_setup }}" = "schema" ]; then
$CONSOLE doctrine:schema:update --force -vvv
else
$CONSOLE doctrine:migrations:migrate -n -vvv
fi
shell: bash
working-directory: "${{ env.test_dir }}"
- name: Install assets
run: $CONSOLE assets:install public -vvv
shell: bash
working-directory: "${{ env.test_dir }}"
- name: Warm up cache
run: $CONSOLE cache:warmup -vvv
shell: bash
working-directory: "${{ env.test_dir }}"
- name: Load fixtures
if: inputs.load_fixtures == 'yes'
run: $CONSOLE sylius:fixtures:load -n
shell: bash
working-directory: "${{ env.test_dir }}"
branding:
icon: activity
color: green