|
8 | 8 | branches: |
9 | 9 | - main |
10 | 10 |
|
| 11 | +# Cancels all previous workflow runs for pull requests that have not completed. |
11 | 12 | concurrency: |
12 | | - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} |
| 13 | + # The concurrency group contains the workflow name and the branch name for pull requests |
| 14 | + # or the commit hash for any other events. |
| 15 | + group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }} |
13 | 16 | cancel-in-progress: true |
14 | 17 |
|
15 | 18 | jobs: |
16 | | - phpunit: |
| 19 | + build-matrix: |
| 20 | + name: Build WP/PHP Matrix |
17 | 21 | runs-on: ubuntu-latest |
18 | | - env: |
19 | | - DB_DATABASE: wordpress_test |
20 | | - DB_USER: root |
21 | | - DB_PASSWORD: root |
22 | | - strategy: |
23 | | - fail-fast: false |
24 | | - matrix: |
25 | | - php-versions: ['8.0', '8.1', '8.2', '8.3', '8.4', '8.5'] |
26 | | - wp-versions: [ '6.6', '6.7', '6.8', '6.9', '7.0', 'latest', 'trunk' ] |
27 | | - name: WP ${{ matrix.wp-versions }} / PHP ${{ matrix.php-versions }} |
28 | | - |
| 22 | + outputs: |
| 23 | + matrix: ${{ steps.set-matrix.outputs.matrix }} |
29 | 24 | steps: |
30 | | - - name: Checkout |
31 | | - uses: actions/checkout@v4 |
32 | | - |
33 | | - - name: Setup PHP |
34 | | - uses: shivammathur/setup-php@v2 |
35 | | - with: |
36 | | - php-version: ${{ matrix.php-versions }} |
37 | | - |
38 | | - - name: Install Subversion. |
39 | | - run: | |
40 | | - sudo apt-get update -y |
41 | | - sudo apt-get install -y subversion |
| 25 | + - id: set-matrix |
| 26 | + name: Generate matrix JSON |
| 27 | + shell: bash |
| 28 | + run: | |
| 29 | + declare -A wp_php |
| 30 | + wp_php["trunk"]="7.4 8.0 8.1 8.2 8.3 8.4 8.5" |
| 31 | + wp_php["7.1"]="7.4 8.0 8.1 8.2 8.3 8.4 8.5" |
| 32 | + wp_php["7.0"]="7.4 8.0 8.1 8.2 8.3 8.4 8.5" |
| 33 | + wp_php["6.9"]="7.4 8.0 8.1 8.2 8.3 8.4 8.5" |
| 34 | + wp_php["6.8"]="7.4 8.0 8.1 8.2 8.3 8.4" |
42 | 35 |
|
43 | | - - name: Check PHP Version |
44 | | - run: php -v |
| 36 | + matrix='{"include":[]}' |
| 37 | + mapfile -t wp_versions < <( |
| 38 | + { |
| 39 | + printf '%s\n' "${!wp_php[@]}" | grep -x 'trunk' || true |
| 40 | + printf '%s\n' "${!wp_php[@]}" | grep -vx 'trunk' | sort -rV |
| 41 | + } |
| 42 | + ) |
45 | 43 |
|
46 | | - - name: Composer install |
47 | | - run: composer install --optimize-autoloader --prefer-dist |
| 44 | + for wp_version in "${wp_versions[@]}"; do |
| 45 | + for php_version in ${wp_php[$wp_version]}; do |
| 46 | + matrix=$(jq \ |
| 47 | + --arg wp "$wp_version" \ |
| 48 | + --arg php "$php_version" \ |
| 49 | + '.include += [{"wp-version": $wp, "php-version": $php}]' \ |
| 50 | + <<< "$matrix") |
| 51 | + done |
| 52 | + done |
48 | 53 |
|
49 | | - - name: Install WP Tests |
50 | | - run: | |
51 | | - sudo /etc/init.d/mysql start |
52 | | - bash bin/install-wp-tests.sh wordpress_test root root 127.0.0.1 ${{ matrix.wp-versions }} |
| 54 | + echo "matrix=$(jq -c . <<< "$matrix")" >> "$GITHUB_OUTPUT" |
53 | 55 |
|
54 | | - - name: PHPUnit tests |
55 | | - run: ./vendor/bin/phpunit |
56 | | - env: |
57 | | - WP_TESTS_DIR: ${{ runner.temp }}/wordpress-tests-lib |
58 | | - WP_CORE_DIR: ${{ runner.temp }}/wordpress |
| 56 | + phpunit: |
| 57 | + needs: build-matrix |
| 58 | + name: WP ${{ matrix.wp-version }} / PHP ${{ matrix.php-version }} |
| 59 | + strategy: |
| 60 | + matrix: ${{ fromJSON(needs.build-matrix.outputs.matrix) }} |
| 61 | + fail-fast: false |
| 62 | + uses: ./.github/workflows/phpunit-reusable.yml |
| 63 | + with: |
| 64 | + wp-version: ${{ matrix.wp-version }} |
| 65 | + php-version: ${{ matrix.php-version }} |
59 | 66 |
|
60 | 67 | required-status-checks: |
61 | 68 | # This should be configured as the required status check in branch protection rules |
|
64 | 71 | # required status check will not need to be updated when matrix items change. |
65 | 72 | name: PHPUnit Required Status Checks |
66 | 73 | runs-on: 'ubuntu-24.04' |
67 | | - needs: [ 'phpunit' ] |
| 74 | + needs: [ 'build-matrix', 'phpunit' ] |
68 | 75 | if: ${{ always() }} |
69 | 76 | steps: |
70 | 77 | - name: Detect any failing status checks |
|
0 commit comments