A GitHub action to run Plugin Check against your plugin.
Results are posted as file annotations.
See action.yml
- uses: wordpress/plugin-check-action@v1
with:
# Personal access token (PAT) used to comment on pull requests.
# Not currently used.
#
# [Learn more about creating and using encrypted secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets)
#
# Default: ${{ github.token }}
repo-token: ''
# Build directory of your plugin.
# Defaults to current directory / repository root.
#
# Default: './'
build-dir: ''
# List of checks to run.
# Each check should be separated with new lines.
# Examples: i18n_usage, file_type, late_escaping.
# By default, all checks are run.
#
# Default: ''
checks: ''
# List of checks to exclude from running.
# Each check should be separated with new lines.
# Examples: i18n_usage, file_type, late_escaping.
# Applies after the `checks` input.
#
# Default: ''
exclude-checks: ''
# List of error codes to ignore.
# Each error code should be separated with new lines.
# Examples: textdomain_mismatch, WordPress.Security.EscapeOutput.OutputNotEscaped.
#
# Default: ''
ignore-codes: ''
# List of categories to limit checks to.
# Each category should be separated with new lines.
# Examples: general, security
# By default, checks in all categories are run.
#
# Default: ''
categories: ''
# List of files (file paths) to exclude from checks.
# Each file should be separated with new lines.
#
# Default: ''
exclude-files: ''
# List of directories to exclude from checks.
# Each directory should be separated with new lines.
#
# Default: ''
exclude-directories: ''
# Whether to ignore warnings reported by Plugin Check.
#
# Default: false
ignore-warnings: ''
# Whether to ignore errors reported by Plugin Check.
#
# Default: false
ignore-errors: ''
# Whether to include experimental checks.
#
# Default: true
include-experimental: ''
# WordPress version to use. Supports "latest" or "trunk".
#
# Default: latest
wp-version: ''
# Severity level.
#
# Default: ''
severity: ''
# Error severity level.
#
# Default: ''
error-severity:
# Warning severity level.
#
# Default: ''
warning-severity:
# Include errors with lower severity than the threshold as other type.
#
# Default: ''
include-low-severity-errors: ''
# Include warnings with lower severity than the threshold as other type.
#
# Default: ''
include-low-severity-warnings: ''
# Slug to override the default.
#
# Default: ''
slug:
# Treat everything as an error.
#
# Default: false
strict: ''The simplest way to get up and running with your plugin.
Add a workflow (.github/workflows/build-test.yml):
name: 'build-test'
on: # rebuild any PRs and main branch changes
pull_request:
push:
branches:
- main
- 'releases/*'
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Run plugin check
uses: wordpress/plugin-check-action@v1The basic example above covers many use cases, but sometimes plugins can be a bit more complex and involve some sort of build process. Also, if you already use tools like PHPCS, you might want to skip the PHPCS-based checks from Plugin Check but focus on the ones that are more useful for you.
steps:
- name: Checkout
uses: actions/checkout@v3
# Here's where you would run your custom build process
# ...
# ...
- name: Build plugin
run: npm run build
- name: Run plugin check
uses: wordpress/plugin-check-action@v1
with:
build-dir: './my-awesome-plugin'
exclude-directories: 'prefixed_vendor_dir,another_dir_to_ignore'
categories: |
performance
accessibilityA common build step involves the wp dist-archive command.
In combination with Plugin Check it could be used like this:
steps:
- name: Checkout
uses: actions/checkout@v3
# Here's where you would run your custom build process
# ...
# ...
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: latest
coverage: none
tools: wp-cli
- name: Install latest version of dist-archive-command
run: wp package install wp-cli/dist-archive-command:@stable
- name: Build plugin
run: |
wp dist-archive . ./my-awesome-plugin.zip
mkdir tmp-build
unzip my-awesome-plugin.zip -d tmp-build
- name: Run plugin check
uses: wordpress/[email protected]
with:
build-dir: './tmp-build/my-awesome-plugin'The action runs Plugin Check in a wp-env
environment, which it configures by adding the settings it needs (a mapping for
the plugin, plus ports) to a .wp-env.json in the workspace root. The unused
tests environment is disabled unless your configuration sets env or
testsEnvironment. Any other
settings in that file are left alone, so you can use it — or a
.wp-env.override.json, which takes precedence — to adjust the environment.
For example, to keep a dependency's PHP notices out of the output:
{
"config": {
"WP_DEBUG_DISPLAY": false,
"WP_DEBUG_LOG": true
}
}At the time of writing, the following checks exist:
i18n_usagecode_obfuscationdirect_db_queriesenqueued_scripts_in_footerenqueued_scripts_sizeenqueued_styles_scopefile_typelate_escapinglocalhostno_unfiltered_uploadsperformant_wp_query_paramsplugin_header_text_domainplugin_readmeplugin_review_phpcsplugin_updatertrademarks
At the time of writing, the following categories exist:
accessibilitygeneralperformanceplugin_reposecurity