mirror of
https://github.com/WordPress/WordPress-Coding-Standards.git
synced 2025-08-30 03:11:24 +08:00
Page:
Running in GitHub Actions
Pages
Customizable sniff properties
Escaping a WP_Error object
Fixing errors for input data
Home
How to use WordPressCS with Eclipse and XAMPP
Ignoring Parts of a File
Project Timeline
Running in GitHub Actions
Running in Travis
Sanitizing array input data
Setting up WordPressCS to work in Atom
Setting up WordPressCS to work in Sublime Text
Upgrade Guide to WordPressCS 2.0.0 for Developers of external standards
Upgrade Guide to WordPressCS 3.0.0 for Developers of external standards
Upgrade Guide to WordPressCS 3.0.0 for ruleset maintainers
No results
23
Running in GitHub Actions
LinaQiu edited this page 2024-10-09 17:02:41 -04:00
You can run PHPCS automatically whenever a new commit is pushed to your repository using GitHub actions, just follow these steps:
- Considering that your plugin is hosted on GitHub.
- ... and you are installing WordPressCS using Composer and can run it locally using
vendor/bin/phpcs
. - ... and you have a
[.]phpcs.xml[.dist]
file in your project root directory. (If not, add--standard=path/to/yourrulesetfile.xml
to the PHPCS command below). - Create the folder
.github/workflows
in the root of your GitHub repository (if it does not exist yet). - Create the file
.github/workflows/phpcs.yml
and add the below yaml script to it.
name: PHPCS check
on:
push:
pull_request:
# Allow manually triggering the workflow.
workflow_dispatch:
# Cancel all previous workflow runs for the same branch that have not yet completed.
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
phpcs:
name: PHPCS check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup PHP
uses: "shivammathur/setup-php@v2"
with:
php-version: 'latest'
ini-values: 'memory_limit=1G'
coverage: none
tools: cs2pr
- name: Install Composer dependencies
uses: "ramsey/composer-install@v3"
with:
# Bust the cache at least once a month - output format: YYYY-MM.
custom-cache-suffix: $(date -u "+%Y-%m")
- name: Run PHPCS checks
id: phpcs
run: vendor/bin/phpcs --report-full --report-checkstyle=./phpcs-report.xml
- name: Show PHPCS results in PR
if: ${{ always() && steps.phpcs.outcome == 'failure' }}
run: cs2pr ./phpcs-report.xml
Expected folder structure for this job to work out-of-the-box:
./project-root
├── .github
│ └── workflows
│ └── phpcs.yml
├── vendor
│ └── bin
│ └── phpcs
└── [.]phpcs.xml[.dist] # PHPCS configuration file
If your folder structure is different, you might need to tweak the workflow a little bit.
Here's an example of a repository using this setup: https://github.com/Luc45/phpcs-ci-example
IDE configuration
Fixing violations
Ignoring violations
Running in CI
For ruleset maintainers
For developers
Project History