Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 42 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The goal of this action is to reduce the repetitive part of our every Sylius Git

## Usage

Below you can find an example of a workflow file that uses this action. Keep in mind `actions/checkout@v2`
Below you can find an example of a workflow file that uses this action. Keep in mind `actions/checkout@v4`
action is required and must be run **before** `SyliusLabs/BuildTestAppAction` action.

```yaml
Expand All @@ -17,60 +17,66 @@ jobs:
tests:
runs-on: ubuntu-latest

name: "Sylius ${{ matrix.sylius }}, PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}, MySQL ${{ matrix.mysql }}"
name: "Sylius ${{ matrix.sylius }}, PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}, ${{ matrix.database }}"

env:
APP_ENV: test_cached
DATABASE_URL: "mysql://root:root@127.0.0.1/sylius?serverVersion=${{ matrix.mysql }}"

strategy:
fail-fast: false
matrix:
php: [ "8.1" ]
symfony: [ "^5.4" ]
sylius: [ "1.12", "1.13" ]
node: [ "16.x" ]
mysql: [ "8.0" ]
php: ["8.3"]
symfony: ["^6.4", "^7.4"]
sylius: ["~2.1.0", "~2.2.0"]
database: ["mysql:8.4"]

include:
- php: "8.3"
symfony: "^7.4"
sylius: "~2.2.0"
database: "postgres:16"

steps:
- uses: actions/checkout@v4

- name: Build application
uses: SyliusLabs/BuildTestAppAction@v3.0
uses: SyliusLabs/BuildTestAppAction@v4
with:
e2e: "yes"
database_version: ${{ matrix.mysql }}
database: ${{ matrix.database }}
php_version: ${{ matrix.php }}
symfony_version: ${{ matrix.symfony }}
sylius_version: ${{ matrix.sylius }}

- name: Run Behat
run: |
vendor/bin/behat
run: vendor/bin/behat
```

The action automatically sets `DATABASE_URL` environment variable with unified credentials (`sylius:sylius@sylius`).
No need to define it in your workflow.

## Inputs

| Name | Description | Default | Required to be explicitly defined |
|------------------------------|----------------------------------------------------------------------------------------|---------------------------------------------------------|-----------------------------------|
| `build_type` | Type of the build. Possible values: `sylius`, `app`, `plugin`. | `app` | No |
| `application_root_dir` | Root directory of the application (useful in monorepos). | Resolved automatically based on `build_type`. | No |
| `application_test_dir` | Directory of the test application (used to run console commands, fixtures, etc.). | Resolved automatically based on `build_type`. | No |
| `console_path` | Relative path to Symfony's `console` binary (overrides auto-detection) | `vendor/bin/console` or `bin/console` (auto) | No |
| `cache_key` | A cache key to be used (used with `actions/cache`). | *(empty)* | No |
| `cache_restore_key` | A cache restore key to be used. | *(empty)* | No |
| `e2e` | Whether to prepare the test application for end-to-end tests. | `no` | No |
| `e2e_js` | Whether to prepare the test application for JS-based end-to-end tests. | `no` | No |
| `database` | Database engine to use. One of: `mysql`, `mariadb`, `postgres` (or `postgresql` - deprecated). | `mysql` | Yes |
| `database_version` | Version of the database to be used. | `8.0` (MySQL) | No |
| `php_version` | PHP version to be used. | *(none)* | Yes |
| `php_extensions` | List of PHP extensions to install. | `intl, gd, opcache, mysql, pdo_mysql, pgsql, pdo_pgsql` | No |
| `php_tools` | PHP tools to install (e.g. `symfony`, `composer`). | `symfony` | No |
| `php_coverage` | Coverage tool to use (e.g. `xdebug`, `pcov`, `none`). | `none` | No |
| `symfony_version` | Symfony version to be used. | *(none)* | Yes |
| `sylius_version` | Sylius version to be used. | *(none)* – no restriction applied | No |
| `sylius_integration` | Internal usage: run Sylius with a specific integration. | *(empty)* | No |
| `node_version` | Node.js version to install (used when `e2e_js: yes`). | `20.x` | No |
| `chrome_version` | Google Chrome version to install (for JS e2e tests). | `stable` | No |
| `opcache_enable` | Control OPcache (`yes`=enable with test-optimized settings, `no`=disable). | *(empty)* – use system defaults | No |
| `composer_minimum_stability` | Set minimum-stability in composer.json (e.g., `stable`, `RC`, `beta`, `alpha`, `dev`). | *(empty)* – no restriction applied | No |
| `composer_prefer_stable` | Set prefer-stable in composer.json (`yes` or `no`). | *(empty)* – no restriction applied | No |
| Name | Description | Default | Required |
|------------------------------|----------------------------------------------------------------------------------------|---------------------------------------------------------|----------|
| `build_type` | Type of the build. Possible values: `sylius`, `app`, `plugin`. | `app` | No |
| `application_root_dir` | Root directory of the application (useful in monorepos). | Resolved automatically based on `build_type`. | No |
| `application_test_dir` | Directory of the test application (used to run console commands, fixtures, etc.). | Resolved automatically based on `build_type`. | No |
| `console_path` | Relative path to Symfony's `console` binary (overrides auto-detection) | `vendor/bin/console` or `bin/console` (auto) | No |
| `cache_key` | A cache key to be used (used with `actions/cache`). | *(empty)* | No |
| `cache_restore_key` | A cache restore key to be used. | *(empty)* | No |
| `e2e` | Whether to prepare the test application for end-to-end tests. | `no` | No |
| `e2e_js` | Whether to prepare the test application for JS-based end-to-end tests. | `no` | No |
| `database` | Database engine and version (e.g., `mysql:8.4`, `postgres:16`, `mariadb:10.11`). | `mysql:8.4` | No |
| `php_version` | PHP version to be used. | *(none)* | Yes |
| `php_extensions` | List of PHP extensions to install. | `intl, gd, opcache, mysql, pdo_mysql, pgsql, pdo_pgsql` | No |
| `php_tools` | PHP tools to install (e.g. `symfony`, `composer`). | `symfony` | No |
| `php_coverage` | Coverage tool to use (e.g. `xdebug`, `pcov`, `none`). | `none` | No |
| `symfony_version` | Symfony version to be used. | *(none)* | Yes |
| `sylius_version` | Sylius version to be used. | *(none)* – no restriction applied | No |
| `sylius_integration` | Internal usage: run Sylius with a specific integration. | *(empty)* | No |
| `node_version` | Node.js version to install (used when `e2e_js: yes`). | `22.x` | No |
| `chrome_version` | Google Chrome version to install (for JS e2e tests). | `stable` | No |
| `opcache_enable` | Control OPcache (`yes`=enable with test-optimized settings, `no`=disable). | *(empty)* – use system defaults | No |
| `composer_minimum_stability` | Set minimum-stability in composer.json (e.g., `stable`, `RC`, `beta`, `alpha`, `dev`). | *(empty)* – no restriction applied | No |
| `composer_prefer_stable` | Set prefer-stable in composer.json (`yes` or `no`). | *(empty)* – no restriction applied | No |
112 changes: 75 additions & 37 deletions action.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "Build Sylius Test Application"
description: "Builds a Sylius plugin's test application with the given PHP, Sylius, Symfony, MySQL versions."
description: "Builds a Sylius plugin's test application with the given PHP, Sylius, Symfony, and database."

inputs:
# General
Expand Down Expand Up @@ -43,28 +43,25 @@ inputs:

# Database
database:
required: true
description: "Database engine to be used"
default: "mysql" # available options are "mysql", "mariadb", "postgresql" (deprecated, use "postgres"), "postgres"
database_version:
required: true
description: "Database engine version to be used"
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: true
required: false
description: "PHP extensions to be installed"
default: "intl, gd, opcache, mysql, pdo_mysql, pgsql, pdo_pgsql"
php_tools:
required: true
required: false
description: "PHP tools to be installed"
default: "symfony"
php_coverage:
required: false
description: "PHP coverage"
description: "PHP coverage driver"
default: "none"
composer_ignore_platform_reqs:
required: false
Expand Down Expand Up @@ -98,7 +95,7 @@ inputs:
node_version:
required: false
description: "Node.js version to be used"
default: "20.x"
default: "22.x"

# Chrome (only when e2e_js is set to "yes")
chrome_version:
Expand All @@ -119,58 +116,98 @@ runs:
# 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: inputs.database == 'mysql'
if: steps.db.outputs.type == 'mysql'
uses: mirromutth/mysql-action@v1.1
with:
mysql version: "${{ inputs.database_version }}"
mysql root password: "root"
mysql version: "${{ steps.db.outputs.version }}"
mysql user: "sylius"
mysql password: "sylius"
mysql database: "sylius"

- name: Setup MariaDB
if: inputs.database == 'mariadb'
if: steps.db.outputs.type == 'mariadb'
uses: getong/mariadb-action@v1.1
with:
mariadb version: "${{ inputs.database_version }}"
mysql root password: "root"

- name: Warn about postgresql deprecation
if: inputs.database == 'postgresql'
run: echo "::warning::Using 'postgresql' is deprecated, use 'postgres' instead"
shell: bash
mariadb version: "${{ steps.db.outputs.version }}"
mysql user: "sylius"
mysql password: "sylius"
mysql database: "sylius"

- name: Setup PostgreSQL
if: inputs.database == 'postgresql' || inputs.database == 'postgres'
if: steps.db.outputs.type == 'postgres'
uses: harmon758/postgresql-action@v1
with:
postgresql version: "${{ inputs.database_version }}"
postgresql password: "postgres"
postgresql version: "${{ steps.db.outputs.version }}"
postgresql user: "sylius"
postgresql password: "sylius"
postgresql db: "sylius"

- name: Optimize PostgreSQL for CI
if: steps.db.outputs.type == 'postgres'
run: |
sudo -u postgres psql -c "ALTER SYSTEM SET fsync = 'off';"
sudo -u postgres psql -c "ALTER SYSTEM SET synchronous_commit = 'off';"
sudo -u postgres psql -c "ALTER SYSTEM SET full_page_writes = 'off';"
sudo -u postgres psql -c "ALTER SYSTEM SET shared_buffers = '256MB';"
sudo -u postgres psql -c "ALTER SYSTEM SET work_mem = '64MB';"
sudo -u postgres psql -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
if: inputs.opcache_enable == ''
uses: shivammathur/setup-php@v2
with:
php-version: "${{ inputs.php_version }}"
extensions: "${{ inputs.php_extensions }}"
tools: "${{ inputs.php_tools }}"
coverage: "${{ inputs.php_coverage }}"

- name: Setup PHP with OPcache configuration
if: inputs.opcache_enable != ''
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' || 'opcache.enable=0, opcache.enable_cli=0' }}
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
Expand Down Expand Up @@ -286,8 +323,9 @@ runs:
which chromedriver || echo "Google Chromedriver successfully removed"
shell: bash

- uses: browser-actions/setup-chrome@latest
- name: Setup Chrome
if: inputs.e2e_js == 'yes'
uses: browser-actions/setup-chrome@v2
with:
chrome-version: "${{ inputs.chrome_version }}"
install-chromedriver: 'true'
Expand Down