Skip to content

Commit

Permalink
Workflows: Run PHP unit tests also against previous WP version (#46983)
Browse files Browse the repository at this point in the history
Gutenberg is supposed to work on the current WordPress version, and on the previous one.

While we already have solid test coverage for the current WP version, we didn't have any coverage for the previous one. This sometimes resulted in failures when people attempted to run GB on the previous WP version, as seen e.g. #46811.

PHP unit tests should catch the bulk of issues like that (while not adding as much overhead as JS unit tests, or e2e tests).

Co-authored-by: Peter Wilson <[email protected]>
  • Loading branch information
ockham and peterwilsoncc authored Apr 5, 2023
1 parent 2a20339 commit e1eb90b
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,34 @@ jobs:
- name: Running the date tests
run: npm run test:unit:date -- --ci --maxWorkers=2 --cacheDirectory="$HOME/.jest-cache"

compute-previous-wordpress-version:
name: Compute previous WordPress version
runs-on: ubuntu-latest
outputs:
previous-wordpress-version: ${{ steps.get-previous-wordpress-version.outputs.previous-wordpress-version }}

steps:
- name: Get previous WordPress version
id: get-previous-wordpress-version
run: |
curl \
-H "Accept: application/json" \
-o versions.json \
"http://api.wordpress.org/core/stable-check/1.0/"
LATEST_WP_VERSION=$(jq --raw-output 'with_entries(select(.value=="latest"))|keys[]' versions.json)
IFS='.' read LATEST_WP_MAJOR LATEST_WP_MINOR LATEST_WP_PATCH <<< "${LATEST_WP_VERSION}"
if [[ ${LATEST_WP_MINOR} == "0" ]]; then
PREVIOUS_WP_SERIES="$((LATEST_WP_MAJOR - 1)).9"
else
PREVIOUS_WP_SERIES="${LATEST_WP_MAJOR}.$((LATEST_WP_MINOR - 1))"
fi
PREVIOUS_WP_VERSION=$(jq --raw-output --arg series "${PREVIOUS_WP_SERIES}" 'with_entries(select(.key|startswith($series)))|keys[-1]' versions.json)
echo "previous-wordpress-version=${PREVIOUS_WP_VERSION}" >> $GITHUB_OUTPUT
rm versions.json
test-php:
name: PHP ${{ matrix.php }}${{ matrix.multisite && ' multisite' || '' }} on ubuntu-latest
name: PHP ${{ matrix.php }}${{ matrix.multisite && ' multisite' || '' }}${{ matrix.wordpress != '' && format( ' (WP {0}) ', matrix.wordpress ) || '' }} on ubuntu-latest
needs: compute-previous-wordpress-version
runs-on: ubuntu-latest
timeout-minutes: 20
if: ${{ github.repository == 'WordPress/gutenberg' || github.event_name == 'pull_request' }}
Expand All @@ -69,9 +95,19 @@ jobs:
- '8.1'
- '8.2'
multisite: [false, true]
wordpress: [''] # Latest WordPress version.
include:
# Test with the previous WP version.
- php: '5.6'
wordpress: ${{ needs.compute-previous-wordpress-version.outputs.previous-wordpress-version }}
- php: '7.4'
wordpress: ${{ needs.compute-previous-wordpress-version.outputs.previous-wordpress-version }}
- php: '8.2'
wordpress: ${{ needs.compute-previous-wordpress-version.outputs.previous-wordpress-version }}

env:
WP_ENV_PHP_VERSION: ${{ matrix.php }}
WP_ENV_CORE: ${{ matrix.wordpress == '' && 'WordPress/WordPress' || format( 'https://wordpress.org/wordpress-{0}.zip', matrix.wordpress ) }}

steps:
- uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
Expand Down

1 comment on commit e1eb90b

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in e1eb90b.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4620213827
📝 Reported issues:

Please sign in to comment.