This action will help you to run phpcs (PHP_CodeSniffer) with GitHub Actions platform. It also supports annotations out of the box.
Add the following code to .github/workflows/phpcs.yml
file.
name: PHPCS check
on: pull_request
jobs:
phpcs:
name: PHPCS
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
tools: composer:v2
- name: Install Dependencies
run: composer install
- name: PHPCS check
uses: navarr/phpcs-action@v3
If you want to check only files changed in the PR (NOTE: This requires checkout with depth 0)
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
...
- name: PHPCS check
uses: navarr/phpcs-action@v3
with:
only_changed_files: true
Or, if you want to limit it even further, you can report on only changed lines:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
...
- name: PHPCS check
uses: navarr/phpcs-action@v3
with:
only_changed_lines: true
To enable phpcs warnings:
...
- name: PHPCS check
uses: navarr/phpcs-action@v3
with:
enable_warnings: true
You probably would like to have configuration file for PHP_CodeSniffer in order to make it work as you like.
If you are using custom standards, you have two options on how to customize this action.
- Just use special library which will find and activate all the standards you have in your
composer.json
.
It will also change phpcs installed_paths
setting, but will prefer local phpcs install. That means we should use local phpcs binary in the action. To do so run action with certain parameter.
...
- name: Install dependencies
run: composer install --dev --prefer-dist --no-progress --no-suggest
- name: PHPCS check
uses: navarr/phpcs-action@v3
with:
phpcs_bin_path: './vendor/bin/phpcs'
- Change the
installed_paths
directly by using another option.
...
- name: PHPCS check
uses: navarr/phpcs-action@v3
with:
installed_paths: '${{ github.workspace }}/vendor/phpcompatibility/php-compatibility'