Skip to content

Commit

Permalink
Check only changed files for PHP and XML linting
Browse files Browse the repository at this point in the history
  • Loading branch information
justinbeaty committed Nov 1, 2024
1 parent 6faa521 commit 11afbc8
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 15 deletions.
63 changes: 51 additions & 12 deletions .github/workflows/syntax-php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,44 @@ on:
workflow_dispatch:

jobs:
files:
name: Find Changed Files
runs-on: [ubuntu-latest]
outputs:
any_changed: ${{ steps.changed-files.outputs.any_changed }}
all_changed_files: ${{ steps.changed-files.outputs.all_changed_files }}

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Get last successful commit
id: last-successful-commit
uses: nrwl/nx-set-shas@v4
with:
workflow-id: 'syntax-xml.yml'

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v45
with:
base_sha: ${{ steps.last-successful-commit.outputs.base }}
files: |
**/*.{php,phtml}
!.phpstorm.meta.php/*
syntax_php:
name: PHP Syntax ${{ matrix.php-versions }}
runs-on: [ubuntu-latest]
needs: files
if: ${{ needs.files.outputs.any_changed == 'true' }}

strategy:
fail-fast: false
matrix:
php: ['8.2', '8.3', '8.4']

name: PHP Syntax ${{ matrix.php }}
php-versions: ['8.2', '8.3', '8.4']

steps:
- name: Checkout code
Expand All @@ -23,13 +53,22 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: mbstring #optional, setup extensions
ini-values: post_max_size=256M, short_open_tag=On #optional, setup php.ini configuration
coverage: none #optional, setup coverage driver

- name: Check .php files
run: '! find . -not \( -path ./.phpstorm.meta.php -prune \) -type f -name "*.php" -exec php -d error_reporting=32767 -l {} \; 2>&1 1> /dev/null | grep "^"'
php-version: ${{ matrix.php-versions }}
ini-values: error_reporting=E_ALL, short_open_tag=Off
tools: none

- name: Check .phtml files
run: '! find app/design -type f -name "*.phtml" -exec php -d error_reporting=32767 -l {} \; 2>&1 1> /dev/null | grep "^"'
- name: Check changed files
env:
ALL_CHANGED_FILES: ${{ needs.files.outputs.all_changed_files }}
run: |
set +e
ERROR=0
for FILE in ${ALL_CHANGED_FILES}; do
MESSAGE=$(php -l "$FILE" 2>&1 1>/dev/null)
if [ $? -ne 0 ]; then
ERROR=255
LINE=$(echo $MESSAGE | sed -En 's/.*on line ([0-9]+).*/\1/p')
echo "::error file=$FILE,line=$LINE::$MESSAGE"
fi
done
exit $ERROR
48 changes: 45 additions & 3 deletions .github/workflows/syntax-xml.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,38 @@ on:
workflow_dispatch:

jobs:
files:
name: Find Changed Files
runs-on: [ubuntu-latest]
outputs:
any_changed: ${{ steps.changed-files.outputs.any_changed }}
all_changed_files: ${{ steps.changed-files.outputs.all_changed_files }}

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Get last successful commit
id: last-successful-commit
uses: nrwl/nx-set-shas@v4
with:
workflow-id: 'syntax-xml.yml'

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v45
with:
base_sha: ${{ steps.last-successful-commit.outputs.base }}
files: |
**/*.xml
syntax_xml:
name: XML Validation
name: XML Syntax
runs-on: [ubuntu-latest]
needs: files
if: ${{ needs.files.outputs.any_changed == 'true' }}

steps:
- name: Checkout code
Expand All @@ -21,5 +50,18 @@ jobs:
- name: Install xmllint
run: "sudo apt-get -y install libxml2-utils"

- name: Validate XMLs
run: "find . -type f -iname '*.xml' | xargs -I '{}' xmllint --noout '{}'"
- name: Check changed files
env:
ALL_CHANGED_FILES: ${{ needs.files.outputs.all_changed_files }}
run: |
set +e
ERROR=0
for FILE in ${ALL_CHANGED_FILES}; do
MESSAGE=$(xmllint --noout "$FILE" 2>&1)
if [ $? -ne 0 ]; then
ERROR=255
LINE=$(echo "$MESSAGE" | head -n 1 | cut -d":" -f 2)
echo "::error file=$FILE,line=$LINE::$MESSAGE"
fi
done
exit $ERROR

0 comments on commit 11afbc8

Please sign in to comment.