|
| 1 | +name: Testing |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - main |
| 8 | + - master |
| 9 | + |
| 10 | +# Cancels all previous workflow runs for the same branch that have not yet completed. |
| 11 | +concurrency: |
| 12 | + # The concurrency group contains the workflow name and the branch name. |
| 13 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 14 | + cancel-in-progress: true |
| 15 | + |
| 16 | +jobs: |
| 17 | + |
| 18 | + unit: #----------------------------------------------------------------------- |
| 19 | + name: Unit test / PHP ${{ matrix.php }} |
| 20 | + strategy: |
| 21 | + fail-fast: false |
| 22 | + matrix: |
| 23 | + php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1'] |
| 24 | + runs-on: ubuntu-20.04 |
| 25 | + |
| 26 | + steps: |
| 27 | + - name: Check out source code |
| 28 | + uses: actions/checkout@v2 |
| 29 | + |
| 30 | + - name: Check existence of composer.json file |
| 31 | + id: check_files |
| 32 | + uses: andstor/file-existence-action@v1 |
| 33 | + with: |
| 34 | + files: "composer.json, phpunit.xml.dist" |
| 35 | + |
| 36 | + - name: Set up PHP environment |
| 37 | + if: steps.check_files.outputs.files_exists == 'true' |
| 38 | + uses: shivammathur/setup-php@v2 |
| 39 | + with: |
| 40 | + php-version: '${{ matrix.php }}' |
| 41 | + coverage: none |
| 42 | + tools: composer,cs2pr |
| 43 | + env: |
| 44 | + COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 45 | + |
| 46 | + - name: Install Composer dependencies & cache dependencies |
| 47 | + if: steps.check_files.outputs.files_exists == 'true' |
| 48 | + uses: "ramsey/composer-install@v2" |
| 49 | + env: |
| 50 | + COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }} |
| 51 | + |
| 52 | + - name: Setup problem matcher to provide annotations for PHPUnit |
| 53 | + if: steps.check_files.outputs.files_exists == 'true' |
| 54 | + run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" |
| 55 | + |
| 56 | + - name: Run PHPUnit |
| 57 | + if: steps.check_files.outputs.files_exists == 'true' |
| 58 | + run: composer phpunit |
| 59 | + |
| 60 | + functional: #---------------------------------------------------------------------- |
| 61 | + name: Functional - WP ${{ matrix.wp }} on PHP ${{ matrix.php }} with MySQL ${{ matrix.mysql }} |
| 62 | + strategy: |
| 63 | + fail-fast: false |
| 64 | + matrix: |
| 65 | + php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1'] |
| 66 | + wp: ['latest'] |
| 67 | + mysql: ['8.0'] |
| 68 | + include: |
| 69 | + - php: '5.6' |
| 70 | + wp: 'trunk' |
| 71 | + mysql: '8.0' |
| 72 | + - php: '5.6' |
| 73 | + wp: 'trunk' |
| 74 | + mysql: '5.7' |
| 75 | + - php: '5.6' |
| 76 | + wp: 'trunk' |
| 77 | + mysql: '5.6' |
| 78 | + - php: '7.4' |
| 79 | + wp: 'trunk' |
| 80 | + mysql: '8.0' |
| 81 | + - php: '8.0' |
| 82 | + wp: 'trunk' |
| 83 | + mysql: '8.0' |
| 84 | + - php: '8.0' |
| 85 | + wp: 'trunk' |
| 86 | + mysql: '5.7' |
| 87 | + - php: '8.0' |
| 88 | + wp: 'trunk' |
| 89 | + mysql: '5.6' |
| 90 | + - php: '8.1' |
| 91 | + wp: 'trunk' |
| 92 | + mysql: '8.0' |
| 93 | + - php: '5.6' |
| 94 | + wp: '3.7' |
| 95 | + mysql: '5.6' |
| 96 | + runs-on: ubuntu-20.04 |
| 97 | + |
| 98 | + services: |
| 99 | + mysql: |
| 100 | + image: mysql:${{ matrix.mysql }} |
| 101 | + ports: |
| 102 | + - 3306 |
| 103 | + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=wp_cli_test --entrypoint sh mysql:${{ matrix.mysql }} -c "exec docker-entrypoint.sh mysqld --default-authentication-plugin=mysql_native_password" |
| 104 | + |
| 105 | + steps: |
| 106 | + - name: Check out source code |
| 107 | + uses: actions/checkout@v2 |
| 108 | + |
| 109 | + - name: Check existence of composer.json & behat.yml files |
| 110 | + id: check_files |
| 111 | + uses: andstor/file-existence-action@v1 |
| 112 | + with: |
| 113 | + files: "composer.json, behat.yml" |
| 114 | + |
| 115 | + - name: Install Ghostscript |
| 116 | + if: steps.check_files.outputs.files_exists == 'true' |
| 117 | + run: | |
| 118 | + sudo apt-get update |
| 119 | + sudo apt-get install ghostscript -y |
| 120 | +
|
| 121 | + - name: Set up PHP envirnoment |
| 122 | + if: steps.check_files.outputs.files_exists == 'true' |
| 123 | + uses: shivammathur/setup-php@v2 |
| 124 | + with: |
| 125 | + php-version: '${{ matrix.php }}' |
| 126 | + extensions: gd, imagick, mysql, zip |
| 127 | + coverage: none |
| 128 | + tools: composer |
| 129 | + env: |
| 130 | + COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 131 | + |
| 132 | + - name: Change ImageMagick policy to allow pdf->png conversion. |
| 133 | + if: steps.check_files.outputs.files_exists == 'true' |
| 134 | + run: | |
| 135 | + sudo sed -i 's/^.*policy.*coder.*none.*PDF.*//' /etc/ImageMagick-6/policy.xml |
| 136 | +
|
| 137 | + - name: Install Composer dependencies & cache dependencies |
| 138 | + if: steps.check_files.outputs.files_exists == 'true' |
| 139 | + uses: "ramsey/composer-install@v2" |
| 140 | + env: |
| 141 | + COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }} |
| 142 | + |
| 143 | + - name: Start MySQL server |
| 144 | + if: steps.check_files.outputs.files_exists == 'true' |
| 145 | + run: sudo systemctl start mysql |
| 146 | + |
| 147 | + - name: Configure DB environment |
| 148 | + if: steps.check_files.outputs.files_exists == 'true' |
| 149 | + run: | |
| 150 | + echo "MYSQL_HOST=127.0.0.1" >> $GITHUB_ENV |
| 151 | + echo "MYSQL_TCP_PORT=${{ job.services.mysql.ports['3306'] }}" >> $GITHUB_ENV |
| 152 | + echo "WP_CLI_TEST_DBROOTUSER=root" >> $GITHUB_ENV |
| 153 | + echo "WP_CLI_TEST_DBROOTPASS=root" >> $GITHUB_ENV |
| 154 | + echo "WP_CLI_TEST_DBNAME=wp_cli_test" >> $GITHUB_ENV |
| 155 | + echo "WP_CLI_TEST_DBUSER=wp_cli_test" >> $GITHUB_ENV |
| 156 | + echo "WP_CLI_TEST_DBPASS=password1" >> $GITHUB_ENV |
| 157 | + echo "WP_CLI_TEST_DBHOST=127.0.0.1:${{ job.services.mysql.ports['3306'] }}" >> $GITHUB_ENV |
| 158 | +
|
| 159 | + - name: Prepare test database |
| 160 | + if: steps.check_files.outputs.files_exists == 'true' |
| 161 | + run: composer prepare-tests |
| 162 | + |
| 163 | + - name: Check Behat environment |
| 164 | + if: steps.check_files.outputs.files_exists == 'true' |
| 165 | + run: WP_CLI_TEST_DEBUG_BEHAT_ENV=1 composer behat |
| 166 | + |
| 167 | + - name: Run Behat |
| 168 | + if: steps.check_files.outputs.files_exists == 'true' |
| 169 | + env: |
| 170 | + WP_VERSION: '${{ matrix.wp }}' |
| 171 | + run: composer behat || composer behat-rerun |
0 commit comments