Skip to content

Commit 1f2328d

Browse files
committed
feat(coding-standard)!: simplify action architecture
Remove embedded PHP setup and checkout from the action; PHP version and composer version are now the caller's responsibility (set up via shivammathur/setup-php before invoking this action). Breaking changes: - Remove `php_version` and `composer_version` inputs - Change `path` default from `app/code` to `.` New features ported from graycore: - Add `composer_auth` input (passed as COMPOSER_AUTH env var) - Skip install when coding standard is already present (check-installed) - Support both vendor/magento and vendor/mage-os install paths - Require magento/php-compatibility-fork alongside coding standard - Improved phpcs flags via bash array; respects .phpcs.xml config files - Add branding block (icon: code, color: green) Remove changed-files detection (PR diff mode) — not present in graycore.
1 parent b281820 commit 1f2328d

3 files changed

Lines changed: 85 additions & 58 deletions

File tree

.github/workflows/_internal-coding-standard.yaml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@ on:
3232

3333
jobs:
3434
compute_matrix:
35+
if: "!startsWith(github.head_ref, 'release-please')"
3536
runs-on: ubuntu-latest
3637
outputs:
3738
matrix: ${{ steps.supported-version.outputs.matrix }}
3839
steps:
39-
- uses: actions/checkout@v4
40+
- uses: actions/checkout@v6
4041
- uses: ./supported-version
4142
with:
42-
kind: all
43+
kind: currently-supported
4344
id: supported-version
4445
- run: echo ${{ steps.supported-version.outputs.matrix }}
4546

@@ -50,10 +51,15 @@ jobs:
5051
fail-fast: false
5152
runs-on: ubuntu-latest
5253
steps:
53-
- uses: actions/checkout@v4
54+
- uses: actions/checkout@v6
55+
56+
- uses: shivammathur/setup-php@v2
57+
with:
58+
php-version: ${{ matrix.php }}
59+
tools: composer:v${{ matrix.composer }}
60+
coverage: none
61+
5462
- uses: './coding-standard'
5563
with:
5664
version: ${{ github.event.inputs.version || '*' }}
5765
path: ${{ github.event.inputs.path || '_test/demo-package' }}
58-
composer_version: ${{ matrix.composer }}
59-
php_version: ${{ matrix.php }}

coding-standard/README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22

33
A Github Action that runs the Magento Coding Standard.
44

5+
> [!WARNING]
6+
> This action is only compatible with Magento v2.4.4+.
7+
58
## Inputs
69

710
See the [action.yml](./action.yml)
811

912
## Usage
1013

14+
The caller is responsible for checking out the repository and setting up PHP before calling this action.
15+
1116
```yml
1217
name: Coding Standard
1318

@@ -23,10 +28,18 @@ jobs:
2328
coding-standard:
2429
runs-on: ubuntu-latest
2530
steps:
31+
- uses: actions/checkout@v6
32+
33+
- uses: shivammathur/setup-php@v2
34+
with:
35+
php-version: '8.3'
36+
tools: composer:v2
37+
coverage: none
38+
2639
- uses: mage-os/github-actions/coding-standard@main
2740
with:
41+
path: app/code # Optional, defaults to .
2842
version: 25 # Optional, will use the latest if omitted.
29-
path: app/code # Optional, will be used when event is not a pull request.
3043
severity: 8 # Optional, will use phpcs default of 5 if not specified.
3144
warning_severity: 4 # Optional, will use severity value if not specified.
3245
error_severity: 7 # Optional, will use severity value if not specified.

coding-standard/action.yml

Lines changed: 60 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,25 @@ author: "Graycore"
33
description: "A Github Action that runs the Magento Coding Standard."
44

55
inputs:
6-
php_version:
7-
required: true
8-
default: "8.3"
9-
description: "PHP version used to do the coding standard check."
10-
11-
composer_version:
12-
required: true
13-
default: "2"
14-
description: "The version of composer to use."
15-
166
path:
177
required: true
18-
default: 'app/code'
19-
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."
8+
default: '.'
9+
description: "The directory containing the code to check."
2010

2111
version:
2212
required: false
2313
description: "The version of the coding standard to use. If not provided, will use the latest version."
24-
14+
2515
severity:
2616
required: false
2717
default: ""
2818
description: "The minimum severity required to display an error or warning (default: 5)"
29-
19+
3020
warning_severity:
3121
required: false
3222
default: ""
3323
description: "The minimum severity required to display a warning"
34-
24+
3525
error_severity:
3626
required: false
3727
default: ""
@@ -42,72 +32,90 @@ inputs:
4232
default: 'false'
4333
required: false
4434

35+
composer_auth:
36+
required: false
37+
default: ""
38+
description: "Composer authentication credentials (contents of auth.json as a JSON string)"
39+
4540
runs:
4641
using: composite
4742
steps:
48-
- name: Checkout Project
49-
uses: actions/checkout@v3
50-
with:
51-
fetch-depth: 0
52-
path: project
53-
54-
- name: Create Standard Directory
43+
- name: Check if Coding Standard is already installed
44+
id: check-installed
5545
shell: bash
56-
run: mkdir standard
57-
58-
- name: Set PHP Version
59-
uses: shivammathur/setup-php@v2
60-
with:
61-
php-version: ${{ inputs.php_version }}
62-
tools: composer:v${{ inputs.composer_version }}
63-
coverage: none
46+
working-directory: ${{ inputs.path }}
47+
run: |
48+
if [ -d "vendor/magento/magento-coding-standard" ] || [ -d "vendor/mage-os/magento-coding-standard" ]; then
49+
echo "installed=true" >> $GITHUB_OUTPUT
50+
else
51+
echo "installed=false" >> $GITHUB_OUTPUT
52+
fi
6453
6554
- name: Get Composer Version
6655
uses: mage-os/github-actions/get-composer-version@main
6756
id: get-composer-version
57+
if: steps.check-installed.outputs.installed != 'true'
6858

6959
- name: Check if allow-plugins option is available for this version of composer
7060
uses: mage-os/github-actions/semver-compare@main
61+
id: is-allow-plugins-available
62+
if: steps.check-installed.outputs.installed != 'true'
7163
with:
7264
version: 2.2
7365
compare_against: ${{ steps.get-composer-version.outputs.version }}
74-
id: is-allow-plugins-available
7566

7667
- name: Enable dealerdirect/phpcodesniffer-composer-installer plugin
7768
shell: bash
78-
working-directory: standard
79-
run: composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true --global
80-
if: steps.is-allow-plugins-available.outputs.result < 1
69+
working-directory: ${{ inputs.path }}
70+
run: composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true --global
71+
if: steps.check-installed.outputs.installed != 'true' && steps.is-allow-plugins-available.outputs.result < 1
8172

8273
- name: Install Coding Standard
8374
shell: bash
84-
working-directory: standard
85-
run: composer require "magento/magento-coding-standard:${{ inputs.version || '*' }}"
75+
working-directory: ${{ inputs.path }}
76+
run: composer require "magento/magento-coding-standard:${{ inputs.version || '*' }}" "magento/php-compatibility-fork"
77+
if: steps.check-installed.outputs.installed != 'true'
78+
env:
79+
COMPOSER_AUTH: ${{ inputs.composer_auth }}
8680

8781
- name: Register Coding Standard
8882
shell: bash
89-
working-directory: standard
90-
run: vendor/bin/phpcs --config-set installed_paths ${{ github.workspace }}/standard/vendor/magento/magento-coding-standard,${{ github.workspace }}/standard/vendor/magento/php-compatibility-fork,${{ github.workspace }}/standard/vendor/phpcompatibility/php-compatibility
83+
working-directory: ${{ inputs.path }}
84+
run: |
85+
if [ -d vendor/magento/magento-coding-standard ]; then
86+
CODING_STANDARD_VENDOR=magento
87+
elif [ -d vendor/mage-os/magento-coding-standard ]; then
88+
CODING_STANDARD_VENDOR=mage-os
89+
else
90+
echo "No magento-coding-standard directory found under vendor/magento or vendor/mage-os."
91+
echo "Trusting dealerdirect/phpcodesniffer-composer-installer to have registered installed_paths."
92+
exit 0
93+
fi
94+
vendor/bin/phpcs --config-set installed_paths \
95+
"vendor/${CODING_STANDARD_VENDOR}/magento-coding-standard,vendor/${CODING_STANDARD_VENDOR}/php-compatibility-fork"
96+
if: steps.check-installed.outputs.installed != 'true'
9197

9298
- name: Set ignore warnings flag
9399
shell: bash
94-
working-directory: standard
100+
working-directory: ${{ inputs.path }}
95101
run: vendor/bin/phpcs --config-set ignore_warnings_on_exit 1
96102
if: inputs.ignore_warnings == 'true'
97103

98-
- name: Get Changed Files
99-
shell: bash
100-
working-directory: project
101-
id: changed-files
102-
run: echo "files=$(git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | xargs)" >> $GITHUB_OUTPUT
103-
if: github.event_name == 'pull_request'
104-
105104
- name: Coding Standard Check
106105
shell: bash
106+
working-directory: ${{ inputs.path }}
107107
run: |
108-
../standard/vendor/bin/phpcs --standard=Magento2 \
109-
$([ -n "${{ inputs.severity }}" ] && echo "--severity=${{ inputs.severity }}") \
110-
$([ -n "${{ inputs.warning_severity }}" ] && echo "--warning-severity=${{ inputs.warning_severity }}") \
111-
$([ -n "${{ inputs.error_severity }}" ] && echo "--error-severity=${{ inputs.error_severity }}") \
112-
${{ github.event_name == 'pull_request' && steps.changed-files.outputs.files || inputs.path }}
113-
working-directory: project
108+
FLAGS=()
109+
[ -n "${{ inputs.severity }}" ] && FLAGS+=(--severity=${{ inputs.severity }}) || true
110+
[ -n "${{ inputs.warning_severity }}" ] && FLAGS+=(--warning-severity=${{ inputs.warning_severity }}) || true
111+
[ -n "${{ inputs.error_severity }}" ] && FLAGS+=(--error-severity=${{ inputs.error_severity }}) || true
112+
113+
if [ -f .phpcs.xml ] || [ -f phpcs.xml ] || [ -f .phpcs.xml.dist ] || [ -f phpcs.xml.dist ]; then
114+
vendor/bin/phpcs "${FLAGS[@]}" .
115+
else
116+
vendor/bin/phpcs --standard=Magento2 --ignore=*vendor/* "${FLAGS[@]}" .
117+
fi
118+
119+
branding:
120+
icon: "code"
121+
color: "green"

0 commit comments

Comments
 (0)