|
| 1 | +name: Run Tests |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + test-package: |
| 7 | + type: string |
| 8 | + required: true |
| 9 | + php: |
| 10 | + type: string |
| 11 | + required: true |
| 12 | + wp: |
| 13 | + type: string |
| 14 | + required: true |
| 15 | + dbtype: |
| 16 | + type: string |
| 17 | + required: true |
| 18 | + object_cache: |
| 19 | + type: string |
| 20 | + required: true |
| 21 | + use-phar: |
| 22 | + type: boolean |
| 23 | + required: true |
| 24 | + |
| 25 | +jobs: |
| 26 | + run-test: |
| 27 | + name: WP ${{ inputs.wp }} | PHP ${{ inputs.php }} | ${{ inputs.dbtype == 'sqlite' && 'SQLite' || inputs.dbtype == 'mysql' && 'MySQL' || 'MariaDB' }}${{ inputs.use-phar && ' (Phar)' || '' }}${{ inputs.object_cache == 'sqlite' && ' (Obj Cache)' || '' }} |
| 28 | + runs-on: ubuntu-22.04 |
| 29 | + continue-on-error: ${{ inputs.dbtype == 'sqlite' || inputs.object_cache == 'sqlite' }} |
| 30 | + |
| 31 | + env: |
| 32 | + MYSQL_HOST: 127.0.0.1 |
| 33 | + MYSQL_TCP_PORT: 3306 |
| 34 | + WP_CLI_TEST_DBROOTUSER: root |
| 35 | + WP_CLI_TEST_DBROOTPASS: root |
| 36 | + WP_CLI_TEST_DBNAME: wp_cli_test |
| 37 | + WP_CLI_TEST_DBUSER: wp_cli_test |
| 38 | + WP_CLI_TEST_DBPASS: password1 |
| 39 | + WP_CLI_TEST_DBHOST: 127.0.0.1:3306 |
| 40 | + WP_CLI_TEST_OBJECT_CACHE: ${{ inputs.object_cache }} |
| 41 | + |
| 42 | + steps: |
| 43 | + - name: Check out source code |
| 44 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 |
| 45 | + |
| 46 | + - name: Check existence of composer.json & behat.yml files |
| 47 | + id: check_files |
| 48 | + run: echo "files_exists=$([ -f composer.json ] && [ -f behat.yml ] && echo true || echo false)" >> "$GITHUB_OUTPUT" |
| 49 | + |
| 50 | + - name: Install Ghostscript |
| 51 | + if: steps.check_files.outputs.files_exists == 'true' |
| 52 | + run: | |
| 53 | + sudo apt-get update |
| 54 | + sudo apt-get install ghostscript -y |
| 55 | +
|
| 56 | + - name: Set up PHP environment |
| 57 | + if: steps.check_files.outputs.files_exists == 'true' |
| 58 | + uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # v2 |
| 59 | + with: |
| 60 | + php-version: '${{ inputs.php }}' |
| 61 | + extensions: gd, imagick, mysql, zip, pdo_sqlite |
| 62 | + coverage: none |
| 63 | + tools: composer |
| 64 | + |
| 65 | + - name: Install Composer dependencies & cache dependencies |
| 66 | + if: steps.check_files.outputs.files_exists == 'true' |
| 67 | + uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # v4 |
| 68 | + env: |
| 69 | + COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }} |
| 70 | + |
| 71 | + - name: Change ImageMagick policy to allow pdf->png conversion. |
| 72 | + if: steps.check_files.outputs.files_exists == 'true' |
| 73 | + run: | |
| 74 | + sudo sed -i 's/^.*policy.*coder.*none.*PDF.*//' /etc/ImageMagick-6/policy.xml |
| 75 | +
|
| 76 | + - name: Setup MySQL Server |
| 77 | + id: setup-mysql |
| 78 | + if: ${{ inputs.dbtype != 'sqlite' }} |
| 79 | + uses: shogo82148/actions-setup-mysql@840178c12b07a58353c6312be784c23b63756eea # v1 |
| 80 | + with: |
| 81 | + mysql-version: '8.0' # Standard MySQL version for these tests |
| 82 | + auto-start: true |
| 83 | + root-password: ${{ env.WP_CLI_TEST_DBROOTPASS }} |
| 84 | + user: ${{ env.WP_CLI_TEST_DBUSER}} |
| 85 | + password: ${{ env.WP_CLI_TEST_DBPASS}} |
| 86 | + my-cnf: | |
| 87 | + default_authentication_plugin=mysql_native_password |
| 88 | +
|
| 89 | + - name: Prepare test database |
| 90 | + if: steps.check_files.outputs.files_exists == 'true' && inputs.dbtype != 'sqlite' |
| 91 | + run: composer prepare-tests |
| 92 | + |
| 93 | + - name: Conditionally use Phar instead of source |
| 94 | + if: steps.check_files.outputs.files_exists == 'true' && inputs.use-phar == true |
| 95 | + run: echo "TEST_PHAR=nightly" >> $GITHUB_ENV |
| 96 | + |
| 97 | + - name: Check Behat environment |
| 98 | + if: steps.check_files.outputs.files_exists == 'true' |
| 99 | + env: |
| 100 | + WP_VERSION: '${{ inputs.wp }}' |
| 101 | + WP_CLI_TEST_DBTYPE: ${{ inputs.dbtype }} |
| 102 | + WP_CLI_TEST_DBSOCKET: '${{ steps.setup-mysql.outputs.base-dir }}/tmp/mysql.sock' |
| 103 | + run: WP_CLI_TEST_DEBUG_BEHAT_ENV=1 composer behat |
| 104 | + |
| 105 | + - name: Run Behat |
| 106 | + if: steps.check_files.outputs.files_exists == 'true' |
| 107 | + env: |
| 108 | + WP_VERSION: '${{ inputs.wp }}' |
| 109 | + WP_CLI_TEST_DBTYPE: ${{ inputs.dbtype }} |
| 110 | + TEST_PACKAGE: 'wp-cli/${{ inputs.test-package }}' |
| 111 | + WP_CLI_TEST_DBSOCKET: '${{ steps.setup-mysql.outputs.base-dir }}/tmp/mysql.sock' |
| 112 | + run: composer test |
0 commit comments