feat(coding-standard)!: remove pr-diff feature and built-in php setup (#224)

BREAKING CHANGE: Much of the "setup" that's built-into the command is removed in favor of a leaner action. This also includes the "on PR, only diff PR contents" behavior. This can be restored, but it shouldn't be the default and should be done as an input.

Fix SEVERITY_FLAGS construction which exited 1 under bash -e when
severity inputs were empty, causing CI failures.
This commit is contained in:
Damien Retzinger
2026-04-26 22:51:44 -04:00
committed by GitHub
parent 953de845eb
commit d5c744e155
4 changed files with 66 additions and 105 deletions
@@ -51,9 +51,14 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v6 - uses: actions/checkout@v6
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer:v${{ matrix.composer }}
coverage: none
- uses: './coding-standard' - uses: './coding-standard'
with: with:
version: ${{ github.event.inputs.version || '*' }} version: ${{ github.event.inputs.version || '*' }}
path: ${{ github.event.inputs.path || '_test/demo-package' }} path: ${{ github.event.inputs.path || '_test/demo-package' }}
composer_version: ${{ matrix.composer }}
php_version: ${{ matrix.php }}
+7 -47
View File
@@ -153,55 +153,15 @@ jobs:
steps: steps:
- uses: actions/checkout@v6 - uses: actions/checkout@v6
- name: Get Composer Version - uses: shivammathur/setup-php@v2
uses: graycoreio/github-actions-magento2/get-composer-version@main
id: get-composer-version
- name: Check if allow-plugins option is available for this version of composer
uses: graycoreio/github-actions-magento2/semver-compare@main
with: with:
version: 2.2 php-version: ${{ matrix.php }}
compare_against: ${{ steps.get-composer-version.outputs.version }} tools: composer:v${{ matrix.composer }}
id: is-allow-plugins-available coverage: none
- name: Enable dealerdirect/phpcodesniffer-composer-installer plugin - uses: graycoreio/github-actions-magento2/coding-standard@main
shell: bash with:
working-directory: ${{ inputs.path }} path: ${{ inputs.path }}
run: composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true --global
if: steps.is-allow-plugins-available.outputs.result < 1
- name: Install Coding Standard
shell: bash
working-directory: ${{ inputs.path }}
run: composer require "magento/magento-coding-standard" "magento/php-compatibility-fork"
env:
COMPOSER_AUTH: ${{ secrets.composer_auth }}
- name: Register Coding Standard
shell: bash
working-directory: ${{ inputs.path }}
run: |
if [ -d vendor/magento/magento-coding-standard ]; then
CODING_STANDARD_VENDOR=magento
elif [ -d vendor/mage-os/magento-coding-standard ]; then
CODING_STANDARD_VENDOR=mage-os
else
echo "No magento-coding-standard directory found under vendor/magento or vendor/mage-os."
echo "Trusting dealerdirect/phpcodesniffer-composer-installer to have registered installed_paths."
exit 0
fi
vendor/bin/phpcs --config-set installed_paths \
"vendor/${CODING_STANDARD_VENDOR}/magento-coding-standard,vendor/${CODING_STANDARD_VENDOR}/php-compatibility-fork"
- name: Coding Standard Check
shell: bash
run: |
if [ -f .phpcs.xml ] || [ -f phpcs.xml ] || [ -f .phpcs.xml.dist ] || [ -f phpcs.xml.dist ]; then
./vendor/bin/phpcs .
else
./vendor/bin/phpcs --standard=Magento2 --ignore=*vendor/* .
fi
working-directory: ${{ inputs.path }}
integration_test: integration_test:
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
+11 -1
View File
@@ -11,6 +11,8 @@ See the [action.yml](./action.yml)
## Usage ## Usage
The caller is responsible for checking out the repository and setting up PHP before calling this action.
```yml ```yml
name: Coding Standard name: Coding Standard
@@ -26,10 +28,18 @@ jobs:
coding-standard: coding-standard:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v6
- uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
tools: composer:v2
coverage: none
- uses: graycoreio/github-actions-magento2/coding-standard@main - uses: graycoreio/github-actions-magento2/coding-standard@main
with: with:
path: app/code # Optional, defaults to .
version: 25 # Optional, will use the latest if omitted. version: 25 # Optional, will use the latest if omitted.
path: app/code # Optional, will be used when event is not a pull request.
severity: 8 # Optional, will use phpcs default of 5 if not specified. severity: 8 # Optional, will use phpcs default of 5 if not specified.
warning_severity: 4 # Optional, will use severity value if not specified. warning_severity: 4 # Optional, will use severity value if not specified.
error_severity: 7 # Optional, will use severity value if not specified. error_severity: 7 # Optional, will use severity value if not specified.
+35 -49
View File
@@ -3,20 +3,10 @@ author: "Graycore"
description: "A Github Action that runs the Magento Coding Standard." description: "A Github Action that runs the Magento Coding Standard."
inputs: inputs:
php_version:
required: true
default: "8.1"
description: "PHP version used to do the coding standard check."
composer_version:
required: true
default: "2"
description: "The version of composer to use."
path: path:
required: true required: true
default: 'app/code' default: '.'
description: "The directory (relative to the project root) in which the coding standard will be checked. Used when the event is not a pull request." description: "The directory containing the code to check."
version: version:
required: false required: false
@@ -45,69 +35,65 @@ inputs:
runs: runs:
using: composite using: composite
steps: steps:
- name: Checkout Project
uses: actions/checkout@v6
with:
fetch-depth: 0
path: project
- name: Create Standard Directory
shell: bash
run: mkdir standard
- name: Set PHP Version
uses: shivammathur/setup-php@v2
with:
php-version: ${{ inputs.php_version }}
tools: composer:v${{ inputs.composer_version }}
coverage: none
- name: Get Composer Version - name: Get Composer Version
uses: graycoreio/github-actions-magento2/get-composer-version@main uses: graycoreio/github-actions-magento2/get-composer-version@main
id: get-composer-version id: get-composer-version
- name: Check if allow-plugins option is available for this version of composer - name: Check if allow-plugins option is available for this version of composer
uses: graycoreio/github-actions-magento2/semver-compare@main uses: graycoreio/github-actions-magento2/semver-compare@main
id: is-allow-plugins-available
with: with:
version: 2.2 version: 2.2
compare_against: ${{ steps.get-composer-version.outputs.version }} compare_against: ${{ steps.get-composer-version.outputs.version }}
id: is-allow-plugins-available
- name: Enable dealerdirect/phpcodesniffer-composer-installer plugin - name: Enable dealerdirect/phpcodesniffer-composer-installer plugin
shell: bash shell: bash
working-directory: standard working-directory: ${{ inputs.path }}
run: composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true --global run: composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true --global
if: steps.is-allow-plugins-available.outputs.result < 1 if: steps.is-allow-plugins-available.outputs.result < 1
- name: Install Coding Standard - name: Install Coding Standard
shell: bash shell: bash
working-directory: standard working-directory: ${{ inputs.path }}
run: composer require "magento/magento-coding-standard:${{ inputs.version || '*' }}" run: composer require "magento/magento-coding-standard:${{ inputs.version || '*' }}" "magento/php-compatibility-fork"
- name: Register Coding Standard - name: Register Coding Standard
shell: bash shell: bash
working-directory: standard working-directory: ${{ inputs.path }}
run: vendor/bin/phpcs --config-set installed_paths ${{ github.workspace }}/standard/vendor/magento/magento-coding-standard,${{ github.workspace }}/standard/vendor/magento/php-compatibility-fork run: |
if [ -d vendor/magento/magento-coding-standard ]; then
CODING_STANDARD_VENDOR=magento
elif [ -d vendor/mage-os/magento-coding-standard ]; then
CODING_STANDARD_VENDOR=mage-os
else
echo "No magento-coding-standard directory found under vendor/magento or vendor/mage-os."
echo "Trusting dealerdirect/phpcodesniffer-composer-installer to have registered installed_paths."
exit 0
fi
vendor/bin/phpcs --config-set installed_paths \
"vendor/${CODING_STANDARD_VENDOR}/magento-coding-standard,vendor/${CODING_STANDARD_VENDOR}/php-compatibility-fork"
- name: Set ignore warnings flag - name: Set ignore warnings flag
shell: bash shell: bash
working-directory: standard working-directory: ${{ inputs.path }}
run: vendor/bin/phpcs --config-set ignore_warnings_on_exit 1 run: vendor/bin/phpcs --config-set ignore_warnings_on_exit 1
if: inputs.ignore_warnings == 'true' if: inputs.ignore_warnings == 'true'
- name: Get Changed Files
shell: bash
working-directory: project
id: changed-files
run: echo "files=$(git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | xargs)" >> $GITHUB_OUTPUT
if: github.event_name == 'pull_request'
- name: Coding Standard Check - name: Coding Standard Check
shell: bash shell: bash
working-directory: ${{ inputs.path }}
run: | run: |
../standard/vendor/bin/phpcs --standard=Magento2 \ FLAGS=()
$([ -n "${{ inputs.severity }}" ] && echo "--severity=${{ inputs.severity }}") \ [ -n "${{ inputs.severity }}" ] && FLAGS+=(--severity=${{ inputs.severity }}) || true
$([ -n "${{ inputs.warning_severity }}" ] && echo "--warning-severity=${{ inputs.warning_severity }}") \ [ -n "${{ inputs.warning_severity }}" ] && FLAGS+=(--warning-severity=${{ inputs.warning_severity }}) || true
$([ -n "${{ inputs.error_severity }}" ] && echo "--error-severity=${{ inputs.error_severity }}") \ [ -n "${{ inputs.error_severity }}" ] && FLAGS+=(--error-severity=${{ inputs.error_severity }}) || true
${{ github.event_name == 'pull_request' && steps.changed-files.outputs.files || inputs.path }}
working-directory: project if [ -f .phpcs.xml ] || [ -f phpcs.xml ] || [ -f .phpcs.xml.dist ] || [ -f phpcs.xml.dist ]; then
vendor/bin/phpcs "${FLAGS[@]}" .
else
vendor/bin/phpcs --standard=Magento2 --ignore=*vendor/* "${FLAGS[@]}" .
fi
branding:
icon: "code"
color: "green"