Update reusable flow #1
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' | |
jobs: | |
phpcs: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
fetch-depth: 0 | |
# ------------------------------------------------------------------------------ | |
# Prepare our cache directories | |
# ------------------------------------------------------------------------------ | |
- name: Get Composer Cache Directory | |
id: get-composer-cache-dir | |
run: | | |
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | |
- uses: actions/cache@v2 | |
id: composer-cache | |
with: | |
path: ${{ steps.get-composer-cache-dir.outputs.dir }} | |
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} | |
restore-keys: | | |
${{ runner.os }}-composer- | |
- uses: "shivammathur/setup-php@v2" | |
with: | |
php-version: 7.4 | |
- uses: "ramsey/composer-install@v2" | |
- name: "Give permissions" | |
run: | | |
sudo chown -R root:root $GITHUB_WORKSPACE | |
# ------------------------------------------------------------------------------ | |
# Get changed files | |
# ------------------------------------------------------------------------------ | |
- name: Get list of changed files | |
id: files | |
run: | | |
echo "CHANGED_FILES=$(git diff --name-only --diff-filter=AM ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | grep '\.php$' | tr '\n' ' ')" >> $GITHUB_ENV | |
# ------------------------------------------------------------------------------ | |
# PHPCS | |
# ------------------------------------------------------------------------------ | |
- uses: reviewdog/action-setup@v1 | |
with: | |
reviewdog_version: latest # Optional. [latest,nightly,v.X.Y.Z] | |
- name: Run reviewdog | |
env: | |
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GH_BOT_TOKEN }} | |
run: | | |
vendor/bin/phpcs --report=json ${CHANGED_FILES} | jq -r ' .files | to_entries[] | .key as $path | .value.messages[] as $msg | "\($path):\($msg.line):\($msg.column):`\($msg.source)`<br>\($msg.message)" ' | reviewdog -efm="%f:%l:%c:%m" -name="phpcs" -filter-mode="added" -fail-on-error=true -reporter=github-pr-review |