|
| 1 | +name: Flarum Backend Jobs |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + enable_backend_testing: |
| 7 | + description: "Enable Backend Testing?" |
| 8 | + type: boolean |
| 9 | + default: true |
| 10 | + required: false |
| 11 | + |
| 12 | + enable_phpstan: |
| 13 | + description: "Enable PHPStan Static Analysis?" |
| 14 | + type: boolean |
| 15 | + default: false |
| 16 | + required: false |
| 17 | + |
| 18 | + backend_directory: |
| 19 | + 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. |
| 20 | + type: string |
| 21 | + required: false |
| 22 | + default: '.' |
| 23 | + |
| 24 | + php_versions: |
| 25 | + description: Versions of PHP to test with. Should be array of strings encoded as JSON array |
| 26 | + type: string |
| 27 | + required: false |
| 28 | + default: '["7.3", "7.4", "8.0", "8.1"]' |
| 29 | + |
| 30 | + php_extensions: |
| 31 | + description: PHP extensions to install. |
| 32 | + type: string |
| 33 | + required: false |
| 34 | + default: 'curl, dom, gd, json, mbstring, openssl, pdo_mysql, tokenizer, zip' |
| 35 | + |
| 36 | + db_versions: |
| 37 | + description: Versions of databases to test with. Should be array of strings encoded as JSON array |
| 38 | + type: string |
| 39 | + required: false |
| 40 | + default: '["mysql:5.7", "mysql:8.0.30", "mariadb"]' |
| 41 | + |
| 42 | + php_ini_values: |
| 43 | + description: PHP ini values |
| 44 | + type: string |
| 45 | + required: false |
| 46 | + default: error_reporting=E_ALL |
| 47 | + |
| 48 | + operating_systems: |
| 49 | + description: Operating systems to test on. Should be array of strings encoded as JSON array |
| 50 | + type: string |
| 51 | + required: false |
| 52 | + default: '["ubuntu-latest"]' |
| 53 | + |
| 54 | +env: |
| 55 | + COMPOSER_ROOT_VERSION: dev-main |
| 56 | + FLARUM_TEST_TMP_DIR_LOCAL: tests/integration/tmp |
| 57 | + |
| 58 | +jobs: |
| 59 | + test: |
| 60 | + strategy: |
| 61 | + matrix: |
| 62 | + php: ${{ fromJSON(inputs.php_versions) }} |
| 63 | + service: ${{ fromJSON(inputs.db_versions) }} |
| 64 | + os: ${{ fromJSON(inputs.operating_systems) }} |
| 65 | + prefix: [''] |
| 66 | + |
| 67 | + # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstrategymatrixinclude |
| 68 | + include: |
| 69 | + # Expands the matrix by naming DBs. |
| 70 | + - service: 'mysql:5.7' |
| 71 | + db: MySQL 5.7 |
| 72 | + - service: 'mysql:8.0.30' |
| 73 | + db: MySQL 8.0 |
| 74 | + - service: mariadb |
| 75 | + db: MariaDB |
| 76 | + |
| 77 | + # Include Database prefix tests with only one PHP version. |
| 78 | + - php: ${{ fromJSON(inputs.php_versions)[0] }} |
| 79 | + service: 'mysql:5.7' |
| 80 | + db: MySQL 5.7 |
| 81 | + os: ${{ fromJSON(inputs.operating_systems)[0] }} |
| 82 | + prefix: flarum_ |
| 83 | + prefixStr: (prefix) |
| 84 | + - php: ${{ fromJSON(inputs.php_versions)[0] }} |
| 85 | + service: 'mysql:8.0.30' |
| 86 | + db: MySQL 8.0 |
| 87 | + os: ${{ fromJSON(inputs.operating_systems)[0] }} |
| 88 | + prefix: flarum_ |
| 89 | + prefixStr: (prefix) |
| 90 | + - php: ${{ fromJSON(inputs.php_versions)[0] }} |
| 91 | + service: mariadb |
| 92 | + db: MariaDB |
| 93 | + os: ${{ fromJSON(inputs.operating_systems)[0] }} |
| 94 | + prefix: flarum_ |
| 95 | + prefixStr: (prefix) |
| 96 | + |
| 97 | + # To reduce number of actions, we exclude some PHP versions from running with some DB versions. |
| 98 | + exclude: |
| 99 | + - php: ${{ fromJSON(inputs.php_versions)[1] }} |
| 100 | + service: 'mysql:8.0.30' |
| 101 | + - php: ${{ fromJSON(inputs.php_versions)[2] }} |
| 102 | + service: 'mysql:8.0.30' |
| 103 | + |
| 104 | + services: |
| 105 | + mysql: |
| 106 | + image: ${{ matrix.service }} |
| 107 | + ports: |
| 108 | + - 13306:3306 |
| 109 | + |
| 110 | + name: 'PHP ${{ matrix.php }} / ${{ matrix.db }} ${{ matrix.prefixStr }} / ${{ matrix.os }}' |
| 111 | + runs-on: ${{ matrix.os }} |
| 112 | + |
| 113 | + if: >- |
| 114 | + inputs.enable_backend_testing && |
| 115 | + ((github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) || github.event_name != 'pull_request') |
| 116 | +
|
| 117 | + steps: |
| 118 | + - uses: actions/checkout@master |
| 119 | + |
| 120 | + - name: Setup PHP |
| 121 | + uses: shivammathur/setup-php@v2 |
| 122 | + with: |
| 123 | + php-version: ${{ matrix.php }} |
| 124 | + coverage: xdebug |
| 125 | + extensions: ${{ inputs.php_extensions }} |
| 126 | + tools: phpunit, composer:v2 |
| 127 | + ini-values: ${{ inputs.php_ini_values }} |
| 128 | + |
| 129 | + # The authentication alter is necessary because newer mysql versions use the `caching_sha2_password` driver, |
| 130 | + # which isn't supported prior to PHP7.4 |
| 131 | + # When we drop support for PHP7.3, we should remove this from the setup. |
| 132 | + - name: Create MySQL Database |
| 133 | + run: | |
| 134 | + sudo systemctl start mysql |
| 135 | + mysql -uroot -proot -e 'CREATE DATABASE flarum_test;' --port 13306 |
| 136 | + mysql -uroot -proot -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';" --port 13306 |
| 137 | +
|
| 138 | + - name: Install Composer dependencies |
| 139 | + run: composer install |
| 140 | + working-directory: ${{ inputs.backend_directory }} |
| 141 | + |
| 142 | + - name: Setup Composer tests |
| 143 | + run: composer test:setup |
| 144 | + working-directory: ${{ inputs.backend_directory }} |
| 145 | + env: |
| 146 | + DB_PORT: 13306 |
| 147 | + DB_PASSWORD: root |
| 148 | + DB_PREFIX: ${{ matrix.prefix }} |
| 149 | + |
| 150 | + - name: Run Composer tests |
| 151 | + run: composer test |
| 152 | + working-directory: ${{ inputs.backend_directory }} |
| 153 | + env: |
| 154 | + COMPOSER_PROCESS_TIMEOUT: 600 |
| 155 | + |
| 156 | + phpstan: |
| 157 | + runs-on: ubuntu-latest |
| 158 | + |
| 159 | + strategy: |
| 160 | + matrix: |
| 161 | + php: ${{ fromJSON(inputs.php_versions) }} |
| 162 | + |
| 163 | + name: 'PHPStan PHP ${{ matrix.php }}' |
| 164 | + |
| 165 | + if: >- |
| 166 | + inputs.enable_phpstan && |
| 167 | + ((github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) || github.event_name != 'pull_request') |
| 168 | +
|
| 169 | + steps: |
| 170 | + - uses: actions/checkout@master |
| 171 | + |
| 172 | + - name: Setup PHP |
| 173 | + uses: shivammathur/setup-php@v2 |
| 174 | + with: |
| 175 | + php-version: ${{ matrix.php }} |
| 176 | + coverage: xdebug |
| 177 | + extensions: ${{ inputs.php_extensions }} |
| 178 | + tools: phpunit, composer:v2 |
| 179 | + ini-values: ${{ inputs.php_ini_values }} |
| 180 | + |
| 181 | + - name: Install Composer dependencies |
| 182 | + run: composer install |
| 183 | + working-directory: ${{ inputs.backend_directory }} |
| 184 | + |
| 185 | + - name: Run PHPStan |
| 186 | + run: composer analyse:phpstan |
0 commit comments