Skip to content

Commit 3c8a449

Browse files
[CI] Use BuildTestAppAction (#413)
| Q | A | --------------- | ----- | Branch? | 2.1 | Bug fix? | no | New feature? | no | Related tickets | - Refactors `.github/workflows/build.yaml` to use `SyliusLabs/BuildTestAppAction@v3.2.0` instead of manually defining all setup steps. Also changes scheduled run from weekly to daily. Refs: - https://docs.sylius.com/plugins-development-guide/test-application - https://github.com/SyliusLabs/BuildTestAppAction
2 parents bf898e0 + c556588 commit 3c8a449

File tree

1 file changed

+48
-158
lines changed

1 file changed

+48
-158
lines changed

.github/workflows/build.yaml

Lines changed: 48 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@ on:
55
branches-ignore:
66
- 'dependabot/**'
77
- 'upmerge/**'
8-
pull_request: ~
8+
paths-ignore:
9+
- "*.md"
10+
pull_request:
11+
paths-ignore:
12+
- "*.md"
913
release:
1014
types: [ created ]
1115
schedule:
1216
-
13-
cron: "0 1 * * 6" # Run at 1am every Saturday
17+
cron: "0 1 * * *" # Run at 1am every day
1418
workflow_dispatch: ~
1519

1620
concurrency:
@@ -21,214 +25,100 @@ jobs:
2125
tests:
2226
runs-on: ubuntu-latest
2327

24-
name: "Sylius ${{ matrix.sylius }}, PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}, ${{ matrix.database == 'mysql' && format('MySQL {0}', matrix.mysql) || matrix.database == 'postgres' && format('PostgreSQL {0}', matrix.postgres) }}, State Machine Adapter ${{ matrix.state_machine_adapter }}"
28+
name: "Sylius ${{ matrix.sylius }}, PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}, ${{ matrix.database }}, State Machine Adapter ${{ matrix.state_machine_adapter }}"
2529

2630
strategy:
2731
fail-fast: false
2832
matrix:
2933
php: ["8.2", "8.3"]
3034
symfony: ["^6.4", "^7.4"]
3135
sylius: ["~2.0.1", "~2.1.0", "~2.2.0"]
32-
database: ["mysql", "postgres"]
33-
mysql: ["8.4"]
34-
postgres: ["15.8"]
36+
database: ["mysql:8.4", "postgres:16"]
3537
node: ["22.x"]
3638
state_machine_adapter: ["symfony_workflow"]
3739

3840
include:
39-
- php: "8.3"
40-
symfony: "~7.3.0"
41-
sylius: "~2.1.0"
42-
node: "24.x"
43-
database: "mysql"
44-
mysql: "8.4"
45-
state_machine_adapter: "winzou_state_machine"
46-
4741
-
4842
php: "8.3"
4943
symfony: "~7.3.0"
5044
sylius: "~2.1.0"
5145
node: "24.x"
52-
database: "postgres"
53-
postgres: "15.8"
54-
state_machine_adapter: "symfony_workflow"
46+
database: "mysql:8.4"
47+
state_machine_adapter: "winzou_state_machine"
5548

5649
env:
5750
APP_ENV: test
58-
DATABASE_URL: ${{ matrix.database == 'mysql' && format('mysql://root:root@127.0.0.1/sylius?serverVersion={0}', matrix.mysql) || format('pgsql://postgres:postgres@127.0.0.1/sylius?serverVersion={0}', matrix.postgres) }}
5951
TEST_SYLIUS_STATE_MACHINE_ADAPTER: "${{ matrix.state_machine_adapter }}"
6052

6153
steps:
6254
-
6355
uses: actions/checkout@v4
6456

6557
-
66-
name: Setup PHP
67-
uses: shivammathur/setup-php@v2
68-
with:
69-
php-version: "${{ matrix.php }}"
70-
extensions: intl
71-
tools: flex, symfony
72-
coverage: none
73-
74-
-
75-
name: Setup Node
76-
uses: actions/setup-node@v4
77-
with:
78-
node-version: "${{ matrix.node }}"
79-
80-
-
81-
name: Shutdown default database services
82-
run: |
83-
sudo service mysql stop || true
84-
sudo service postgresql stop || true
85-
86-
-
87-
name: Setup MySQL
88-
if: matrix.database == 'mysql'
89-
uses: mirromutth/mysql-action@v1.1
90-
with:
91-
mysql version: "${{ matrix.mysql }}"
92-
mysql root password: "root"
93-
94-
-
95-
name: Setup PostgreSQL
96-
if: matrix.database == 'postgres'
97-
uses: harmon758/postgresql-action@v1
98-
with:
99-
postgresql version: "${{ matrix.postgres }}"
100-
postgresql password: "postgres"
101-
102-
-
103-
name: Output PHP version for Symfony CLI
104-
run: php -v | head -n 1 | awk '{ print $2 }' > .php-version
105-
106-
-
107-
name: Get Composer cache directory
108-
id: composer-cache
109-
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
110-
111-
-
112-
name: Cache Composer
113-
uses: actions/cache@v4
114-
with:
115-
path: ${{ steps.composer-cache.outputs.dir }}
116-
key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.json **/composer.lock') }}
117-
restore-keys: |
118-
${{ runner.os }}-php-${{ matrix.php }}-composer-
119-
120-
-
121-
name: Restrict Symfony version
122-
if: matrix.symfony != ''
58+
name: Parse database string
12359
run: |
124-
composer global config --no-plugins allow-plugins.symfony/flex true
125-
composer global require --no-progress --no-scripts --no-plugins "symfony/flex:^2.4"
126-
composer config extra.symfony.require "${{ matrix.symfony }}"
60+
DB_TYPE="${DATABASE%%:*}"
61+
DB_VERSION="${DATABASE##*:}"
62+
echo "DB_TYPE=$DB_TYPE" >> $GITHUB_ENV
63+
echo "DB_VERSION=$DB_VERSION" >> $GITHUB_ENV
12764
128-
-
129-
name: Restrict Sylius version
130-
if: matrix.sylius != ''
131-
run: composer require "sylius/sylius:${{ matrix.sylius }}" --no-update --no-scripts --no-interaction
65+
if [ "$DB_TYPE" = "postgres" ]; then
66+
echo "DATABASE_URL=pgsql://postgres:postgres@127.0.0.1/sylius?serverVersion=$DB_VERSION" >> $GITHUB_ENV
67+
else
68+
echo "DATABASE_URL=mysql://root:root@127.0.0.1/sylius?serverVersion=$DB_VERSION" >> $GITHUB_ENV
69+
fi
70+
env:
71+
DATABASE: ${{ matrix.database }}
13272

13373
-
13474
name: Require Winzou State Machine
13575
if: "${{ matrix.state_machine_adapter == 'winzou_state_machine' }}"
13676
run: |
137-
composer require winzou/state-machine:^0.4 --no-update
138-
composer require winzou/state-machine-bundle:^0.6 --no-update
139-
140-
-
141-
name: Install PHP dependencies
142-
run: composer install --no-interaction
143-
144-
-
145-
name: Run PHPStan
146-
run: vendor/bin/phpstan analyse -c phpstan.neon.dist
147-
148-
-
149-
name: Run ECS
150-
run: vendor/bin/ecs check src/
77+
composer require winzou/state-machine:^0.4 --no-update
78+
composer require winzou/state-machine-bundle:^0.6 --no-update
15179
15280
-
153-
name: Run unit tests
154-
run: vendor/bin/phpunit --colors=always --testsuite=unit
155-
156-
-
157-
name: Get Yarn cache directory
158-
id: yarn-cache
159-
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
160-
161-
-
162-
name: Cache Yarn
163-
uses: actions/cache@v4
81+
name: Build Sylius Test Application
82+
uses: SyliusLabs/BuildTestAppAction@v3.2.0
16483
with:
165-
path: ${{ steps.yarn-cache.outputs.dir }}
166-
key: ${{ runner.os }}-node-${{ matrix.node }}-yarn-${{ hashFiles('**/package.json **/yarn.lock') }}
167-
restore-keys: |
168-
${{ runner.os }}-node-${{ matrix.node }}-yarn-
169-
170-
-
171-
name: Install JS dependencies
172-
run: (cd vendor/sylius/test-application && yarn install)
173-
174-
- name: Check out database schema update
175-
run: |
176-
vendor/bin/console doctrine:database:create
177-
vendor/bin/console doctrine:schema:update --force
178-
vendor/bin/console doctrine:schema:validate
179-
vendor/bin/console doctrine:database:drop --force
180-
181-
-
182-
name: Prepare test application database
183-
run: |
184-
vendor/bin/console doctrine:database:create -vvv
185-
vendor/bin/console doctrine:migrations:migrate -n -vvv -q
84+
e2e_js: "yes"
85+
cache_key: "${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}"
86+
cache_restore_key: "${{ runner.os }}-php-${{ matrix.php }}-composer-"
87+
database: "${{ env.DB_TYPE }}"
88+
database_version: "${{ env.DB_VERSION }}"
89+
node_version: "${{ matrix.node }}"
90+
php_version: "${{ matrix.php }}"
91+
sylius_version: "${{ matrix.sylius }}"
92+
symfony_version: "${{ matrix.symfony }}"
18693

18794
-
188-
name: Setup messenger transports
189-
run: vendor/bin/console messenger:setup-transports -vvv
95+
name: Run security check
96+
run: composer audit --abandoned=ignore
19097

19198
-
192-
name: Validate database schema
193-
run: vendor/bin/console doctrine:schema:validate -vvv
194-
195-
-
196-
name: Prepare test application assets
197-
run: |
198-
vendor/bin/console assets:install -vvv
199-
(cd vendor/sylius/test-application && yarn build)
99+
name: Validate composer.json
100+
run: composer validate --ansi --strict
200101

201102
-
202-
name: Prepare test application cache
203-
run: vendor/bin/console cache:warmup -vvv
103+
name: Run ECS
104+
run: vendor/bin/ecs check src/
204105

205106
-
206-
name: Validate container
107+
name: Lint container
207108
run: vendor/bin/console lint:container -vvv
208109

209-
- name: Run security check
210-
run: symfony security:check
211-
212110
-
213-
name: Validate composer.json
214-
run: composer validate --ansi --strict
111+
name: Run PHPStan
112+
run: vendor/bin/phpstan analyse -c phpstan.neon.dist
215113

216114
-
217-
name: Load fixtures in test application
218-
run: vendor/bin/console sylius:fixtures:load -n
115+
name: Run PHPUnit (Unit)
116+
run: vendor/bin/phpunit --colors=always --testsuite=unit
219117

220118
-
221-
name: Run Non-unit PHPUnit tests
119+
name: Run PHPUnit (Non-unit)
222120
run: vendor/bin/phpunit --colors=always --testsuite=non-unit
223121

224-
-
225-
name: Run Chrome Headless
226-
run: google-chrome-stable --enable-automation --disable-background-networking --no-default-browser-check --no-first-run --disable-popup-blocking --disable-default-apps --allow-insecure-localhost --disable-translate --disable-extensions --no-sandbox --enable-features=Metal --headless --remote-debugging-port=9222 --window-size=2880,1800 --proxy-server='direct://' --proxy-bypass-list='*' http://127.0.0.1 > /dev/null 2>&1 &
227-
228-
-
229-
name: Run webserver
230-
run: symfony server:start --port=8080 --daemon
231-
232122
-
233123
name: Run Behat
234124
run: vendor/bin/behat --colors --strict -vvv --no-interaction -f progress || vendor/bin/behat --colors --strict -vvv --no-interaction -f progress --rerun
@@ -238,7 +128,7 @@ jobs:
238128
uses: actions/upload-artifact@v4
239129
if: failure()
240130
with:
241-
name: "Behat logs - ${{ matrix.sylius }}-${{ github.run_id }}-${{ github.run_number }}"
131+
name: "Behat logs - Sylius ${{ matrix.sylius }}, PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}, ${{ matrix.database }}"
242132
path: etc/build/
243133
if-no-files-found: ignore
244134
compression-level: 6

0 commit comments

Comments
 (0)