Skip to content

Commit

Permalink
Merge pull request #653 from Automattic/fix/ghactions-improve-php-lin…
Browse files Browse the repository at this point in the history
…ting

GH Actions: switch over to parallel linting of PHP files
  • Loading branch information
rebeccahum authored Apr 15, 2021
2 parents c94e555 + 7d3d8cd commit 1af6b37
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 16 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/basics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ jobs:
coverage: none
tools: cs2pr

- name: 'Lint PHP against parse errors'
run: ./bin/php-lint

- name: Install xmllint
run: sudo apt-get install --no-install-recommends -y libxml2-utils

Expand Down
38 changes: 38 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,45 @@ on:
workflow_dispatch:

jobs:
#### PHP LINT STAGE ####
# Linting against high/low PHP versions should catch everything.
# If needs be, we can always add interim versions at a later point in time.
lint:
runs-on: ubuntu-latest

strategy:
matrix:
php: ['5.4', 'latest']
experimental: [false]

include:
- php: '8.1'
experimental: true

name: "Lint: PHP ${{ matrix.php }}"
continue-on-error: ${{ matrix.experimental }}

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none
tools: cs2pr

- name: Install Composer dependencies
uses: "ramsey/composer-install@v1"

- name: Lint against parse errors
run: ./bin/php-lint --checkstyle | cs2pr

test:
# No use running the tests if there is a linting error somewhere as they would fail anyway.
needs: lint

runs-on: ubuntu-latest

strategy:
Expand Down
14 changes: 1 addition & 13 deletions bin/php-lint
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,9 @@
#
# Lint the PHP files against parse errors.
#
# The find utility recursively descends the directory tree for each path listed.
#
# find . = Start with all files in this package
# -path ./vendor -prune = But remove those in the vendor directory
# -o -path ./bin -prune = And remove those in the bin directory
# -o -path ./.git -prune = And remove those in the .git directory
# -o -name "*.php" = And only consider those with a .php extension
# -exec php -l {} = Run PHP linter on the remaining files
# | grep "^[Parse error|Fatal error]" = Look in the results for any parse or fatal errors.
#
# EXAMPLE TO RUN LOCALLY:
#
# ./bin/php-lint
#

if find . -path ./vendor -prune -o -path ./bin -prune -o -path ./.git -prune -o -name "*.php" -exec php -l -f {} \; | grep "^[Errors parsing]"; then
exit 1;
fi
"$(pwd)/vendor/bin/parallel-lint" . -e php --exclude vendor --exclude .git $@
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"wp-coding-standards/wpcs": "^2.3"
},
"require-dev": {
"php-parallel-lint/php-parallel-lint": "^1.0",
"php-parallel-lint/php-console-highlighter": "^0.5",
"phpcompatibility/php-compatibility": "^9",
"phpunit/phpunit": "^4 || ^5 || ^6 || ^7"
},
Expand Down

0 comments on commit 1af6b37

Please sign in to comment.