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. Considering that you have a .phpcs.xml.dist file in your root directory. (If not, tweak the last line of the workflow below)
  4. Create the folder .github/workflows/phpcs on the root of your GitHub repository
  5. Create the file .github/workflows/phpcs.yml
  6. Place this content inside of it:
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 \
            -v "${GITHUB_WORKSPACE}:/app" \
            --workdir "/app" \
            php:7-cli \
            bash -c "php -d memory_limit=1G /app/vendor/bin/phpcs -s --standard=/app/.phpcs.xml.dist"

Expected folder structure for this to work:

./plugin-foo
├── .github
│   └── workflows
│       └── phpcs.yml
├── vendor
│   └── bin
│       └── phpcs
├── .phpcs.xml.dist  # PHPCS configuration file
└── composer.lock    # Composer.lock file with PHPCS

Here's an example of a repository using this setup: https://github.com/Luc45/phpcs-ci-example