@@ -3,35 +3,25 @@ author: "Graycore"
33description : " A Github Action that runs the Magento Coding Standard."
44
55inputs :
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+
4540runs :
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