Skip to content
Merged
Show file tree
Hide file tree
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
43 changes: 36 additions & 7 deletions .github/workflows/code-style.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
name: CodeStyle

on:
# Run on all relevant pushes (except to main) and on all relevant pull requests.
# Run on long-lived branch pushes and on all relevant pull requests.
push:
branches:
- main
- develop
- 'release/[0-9]+.[0-9]+*'
- 'hotfix/[0-9]+.[0-9]+*'
paths:
- '**.php'
- 'composer.json'
Expand Down Expand Up @@ -41,6 +46,7 @@ jobs:
with:
php-version: '8.2'
coverage: none
tools: cs2pr

# Validate the composer.json file.
# @link https://getcomposer.org/doc/03-cli.md#validate
Expand All @@ -62,16 +68,39 @@ jobs:
# Use a reproducible, unique suffix from the run id to avoid shell evaluation problems.
custom-cache-suffix: ${{ github.run_id }}

- name: Collect changed PHP files
id: changed_php
shell: bash
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
base="${{ github.event.pull_request.base.sha }}"
git fetch --no-tags --depth=1 origin "$base"
else
base="${{ github.event.before }}"
if [ "$base" = "0000000000000000000000000000000000000000" ]; then
base="HEAD^"
else
git fetch --no-tags --depth=1 origin "$base" || true
fi
fi

files="$(git diff --name-only --diff-filter=ACMRT "$base" HEAD -- '*.php' | tr '\n' ' ')"
echo "files=$files" >> "$GITHUB_OUTPUT"

if [ -z "$files" ]; then
echo "No changed PHP files to scan."
else
echo "Changed PHP files: $files"
fi

# Check the codestyle of the files.
# The results of the CS check will be shown inline in the PR via the CS2PR tool.
# @link https://github.com/staabm/annotate-pull-request-from-checkstyle/
- name: Check PHP code style
id: phpcs
run: composer check-cs -- --no-cache --report-full --report-checkstyle=./phpcs-report.xml
if: ${{ steps.changed_php.outputs.files != '' }}
run: ./vendor/bin/phpcs -s --no-cache --report-full --report-checkstyle=./phpcs-report.xml ${{ steps.changed_php.outputs.files }}

- name: Show PHPCS results in PR
if: ${{ always() && steps.phpcs.outcome == 'failure' }}
uses: staabm/annotate-pull-request-from-checkstyle@v2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
checkstyle_report: ./phpcs-report.xml
if: ${{ always() && steps.changed_php.outputs.files != '' && steps.phpcs.outcome == 'failure' }}
run: cs2pr ./phpcs-report.xml
6 changes: 2 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
with:
php-version: 8.1
coverage: none
tools: cs2pr

# The lint stage doesn't use code style, so no need for WPCS or phpcompatibility.
- name: 'Composer: adjust dependencies - remove PHPCompatibility'
Expand Down Expand Up @@ -66,10 +67,7 @@ jobs:

- name: Show lint results in PR
if: ${{ always() }}
uses: staabm/annotate-pull-request-from-checkstyle@v2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
checkstyle_report: ./lint-report.xml
run: cs2pr ./lint-report.xml

- name: Lint blueprint file
run: composer lint-blueprint
15 changes: 10 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,27 @@
"wp-coding-standards/wpcs": "3.3",
"phpstan/phpstan": "^2.0",
"phpstan/extension-installer": "^1.4",
"szepeviktor/phpstan-wordpress": "^2.0"
"szepeviktor/phpstan-wordpress": "^2.0",
"php-parallel-lint/php-parallel-lint": "^1.4",
"phpunit/phpunit": "^9.6"
},
"scripts": {
"check-cs": [
"@php ./vendor/bin/phpcs -s"
"@php ./vendor/bin/phpcs -s ."
],
"fix-cs": [
"PHP_CS_FIXER_IGNORE_ENV=1",
"@php ./vendor/bin/phpcbf",
"@php ./vendor/bin/phpcbf .",
"@php ./vendor/bin/php-cs-fixer fix . --allow-risky=yes"
],
"lint": [
"@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --show-deprecated --exclude vendor --exclude node_modules --exclude .git"
"@php ./vendor/bin/parallel-lint . -e php --show-deprecated --exclude vendor --exclude node_modules --exclude .git"
],
"lint-blueprint": [
"@php -r \"exit( intval( is_null( json_decode( file_get_contents( './.wordpress-org/blueprints/blueprint.json' ) ) ) ) );\""
],
"test": [
"@php ./vendor/phpunit/phpunit/phpunit --dont-report-useless-tests"
"@php ./vendor/bin/phpunit --dont-report-useless-tests"
],
"phpstan": [
"@php ./vendor/bin/phpstan analyse --memory-limit=2048M"
Expand All @@ -57,6 +59,9 @@
}
},
"config": {
"platform": {
"php": "8.1.0"
},
"allow-plugins": {
"composer/installers": true,
"dealerdirect/phpcodesniffer-composer-installer": true,
Expand Down
Loading
Loading