mirror of
https://github.com/graycoreio/github-actions-magento2.git
synced 2026-06-08 19:46:41 +00:00
d5c744e155
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.
99 lines
3.6 KiB
YAML
99 lines
3.6 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
|
|
|
|
runs:
|
|
using: composite
|
|
steps:
|
|
- name: Get Composer Version
|
|
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
|
|
id: is-allow-plugins-available
|
|
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.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"
|
|
|
|
- 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: 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" |