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 : '.'
php_versions :
description : Versions of PHP to test with. Should be array of strings encoded as JSON array
type : string
required : false
2023-02-15 02:09:56 +08:00
default : '["7.3", "7.4", "8.0", "8.1", "8.2"]'
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
2022-08-13 02:22:38 +08:00
default : '["mysql:5.7", "mysql:8.0.30", "mariadb"]'
2022-06-19 18:14:21 +08:00
php_ini_values :
description : PHP ini values
type : string
required : false
default : error_reporting=E_ALL
env :
COMPOSER_ROOT_VERSION : dev-main
FLARUM_TEST_TMP_DIR_LOCAL : tests/integration/tmp
jobs :
test :
runs-on : ubuntu-latest
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
- service : 'mysql:8.0.30'
db : MySQL 8.0
2022-06-19 18:14:21 +08:00
- service : mariadb
db : MariaDB
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
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] }}
service : 'mysql:8.0.30'
db : MySQL 8.0
prefix : flarum_
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
2022-06-19 18:14:21 +08:00
prefix : flarum_
2022-08-13 02:22:38 +08:00
prefixStr : (prefix)
2023-02-15 02:09:56 +08:00
# @TODO: remove in 2.0
# Include testing PHP 8.2 with deprecation warnings disabled.
- php : 8.2
php_ini_values : error_reporting=E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED
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'
- php : ${{ fromJSON(inputs.php_versions)[2] }}
service : 'mysql:8.0.30'
2023-02-15 02:09:56 +08:00
- php : ${{ fromJSON(inputs.php_versions)[3] }}
service : 'mysql:8.0.30'
# @TODO: remove in 2.0
# Exclude testing PHP 8.2 with deprecation warnings enabled.
- php : 8.2
php_ini_values : error_reporting=E_ALL
2022-06-19 18:14:21 +08:00
services :
mysql :
image : ${{ matrix.service }}
ports :
- 13306 : 3306
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
# The authentication alter is necessary because newer mysql versions use the `caching_sha2_password` driver,
# which isn't supported prior to PHP7.4
# When we drop support for PHP7.3, we should remove this from the setup.
- name : Create MySQL Database
run : |
sudo systemctl start mysql
mysql -uroot -proot -e 'CREATE DATABASE flarum_test;' --port 13306
mysql -uroot -proot -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';" --port 13306
- name : Install Composer dependencies
run : composer install
working-directory : ${{ inputs.backend_directory }}
- name : Setup Composer tests
run : composer test:setup
working-directory : ${{ inputs.backend_directory }}
env :
DB_PORT : 13306
DB_PASSWORD : root
DB_PREFIX : ${{ matrix.prefix }}
- name : Run Composer tests
run : composer test
working-directory : ${{ inputs.backend_directory }}
env :
COMPOSER_PROCESS_TIMEOUT : 600
2022-09-14 22:23:56 +08:00
phpstan :
runs-on : ubuntu-latest
strategy :
matrix :
php : ${{ fromJSON(inputs.php_versions) }}
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 }}
- name : Run PHPStan
run : composer analyse:phpstan