-
Notifications
You must be signed in to change notification settings - Fork 35
Consistent phpunit runners for local and CI #493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kasparsd
wants to merge
65
commits into
fairpm:release_1.4.1
Choose a base branch
from
kasparsd:add-phpstan-fresh
base: release_1.4.1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
65 commits
Select commit
Hold shift + click to select a range
a36e779
Add CI for linting
kasparsd 745af44
Per linter
kasparsd 3e3b634
Define known versions for min supported PHP 7.4
kasparsd bc5fc99
This already happens
kasparsd cba55da
Sync min required
kasparsd 68dfd1d
Use the existing file
kasparsd d9e2566
Keep the name
kasparsd d3859d3
Relax for Composer
kasparsd ba2d6fb
Lock at versions supported by min supported PHP
kasparsd 0a53643
Add the vendor
kasparsd 254cfae
Make it work with 7.4 by default
kasparsd ebf2198
Use wp-env for tests across the board
kasparsd e6d7481
Use the same shared dev env for running PHP stuff
kasparsd 6acddc6
Add a reusable npm run cli command to avoid repetition
kasparsd 400cef2
Add coverage reporting too
kasparsd 76d2895
Install deps
kasparsd 1a1e108
Ignore the warning for now
kasparsd 2a6e96b
Use the correct reporting script
kasparsd e54baf8
Use a reliable helper instead of constants
kasparsd 347bd8d
Always return a string
kasparsd ae20936
Bump limits
kasparsd 5ec58cf
To ensure we have all symbols for phpstan
kasparsd 85fe610
This already happens during add_key_rewrite_rule()
kasparsd 98f001e
Doesn’t accept any arguments
kasparsd f26cc35
Shoudn’t return during an action
kasparsd 0dee60b
Exclude phpunit caches
kasparsd 7e79a25
Per linter
kasparsd 127e604
Per linter
kasparsd 48e0bfa
Colocate all phpunit configs
kasparsd 43fecce
Cache between runs
kasparsd 13e1dc6
Also during phpcs and phpstan checks
kasparsd 4dd35da
Lock to known PHP 7.4 versions
kasparsd b973311
Use matrix generator for easier management
kasparsd 17d7b15
Use a name
kasparsd b01cdac
Install phpunit matching PHP and WP combo
kasparsd 8c46ac4
Redundant spaces
kasparsd 731a225
Better formatting
kasparsd 76fb78d
Not used
kasparsd aad3f6f
No need to escape it
kasparsd 2dcc95b
Skip installing optional plugins during phpunit runs
kasparsd b7531ee
Document development tooling
kasparsd 36e9787
Add schema
kasparsd e8cabea
Ignore the wp-env override
kasparsd 858a91d
account for newly added packages
kasparsd a5a646d
Match the plugin.php required PHP version
kasparsd 1ba9ec8
Match the model in other CI files
kasparsd dc65cfd
Update baseline to match the fixed issues
kasparsd 91fdd8d
Match the update project requirements
kasparsd c798a64
Rely on composer resolving the correctly binary from local deps first
kasparsd 100ce12
Bump wp-env
kasparsd f67eda5
Use a file to lock the Node version
kasparsd b21689d
Lock to PHP 8.0 as min
kasparsd cabe677
Consistent known version
kasparsd 99d9a0e
Ignore for ci purposes
kasparsd 4b8bc4d
Account for missing deps in wp-env
kasparsd f317ccd
Keep the existing structure
kasparsd ac60e9f
Reduce changeset
kasparsd a99fafb
Match the updated meta files
kasparsd 07bb649
Don’t include release instructions
kasparsd 5cbe232
Don’t release linter config
kasparsd 7ec0085
Run with WP core trunk too
kasparsd f8a2d44
Make it run on pull request to release branches too
kasparsd 8691ba0
No longer needed
kasparsd 660f68f
Try caching the wp-env home directory between runs
kasparsd 5764ec8
Bust the cache, include package.json since that has wp-env dep
kasparsd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,8 +5,6 @@ on: | |
| branches: | ||
| - main | ||
| pull_request: | ||
| branches: | ||
| - main | ||
| workflow_dispatch: | ||
|
|
||
| # Cancels all previous workflow runs for pull requests that have not completed. | ||
|
|
@@ -16,100 +14,122 @@ concurrency: | |
| group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }} | ||
| cancel-in-progress: true | ||
|
|
||
| permissions: | ||
| contents: read | ||
| # Disable permissions for all available scopes by default. | ||
| # Any needed permissions should be configured at the job level. | ||
| permissions: {} | ||
|
|
||
| jobs: | ||
| # Runs the PHPUnit tests for FAIR. | ||
| # | ||
| # Performs the following steps: | ||
| # - Checks out the repository. | ||
| # - Sets up PHP. | ||
| # - Installs Composer dependencies. | ||
| # - Installs SVN. | ||
| # - Installs the test suite. | ||
| # - Runs the PHPUnit tests. | ||
| # - Ensures version-controlled files are not modified. | ||
| generate-matrix: | ||
| name: Generate PHP and WP version testing matrix | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| outputs: | ||
| matrix: ${{ steps.generate.outputs.matrix }} | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| - name: Generate PHP and WP testing matrix | ||
| id: generate | ||
| run: echo "matrix=$(node ./bin/github-actions-matrix.js)" >> "$GITHUB_OUTPUT" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use a simple node script to generate the test matrix since it is easier to read and maintain. |
||
|
|
||
| phpunit: | ||
| name: Run tests (WP ${{ matrix.wp-version }}, PHP ${{ matrix.php-version }}) | ||
| runs-on: ubuntu-latest | ||
| continue-on-error: ${{ matrix.wp-version == 'trunk' }} # Allow tests to fail for trunk. | ||
| permissions: | ||
| contents: read | ||
| needs: generate-matrix | ||
| env: | ||
| WP_ENV_HOME: .cache/wp-env | ||
| WP_ENV_PHP_VERSION: ${{ matrix.php-version }} | ||
| WP_ENV_CORE: ${{ matrix.wp-version == 'trunk' && 'WordPress/WordPress' || format( 'https://wordpress.org/wordpress-{0}.zip', matrix.wp-version ) }} | ||
| strategy: | ||
| matrix: | ||
| php-version: [ '8.0', '8.1', '8.2', '8.3', '8.4', '8.5' ] | ||
| wp-version: [ '6.2', '6.3', '6.4', '6.5', '6.6', '6.7', '6.8', '6.9' ] | ||
| exclude: | ||
| # PHP 8.5 exclusions | ||
| - wp-version: '6.8' | ||
| php-version: '8.5' | ||
| - wp-version: '6.7' | ||
| php-version: '8.5' | ||
| - wp-version: '6.6' | ||
| php-version: '8.5' | ||
| - wp-version: '6.5' | ||
| php-version: '8.5' | ||
| - wp-version: '6.4' | ||
| php-version: '8.5' | ||
| - wp-version: '6.3' | ||
| php-version: '8.5' | ||
| - wp-version: '6.2' | ||
| php-version: '8.5' | ||
|
|
||
| # PHP 8.4 exclusions | ||
| - wp-version: '6.6' | ||
| php-version: '8.4' | ||
| - wp-version: '6.5' | ||
| php-version: '8.4' | ||
| - wp-version: '6.4' | ||
| php-version: '8.4' | ||
| - wp-version: '6.3' | ||
| php-version: '8.4' | ||
| - wp-version: '6.2' | ||
| php-version: '8.4' | ||
|
|
||
| # PHP 8.3 exclusions | ||
| - wp-version: '6.3' | ||
| php-version: '8.3' | ||
| - wp-version: '6.2' | ||
| php-version: '8.3' | ||
| fail-fast: false | ||
| matrix: ${{ fromJSON( needs.generate-matrix.outputs.matrix ) }} | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@master | ||
| uses: actions/checkout@v6 | ||
|
|
||
| - name: Setup MySQL with mysql_native_password | ||
| uses: shogo82148/actions-setup-mysql@v1 | ||
| - name: Setup Node | ||
| uses: actions/setup-node@v6 | ||
| with: | ||
| mysql-version: ${{ matrix.wp-version >= '5.0' && '8.0' || '5.6' }} | ||
| my-cnf: | | ||
| bind_address=127.0.0.1 | ||
| default-authentication-plugin=mysql_native_password | ||
| root-password: root | ||
|
|
||
| - name: Set up PHP | ||
| uses: shivammathur/setup-php@v2 | ||
| cache: 'npm' | ||
| node-version-file: '.nvmrc' | ||
|
|
||
| - name: Install dependencies | ||
| run: npm install | ||
|
|
||
| - name: Setup cache | ||
| uses: actions/cache@v5 | ||
| with: | ||
| php-version: ${{ matrix.php-version }} | ||
| coverage: none | ||
| extensions: mysql, mysqli | ||
| tools: composer, wp-cli, phpunit:${{ matrix.wp-version < '5.1' && '6' || ( matrix.wp-version < '5.9' || matrix.php-version < '8.0' ) && '7' || '9' }}, phpunit-polyfills:^1.1.0 | ||
| env: | ||
| COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| key: ${{ runner.os }}-${{ hashFiles('composer.json', 'package.json') }} | ||
| path: | | ||
| .cache | ||
| tests/phpunit/cache | ||
|
|
||
| - name: Install Composer dependencies | ||
| run: composer update --optimize-autoloader --prefer-dist | ||
| - name: Skip development plugins | ||
| run: echo '{"plugins":[]}' > .wp-env.override.json | ||
|
|
||
| - name: Install SVN | ||
| run: sudo apt-get update && sudo apt-get install -y subversion | ||
| - name: Start the development environment | ||
| run: npm run env start | ||
|
|
||
| - name: Install test suite | ||
| - name: Report Versions | ||
| run: | | ||
| echo "WP_VERSION=${{ matrix.wp-version }}" >> $GITHUB_ENV | ||
| echo "TMPDIR=${{ runner.temp }}" >> $GITHUB_ENV | ||
| echo "WP_TESTS_DIR=${{ runner.temp }}/wordpress-tests-lib" >> $GITHUB_ENV | ||
| echo "WP_CORE_DIR=${{ runner.temp }}/wordpress" >> $GITHUB_ENV | ||
| TMPDIR=${{ runner.temp }} bash bin/install-wp-tests.sh wordpress_test root root 127.0.0.1 ${{ matrix.wp-version }} | ||
| npm run env run cli -- php -v | ||
| npm run env run cli -- wp core version | ||
|
|
||
| - name: Install fresh dependencies for PHP ${{ matrix.php-version }} | ||
| run: rm composer.lock | ||
|
|
||
| - name: Install dependencies | ||
| run: npm run cli -- composer require --ignore-platform-req=ext-gmp --dev phpunit/phpunit:^${{ matrix.wp-version < '5.1' && '6' || ( matrix.wp-version < '5.9' || matrix.php-version < '8.0' ) && '7' || '9' }} | ||
|
|
||
| - name: Run PHPUnit tests | ||
| - name: Run PHPUnit tests (single site) | ||
| run: npm run test:php | ||
|
|
||
| - name: Run PHPUnit tests (multisite) | ||
| run: npm run test:php:multisite | ||
|
|
||
| phpunit-coverage: | ||
| name: PHPUnit Coverage | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| env: | ||
| WP_ENV_HOME: .cache/wp-env | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v6 | ||
|
|
||
| - name: Setup cache | ||
| uses: actions/cache@v5 | ||
| with: | ||
| key: ${{ runner.os }}-${{ hashFiles('composer.json', 'package.json') }} | ||
| path: | | ||
| .cache | ||
| tests/phpunit/cache | ||
|
|
||
| - name: Setup Node | ||
| uses: actions/setup-node@v6 | ||
| with: | ||
| cache: 'npm' | ||
| node-version-file: '.nvmrc' | ||
|
|
||
| - name: Install dependencies | ||
| run: npm install | ||
|
|
||
| - name: Start the development environment | ||
| run: npm run env -- start --xdebug=coverage | ||
|
|
||
| - name: Report Versions | ||
| run: | | ||
| echo "define('WP_TESTS_PHPUNIT_POLYFILLS_PATH', '$HOME/.composer/vendor/yoast/phpunit-polyfills');" >> ${{ runner.temp }}/wordpress-tests-lib/wp-tests-config.php | ||
| phpunit | ||
| npm run env run cli -- php -v | ||
| npm run env run cli -- php -i | grep xdebug | ||
| npm run env run cli -- wp core version | ||
|
|
||
| - name: Install Composer dependencies | ||
| run: npm run test:php:install-deps | ||
|
|
||
| - name: Generate coverage report | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add in coverage reporting. |
||
| run: npm run coverage:php:full | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 20 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| // PHP versions and their supported WP versions. | ||
| const supported = { | ||
| "8.0": [ "6.2", "6.3", "6.4", "6.5", "6.6", "6.7", "6.8", "6.9" ], | ||
| "8.1": [ "6.2", "6.3", "6.4", "6.5", "6.6", "6.7", "6.8", "6.9" ], | ||
| "8.2": [ "6.2", "6.3", "6.4", "6.5", "6.6", "6.7", "6.8", "6.9" ], | ||
| "8.3": [ "6.4", "6.5", "6.6", "6.7", "6.8", "6.9" ], | ||
| "8.4": [ "6.7", "6.8", "6.9" ], | ||
| "8.5": [ "6.9", "trunk" ], | ||
| }; | ||
|
|
||
| const include = Object.entries( supported ).flatMap( ( [ php, wps ] ) => | ||
| wps.map( ( wp ) => ( { "php-version": php, "wp-version": wp } ) ) | ||
| ); | ||
|
|
||
| process.stdout.write( JSON.stringify( { include } ) ); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Introduce
.nvmrcto lock the version of Node to a known version for this project.