mirror of
https://github.com/graycoreio/github-actions-magento2.git
synced 2026-06-08 19:46:41 +00:00
122 lines
4.5 KiB
YAML
Executable File
122 lines
4.5 KiB
YAML
Executable File
name: "M2 Coding Standard"
|
|
author: "Mage-OS"
|
|
description: "A Github Action that runs the Magento Coding Standard."
|
|
|
|
inputs:
|
|
php_version:
|
|
type: string
|
|
required: true
|
|
default: "8.2"
|
|
description: "PHP version used to do the coding standard check (default: 8.2)."
|
|
|
|
composer_version:
|
|
type: string
|
|
required: true
|
|
default: "2"
|
|
description: "The version of composer to use (default: 2)."
|
|
|
|
version:
|
|
type: string
|
|
required: false
|
|
default: "*"
|
|
description: "The version of the coding standard to use (default: latest)."
|
|
|
|
severity:
|
|
type: string
|
|
required: false
|
|
default: "5"
|
|
description: "The minimum severity required to display an error or warning (default: 5)"
|
|
|
|
warning_severity:
|
|
type: string
|
|
required: false
|
|
default: "8"
|
|
description: "The minimum severity required to display a warning (default: 8)."
|
|
|
|
error_severity:
|
|
type: string
|
|
required: false
|
|
default: "8"
|
|
description: "The minimum severity required to display an error (default: 8)."
|
|
|
|
baseline_version:
|
|
type: string
|
|
required: false
|
|
default: "*"
|
|
description: "The version of phpcs baseline to use (default: latest)."
|
|
|
|
runs:
|
|
using: composite
|
|
steps:
|
|
- name: Checkout Project
|
|
uses: actions/checkout@v3
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Set PHP Version
|
|
uses: shivammathur/setup-php@v2
|
|
with:
|
|
php-version: ${{ inputs.php_version }}
|
|
tools: composer:v${{ inputs.composer_version }}
|
|
coverage: none
|
|
|
|
- name: Install Coding Standard && Codesniffer baseline
|
|
shell: bash
|
|
run: |
|
|
git config --global advice.detachedHead false
|
|
composer require "magento/magento-coding-standard: ${{ github.event.inputs.version || '*' }}" -W
|
|
composer config --no-plugins allow-plugins.digitalrevolution/php-codesniffer-baseline true
|
|
composer require --dev "digitalrevolution/php-codesniffer-baseline: ${{ github.event.inputs.baseline_version || '*' }}"
|
|
|
|
- name: Register Coding Standard
|
|
shell: bash
|
|
run: vendor/bin/phpcs --config-set installed_paths ${{ github.workspace }}/vendor/magento/magento-coding-standard,${{ github.workspace }}/vendor/phpcompatibility/php-compatibility
|
|
|
|
- name: Get all changed files
|
|
uses: tj-actions/changed-files@v37
|
|
with:
|
|
write_output_files: true
|
|
output_dir: ${{ github.workspace }}
|
|
separator: " "
|
|
|
|
- name: Verify the contents of the modified_files.txt file
|
|
shell: bash
|
|
run: |
|
|
sed "s/ /\n/g" ${{ github.workspace }}/modified_files.txt > ${{ github.workspace }}/newline_file.txt
|
|
grep -iE "\.php|\.phtml|\.html|\.xml" ${{ github.workspace }}/newline_file.txt > ${{ github.workspace }}/phpcs_files.txt || /bin/true
|
|
|
|
- name: Checkout - Before Merge
|
|
shell: bash
|
|
if: test -s ${{ github.workspace }}/phpcs_files.txt
|
|
run: |
|
|
if ${{ github.event_name == 'pull_request' }}; then
|
|
git checkout ${{ github.event.pull_request.base.ref }}
|
|
else
|
|
git checkout ${{ github.event.before }}
|
|
fi
|
|
|
|
- name: Filter php files and execute phpcs - Before Merge
|
|
shell: bash
|
|
if: test -s ${{ github.workspace }}/phpcs_files.txt
|
|
run: |
|
|
php vendor/bin/phpcs --standard=Magento2 \
|
|
$([ -n "${{ inputs.severity }}" ] && echo "--severity=${{ inputs.severity }}") \
|
|
$([ -n "${{ inputs.warning_severity }}" ] && echo "--warning-severity=${{ inputs.warning_severity }}") \
|
|
$([ -n "${{ inputs.error_severity }}" ] && echo "--error-severity=${{ inputs.error_severity }}") \
|
|
--report=\\DR\\CodeSnifferBaseline\\Reports\\Baseline --report-file=${{ github.workspace }}/phpcs.baseline.xml --file-list=${{ github.workspace }}/phpcs_files.txt || /bin/true
|
|
|
|
- name: Checkout after Merge and execute phpcs
|
|
shell: bash
|
|
if: test -s ${{ github.workspace }}/phpcs_files.txt
|
|
run: |
|
|
if ${{ github.event_name == 'pull_request' }}; then
|
|
git checkout ${{ github.event.pull_request.head.ref }}
|
|
else
|
|
git checkout ${{ github.event.after }}
|
|
fi
|
|
php vendor/bin/phpcs --standard=Magento2 \
|
|
$([ -n "${{ inputs.severity }}" ] && echo "--severity=${{ inputs.severity }}") \
|
|
$([ -n "${{ inputs.warning_severity }}" ] && echo "--warning-severity=${{ inputs.warning_severity }}") \
|
|
$([ -n "${{ inputs.error_severity }}" ] && echo "--error-severity=${{ inputs.error_severity }}") \
|
|
--file-list=${{ github.workspace }}/phpcs_files.txt
|