2022-06-19 18:14:21 +08:00
name : Flarum Backend Jobs
on :
workflow_call :
inputs :
enable_backend_testing :
description : "Enable Backend Testing?"
type : boolean
default : true
required : false
2022-09-14 22:23:56 +08:00
enable_phpstan :
description : "Enable PHPStan Static Analysis?"
type : boolean
default : false
required : false
2022-06-19 18:14:21 +08:00
backend_directory :
description : The directory of the project where backend code is located. This should contain a `composer.json` file, and is generally the root directory of the repo.
type : string
required : false
default : '.'
2023-06-15 20:26:39 +08:00
# Only relevant in mono-repos.
monorepo_tests :
description : "The list of directories to test in a monorepo. This should be a space-separated list of directories relative to the backend directory."
type : string
required : false
2022-06-19 18:14:21 +08:00
php_versions :
description : Versions of PHP to test with. Should be array of strings encoded as JSON array
type : string
required : false
2024-01-19 16:54:26 +08:00
# Keep PHP versions synced with build-install-packages.yml
2024-08-06 23:50:09 +08:00
default : '["8.2", "8.3"]'
2022-10-01 03:53:50 +08:00
php_extensions :
description : PHP extensions to install.
type : string
required : false
default : 'curl, dom, gd, json, mbstring, openssl, pdo_mysql, tokenizer, zip'
2022-06-19 18:14:21 +08:00
db_versions :
description : Versions of databases to test with. Should be array of strings encoded as JSON array
type : string
required : false
2024-06-22 15:03:56 +08:00
default : '["mysql:5.7", "mysql:8.0.30", "mysql:8.1.0", "mariadb", "sqlite:3", "postgres:10"]'
2022-06-19 18:14:21 +08:00
php_ini_values :
description : PHP ini values
type : string
required : false
default : error_reporting=E_ALL
2024-05-17 00:30:13 +08:00
runner_type :
description : The type of runner to use for the jobs. This should be one of the types supported by the `runs-on` keyword.
type : string
required : false
default : 'ubuntu-latest'
2024-01-23 01:57:54 +08:00
secrets :
composer_auth :
description : The Composer auth tokens to use for private packages.
required : false
2022-06-19 18:14:21 +08:00
env :
COMPOSER_ROOT_VERSION : dev-main
2023-06-15 20:26:39 +08:00
# `inputs.composer_directory` defaults to `inputs.backend_directory`
2022-06-19 18:14:21 +08:00
FLARUM_TEST_TMP_DIR_LOCAL : tests/integration/tmp
2024-01-23 01:57:54 +08:00
COMPOSER_AUTH : ${{ secrets.composer_auth }}
2024-06-22 15:03:56 +08:00
DB_DATABASE : flarum_test
DB_USERNAME : root
DB_PASSWORD : root
2022-06-19 18:14:21 +08:00
jobs :
test :
2024-05-17 00:30:13 +08:00
runs-on : ${{ inputs.runner_type }}
2022-06-19 18:14:21 +08:00
strategy :
matrix :
php : ${{ fromJSON(inputs.php_versions) }}
service : ${{ fromJSON(inputs.db_versions) }}
2022-08-13 02:22:38 +08:00
prefix : [ '' ]
2023-02-15 02:09:56 +08:00
php_ini_values : [ inputs.php_ini_values]
2022-06-19 18:14:21 +08:00
2022-08-13 02:22:38 +08:00
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstrategymatrixinclude
2022-06-19 18:14:21 +08:00
include :
2022-08-13 02:22:38 +08:00
# Expands the matrix by naming DBs.
2022-06-19 18:14:21 +08:00
- service : 'mysql:5.7'
2022-08-13 02:22:38 +08:00
db : MySQL 5.7
2024-06-21 14:25:11 +08:00
driver : mysql
2022-08-13 02:22:38 +08:00
- service : 'mysql:8.0.30'
db : MySQL 8.0
2024-06-21 14:25:11 +08:00
driver : mysql
2022-06-19 18:14:21 +08:00
- service : mariadb
db : MariaDB
2024-06-21 14:25:11 +08:00
driver : mysql
2023-09-15 04:04:25 +08:00
- service : 'mysql:8.1.0'
db : MySQL 8.1
2024-06-21 14:25:11 +08:00
driver : mysql
- service : 'sqlite:3'
db : SQLite
driver : sqlite
2024-06-22 15:03:56 +08:00
- service : 'postgres:10'
db : PostgreSQL 10
driver : pgsql
2022-06-19 18:14:21 +08:00
2022-08-13 02:22:38 +08:00
# Include Database prefix tests with only one PHP version.
- php : ${{ fromJSON(inputs.php_versions)[0] }}
2022-06-19 18:14:21 +08:00
service : 'mysql:5.7'
2022-08-13 02:22:38 +08:00
db : MySQL 5.7
2024-06-21 14:25:11 +08:00
driver : mysql
2022-06-19 18:14:21 +08:00
prefix : flarum_
2022-08-13 02:22:38 +08:00
prefixStr : (prefix)
- php : ${{ fromJSON(inputs.php_versions)[0] }}
2022-06-19 18:14:21 +08:00
service : mariadb
2022-08-13 02:22:38 +08:00
db : MariaDB
2024-06-21 14:25:11 +08:00
driver : mysql
2022-06-19 18:14:21 +08:00
prefix : flarum_
2022-08-13 02:22:38 +08:00
prefixStr : (prefix)
2024-06-21 14:25:11 +08:00
- php : ${{ fromJSON(inputs.php_versions)[0] }}
service : 'sqlite:3'
db : SQLite
driver : sqlite
2023-09-15 04:04:25 +08:00
prefix : flarum_
prefixStr : (prefix)
2024-06-22 15:03:56 +08:00
- php : ${{ fromJSON(inputs.php_versions)[0] }}
service : 'postgres:10'
db : PostgreSQL 10
driver : pgsql
prefix : flarum_
prefixStr : (prefix)
2022-08-13 02:22:38 +08:00
# To reduce number of actions, we exclude some PHP versions from running with some DB versions.
exclude :
- php : ${{ fromJSON(inputs.php_versions)[1] }}
service : 'mysql:8.0.30'
2024-06-21 14:25:11 +08:00
- php : ${{ fromJSON(inputs.php_versions)[0] }}
service : mariadb
- php : ${{ fromJSON(inputs.php_versions)[1] }}
service : mariadb
- php : ${{ fromJSON(inputs.php_versions)[0] }}
service : 'mysql:8.1.0'
- php : ${{ fromJSON(inputs.php_versions)[1] }}
service : 'mysql:8.1.0'
- php : ${{ fromJSON(inputs.php_versions)[0] }}
service : 'sqlite:3'
- php : ${{ fromJSON(inputs.php_versions)[1] }}
service : 'sqlite:3'
2024-06-22 15:03:56 +08:00
- php : ${{ fromJSON(inputs.php_versions)[0] }}
service : 'postgres:10'
- php : ${{ fromJSON(inputs.php_versions)[1] }}
service : 'postgres:10'
2022-06-19 18:14:21 +08:00
services :
mysql :
2024-06-22 15:03:56 +08:00
image : ${{ matrix.driver == 'mysql' && matrix.service || '' }}
env :
MYSQL_DATABASE : ${{ env.DB_DATABASE }}
MYSQL_USER : ${{ env.DB_USERNAME }}
MYSQL_PASSWORD : ${{ env.DB_PASSWORD }}
MYSQL_ROOT_PASSWORD : ${{ env.DB_PASSWORD }}
2022-06-19 18:14:21 +08:00
ports :
- 13306 : 3306
2024-06-22 15:03:56 +08:00
postgres :
image : ${{ matrix.driver == 'pgsql' && matrix.service || '' }}
env :
POSTGRES_DB : ${{ env.DB_DATABASE }}
POSTGRES_USER : ${{ env.DB_USERNAME }}
POSTGRES_PASSWORD : ${{ env.DB_PASSWORD }}
ports :
- 15432 : 5432
options : >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
2022-06-19 18:14:21 +08:00
name : 'PHP ${{ matrix.php }} / ${{ matrix.db }} ${{ matrix.prefixStr }}'
2022-08-13 16:33:37 +08:00
if : >-
inputs.enable_backend_testing &&
((github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) || github.event_name != 'pull_request')
2022-06-19 18:14:21 +08:00
steps :
- uses : actions/checkout@master
- name : Setup PHP
uses : shivammathur/setup-php@v2
with :
php-version : ${{ matrix.php }}
coverage : xdebug
2022-10-01 03:53:50 +08:00
extensions : ${{ inputs.php_extensions }}
2022-06-19 18:14:21 +08:00
tools : phpunit, composer:v2
2023-02-15 02:09:56 +08:00
ini-values : ${{ matrix.php_ini_values }}
2022-06-19 18:14:21 +08:00
- name : Create MySQL Database
2024-06-22 15:03:56 +08:00
if : ${{ matrix.driver == 'mysql' }}
2022-06-19 18:14:21 +08:00
run : |
sudo systemctl start mysql
mysql -uroot -proot -e 'CREATE DATABASE flarum_test;' --port 13306
- name : Install Composer dependencies
run : composer install
working-directory : ${{ inputs.backend_directory }}
2023-06-15 20:26:39 +08:00
# If we have a `inputs.monorepo_tests`, we will run tests for each item of the provided array in a ::group::item
# If we don't have a `inputs.monorepo_tests`, we will run tests for the current repository
# We also have to run the `composer test:setup` script first before running each test
- name : Run tests
run : |
if [ -z "${{ inputs.monorepo_tests }}" ]; then
composer test:setup
composer test
else
for test in ${{ inputs.monorepo_tests }}; do
echo "::group::Running tests for $test"
composer test:setup --working-dir=$test
composer test --working-dir=$test
echo "::endgroup::"
done
fi
2022-06-19 18:14:21 +08:00
working-directory : ${{ inputs.backend_directory }}
env :
2024-06-22 15:03:56 +08:00
DB_PORT : ${{ matrix.driver == 'mysql' && 13306 || 15432 }}
2022-06-19 18:14:21 +08:00
DB_PREFIX : ${{ matrix.prefix }}
2024-06-21 14:25:11 +08:00
DB_DRIVER : ${{ matrix.driver }}
2022-06-19 18:14:21 +08:00
COMPOSER_PROCESS_TIMEOUT : 600
2022-09-14 22:23:56 +08:00
phpstan :
2024-05-17 00:30:13 +08:00
runs-on : ${{ inputs.runner_type }}
2022-09-14 22:23:56 +08:00
strategy :
matrix :
php : ${{ fromJSON(inputs.php_versions) }}
2023-06-16 00:49:39 +08:00
services :
mysql :
image : mysql:8.0.30
ports :
- 33306 : 3306
2022-09-14 22:23:56 +08:00
name : 'PHPStan PHP ${{ matrix.php }}'
if : >-
inputs.enable_phpstan &&
((github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) || github.event_name != 'pull_request')
steps :
- uses : actions/checkout@master
- name : Setup PHP
uses : shivammathur/setup-php@v2
with :
php-version : ${{ matrix.php }}
coverage : xdebug
2022-10-01 03:53:50 +08:00
extensions : ${{ inputs.php_extensions }}
2022-09-14 22:23:56 +08:00
tools : phpunit, composer:v2
2023-02-15 02:09:56 +08:00
ini-values : ${{ matrix.php_ini_values }}
2022-09-14 22:23:56 +08:00
- name : Install Composer dependencies
run : composer install
working-directory : ${{ inputs.backend_directory }}
2023-06-16 00:49:39 +08:00
- name : Create MySQL Database
run : |
sudo systemctl start mysql
mysql -uroot -proot -e 'CREATE DATABASE flarum_test;' --port 33306
2022-09-14 22:23:56 +08:00
- name : Run PHPStan
run : composer analyse:phpstan
2023-06-16 00:49:39 +08:00
env :
DB_PORT : 33306
DB_PASSWORD : root
COMPOSER_PROCESS_TIMEOUT : 600
FLARUM_TEST_TMP_DIR_LOCAL : ./tmp