Last active
October 30, 2021 16:44
-
-
Save ocean90/b27b08bdec33591eae777adf0695a2c7 to your computer and use it in GitHub Desktop.
GitHub Action for running PHP_CodeSniffer on pull requests with annotations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: PHP_CodeSniffer | |
on: pull_request | |
jobs: | |
phpcs: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Setup PHP | |
uses: shivammathur/setup-php@v2 | |
with: | |
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 | |
with: | |
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 |
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 https://github.com/bueltge/marksimple/actions
composer config
"scripts": {
"cs": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs",
"pu": "@php ./vendor/bin/phpunit",
"qa": ["@cs", "@pu"]
}
workflow
- name: Run QA Scripts from composer.json
run: composer qa
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
Blog post: https://dominikschilling.de/schnipsel/github-action-workflow-php-codesniffer-check-annotations/