mirror of
https://github.com/graycoreio/github-actions-magento2.git
synced 2026-06-08 19:46:41 +00:00
121 lines
4.4 KiB
YAML
121 lines
4.4 KiB
YAML
name: "Coding Standard"
|
|
author: "Graycore"
|
|
description: "A Github Action that runs the Magento Coding Standard."
|
|
|
|
inputs:
|
|
path:
|
|
required: true
|
|
default: '.'
|
|
description: "The directory containing the code to check."
|
|
|
|
version:
|
|
required: false
|
|
description: "The version of the coding standard to use. If not provided, will use the latest version."
|
|
|
|
severity:
|
|
required: false
|
|
default: ""
|
|
description: "The minimum severity required to display an error or warning (default: 5)"
|
|
|
|
warning_severity:
|
|
required: false
|
|
default: ""
|
|
description: "The minimum severity required to display a warning"
|
|
|
|
error_severity:
|
|
required: false
|
|
default: ""
|
|
description: "The minimum severity required to display an error"
|
|
|
|
ignore_warnings:
|
|
description: 'Whether or not the action should fail on warnings, defaults to false (fails on warnings)'
|
|
default: 'false'
|
|
required: false
|
|
|
|
composer_auth:
|
|
required: false
|
|
default: ""
|
|
description: "Composer authentication credentials (contents of auth.json as a JSON string)"
|
|
|
|
runs:
|
|
using: composite
|
|
steps:
|
|
- name: Check if Coding Standard is already installed
|
|
id: check-installed
|
|
shell: bash
|
|
working-directory: ${{ inputs.path }}
|
|
run: |
|
|
if [ -d "vendor/magento/magento-coding-standard" ] || [ -d "vendor/mage-os/magento-coding-standard" ]; then
|
|
echo "installed=true" >> $GITHUB_OUTPUT
|
|
else
|
|
echo "installed=false" >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
- name: Get Composer Version
|
|
uses: graycoreio/github-actions-magento2/get-composer-version@v8.0.0-rc.1
|
|
id: get-composer-version
|
|
if: steps.check-installed.outputs.installed != 'true'
|
|
|
|
- name: Check if allow-plugins option is available for this version of composer
|
|
uses: graycoreio/github-actions-magento2/semver-compare@v8.0.0-rc.1
|
|
id: is-allow-plugins-available
|
|
if: steps.check-installed.outputs.installed != 'true'
|
|
with:
|
|
version: 2.2
|
|
compare_against: ${{ steps.get-composer-version.outputs.version }}
|
|
|
|
- name: Enable dealerdirect/phpcodesniffer-composer-installer plugin
|
|
shell: bash
|
|
working-directory: ${{ inputs.path }}
|
|
run: composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true --global
|
|
if: steps.check-installed.outputs.installed != 'true' && 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:${{ inputs.version || '*' }}" "magento/php-compatibility-fork"
|
|
if: steps.check-installed.outputs.installed != 'true'
|
|
env:
|
|
COMPOSER_AUTH: ${{ inputs.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"
|
|
if: steps.check-installed.outputs.installed != 'true'
|
|
|
|
- name: Set ignore warnings flag
|
|
shell: bash
|
|
working-directory: ${{ inputs.path }}
|
|
run: vendor/bin/phpcs --config-set ignore_warnings_on_exit 1
|
|
if: inputs.ignore_warnings == 'true'
|
|
|
|
- name: Coding Standard Check
|
|
shell: bash
|
|
working-directory: ${{ inputs.path }}
|
|
run: |
|
|
FLAGS=()
|
|
[ -n "${{ inputs.severity }}" ] && FLAGS+=(--severity=${{ inputs.severity }}) || true
|
|
[ -n "${{ inputs.warning_severity }}" ] && FLAGS+=(--warning-severity=${{ inputs.warning_severity }}) || true
|
|
[ -n "${{ inputs.error_severity }}" ] && FLAGS+=(--error-severity=${{ inputs.error_severity }}) || true
|
|
|
|
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" |