Skip to content

Running in GitHub Actions

Lucas Bustamante edited this page Jun 24, 2022 · 23 revisions

You can run PHPCS automatically whenever a new commit is pushed to your repository using GitHub actions, just follow these simple steps:

  1. Considering that your plugin is hosted in GitHub
  2. Considering you are already running PHPCS locally using ./vendor/bin/phpcs
  3. Create the folder .github/workflows/phpcs on the root of your GitHub repository
  4. Create the file .github/workflows/phpcs.yml
  5. Place this content inside of it:

Considering this EXAMPLE folder structure:

./plugin-foo
├── .github
│   └── workflows
│       └── phpcs.yml
├── .phpcs.xml.dist    # PHPCS configuration file
├── plugin-foo.php     # Plugin entry-point
└── src                # PSR-4 autoload "src" folder
    └── FooBar.php

name: PHPCS checks
on:
  push
jobs:
  phpcs:
    name: PHPCS
    runs-on: ubuntu-20.04
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
      - name: Composer install
        run: composer install
      - name: Run PHPCS checks
        run: docker run --rm \
             --user 0:0 \
             -v "${PWD}:/app" \
             --workdir "${GITHUB_WORKSPACE}" \
             php:7-cli \
             bash -c "php -d memory_limit=1G ./vendor/bin/phpcs /app/plugin-foo.php /app/src -s --standard=/app/.phpcs.xml.dist --basepath=/app/src"

If your folder structure is different, you will need to tweak the last line of the workflow to point to the expected paths.