Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions .github/workflows/phpcs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,35 @@ jobs:
ref: ${{ inputs.ref }}
fetch-depth: 0

# ------------------------------------------------------------------------------
# Get changed files — runs right after checkout so we can skip remaining
# steps entirely when no PHP files changed
# ------------------------------------------------------------------------------
- name: Get list of changed files
id: files
run: |
CHANGED_FILES=$(git diff --name-only --diff-filter=AM ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} -- . ':!tests' | grep '\.php$' || true)

{
echo 'CHANGED_FILES<<EOF'
echo "$CHANGED_FILES"
echo EOF
} >> $GITHUB_ENV

if [ -n "$CHANGED_FILES" ]; then
echo "has_php_files=true" >> $GITHUB_OUTPUT
else
echo "No PHP files changed, skipping phpcs"
echo "has_php_files=false" >> $GITHUB_OUTPUT
fi

- uses: shivammathur/setup-php@v2
if: steps.files.outputs.has_php_files == 'true'
with:
php-version: ${{ inputs.php_version }}

- uses: ramsey/composer-install@v3
if: steps.files.outputs.has_php_files == 'true'
with:
composer-options: "--ignore-platform-reqs"

Expand All @@ -42,26 +66,20 @@ jobs:
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 }} -- . ':!tests' | grep '\.php$' | tr '\n' ' ')" >> $GITHUB_ENV

# ------------------------------------------------------------------------------
# PHPCS
# ------------------------------------------------------------------------------
- uses: reviewdog/action-setup@v1
if: steps.files.outputs.has_php_files == 'true'
with:
reviewdog_version: latest # Optional. [latest,nightly,v.X.Y.Z]
- name: Run reviewdog
if: steps.files.outputs.has_php_files == 'true'
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.access-token }}
run: |
# Run phpcs and capture both the output and the exit code
JSON_REPORT=$(vendor/bin/phpcs --report=json -q ${{ env.CHANGED_FILES }} || echo "")
# Run phpcs — printf + xargs -d '\n' keeps filenames with spaces intact
JSON_REPORT=$(printf '%s\n' "${{ env.CHANGED_FILES }}" | xargs -d '\n' vendor/bin/phpcs --report=json -q)
PHPCS_EXIT_CODE=$?

# Check if phpcs produced a JSON report
Expand Down