Skip to content

Instantly share code, notes, and snippets.

Last active Oct 30, 2021
What would you like to do?
GitHub Action for running PHP_CodeSniffer on pull requests with annotations
name: PHP_CodeSniffer
on: pull_request
runs-on: ubuntu-latest
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
php-version: '7.3'
coverage: none
tools: composer, cs2pr
- name: Get Composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Setup cache
uses: pat-s/always-upload-cache@v1.1.4
path: ${{ steps.composer-cache.outputs.dir }}
# Use the hash of composer.json as the key for your cache if you do not commit composer.lock.
# key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install dependencies
run: composer install --prefer-dist --no-suggest --no-progress
- name: Detect coding standard violations
run: vendor/bin/phpcs -q --report=checkstyle | cs2pr --graceful-warnings

This comment has been minimized.


This comment has been minimized.

Copy link

@bueltge bueltge commented Apr 6, 2020

I played also a with actions. But it works easier for me if I leave the phpcs run inside the composer.json and request this inside the workflow file for the actions. So is it easier to play local and via actions on GitHub with the same scripts and tests.
The follow example should demonstrate this, run currently in this repo

composer config

        "scripts": {
        "cs": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs",
        "pu": "@php ./vendor/bin/phpunit",
        "qa": ["@cs", "@pu"]


    - name: Run QA Scripts from composer.json
      run: composer qa

This comment has been minimized.

Copy link

@dakorpar dakorpar commented Jan 28, 2021

I see cache is missing here which on big projects saves a lot of time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment