name: Flarum Backend Jobs on: workflow_call: inputs: enable_backend_testing: description: "Enable Backend Testing?" type: boolean default: true required: false enable_phpstan: description: "Enable PHPStan Static Analysis?" type: boolean default: false required: false 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: '.' # 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 php_versions: description: Versions of PHP to test with. Should be array of strings encoded as JSON array type: string required: false # Keep PHP versions synced with build-install-packages.yml default: '["8.1", "8.2", "8.3"]' php_extensions: description: PHP extensions to install. type: string required: false default: 'curl, dom, gd, json, mbstring, openssl, pdo_mysql, tokenizer, zip' db_versions: description: Versions of databases to test with. Should be array of strings encoded as JSON array type: string required: false default: '["mysql:5.7", "mysql:8.0.30", "mysql:8.1.0", "mariadb"]' php_ini_values: description: PHP ini values type: string required: false default: error_reporting=E_ALL secrets: composer_auth: description: The Composer auth tokens to use for private packages. required: false env: COMPOSER_ROOT_VERSION: dev-main # `inputs.composer_directory` defaults to `inputs.backend_directory` FLARUM_TEST_TMP_DIR_LOCAL: tests/integration/tmp COMPOSER_AUTH: ${{ secrets.composer_auth }} jobs: test: runs-on: ubuntu-latest strategy: matrix: php: ${{ fromJSON(inputs.php_versions) }} service: ${{ fromJSON(inputs.db_versions) }} prefix: [''] php_ini_values: [inputs.php_ini_values] # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstrategymatrixinclude include: # Expands the matrix by naming DBs. - service: 'mysql:5.7' db: MySQL 5.7 - service: 'mysql:8.0.30' db: MySQL 8.0 - service: mariadb db: MariaDB - service: 'mysql:8.1.0' db: MySQL 8.1 # Include Database prefix tests with only one PHP version. - php: ${{ fromJSON(inputs.php_versions)[0] }} service: 'mysql:5.7' db: MySQL 5.7 prefix: flarum_ 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] }} service: mariadb db: MariaDB prefix: flarum_ prefixStr: (prefix) - php: ${{ fromJSON(inputs.php_versions)[0] }} service: 'mysql:8.1.0' db: MySQL 8.1 prefix: flarum_ prefixStr: (prefix) # 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' services: mysql: image: ${{ matrix.service }} ports: - 13306:3306 name: 'PHP ${{ matrix.php }} / ${{ matrix.db }} ${{ matrix.prefixStr }}' 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') steps: - uses: actions/checkout@master - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} coverage: xdebug extensions: ${{ inputs.php_extensions }} tools: phpunit, composer:v2 ini-values: ${{ matrix.php_ini_values }} - name: Create MySQL Database 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 }} # 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 working-directory: ${{ inputs.backend_directory }} env: DB_PORT: 13306 DB_PASSWORD: root DB_PREFIX: ${{ matrix.prefix }} COMPOSER_PROCESS_TIMEOUT: 600 phpstan: runs-on: ubuntu-latest strategy: matrix: php: ${{ fromJSON(inputs.php_versions) }} services: mysql: image: mysql:8.0.30 ports: - 33306:3306 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 extensions: ${{ inputs.php_extensions }} tools: phpunit, composer:v2 ini-values: ${{ matrix.php_ini_values }} - name: Install Composer dependencies run: composer install working-directory: ${{ inputs.backend_directory }} - name: Create MySQL Database run: | sudo systemctl start mysql mysql -uroot -proot -e 'CREATE DATABASE flarum_test;' --port 33306 - name: Run PHPStan run: composer analyse:phpstan env: DB_PORT: 33306 DB_PASSWORD: root COMPOSER_PROCESS_TIMEOUT: 600 FLARUM_TEST_TMP_DIR_LOCAL: ./tmp