Merge pull request #79 from MeetKamal/coding_standard_baseline

added coding-standard-baseline folder for codesniffer baseline task
This commit is contained in:
Simon Sprankel
2023-07-25 15:35:59 +02:00
committed by GitHub
2 changed files with 153 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
# Magento 2 Coding Standard Action
A Github Action that runs the Magento Coding Standard.
## Inputs
See the [action.yml](./action.yml)
## Usage
```yml
name: Coding Standard baseline
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
coding-standard:
runs-on: ubuntu-latest
steps:
- uses: mage-os/github-actions/coding-standard-baseline@main
with:
php_version: "8.1" # Optional, will be used for Php version
composer_version: "2"
version: "31" # Optional, will use the latest if omitted.
severity: "8" # Optional, will use phpcs default of 5 if not specified.
warning_severity: "4" # Optional, will use warning severity value if not specified.
error_severity: "7" # Optional, will use error severity value if not specified.
baseline_version: "1.1.2" # Optional, will use for php codesniffer baseline version
```
+118
View File
@@ -0,0 +1,118 @@
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.1"
description: "PHP version used to do the coding standard check."
composer_version:
type: string
required: true
default: "2"
description: "The version of composer to use."
version:
type: string
required: false
default: "31"
description: "The version of the coding standard to use. If not provided, will use the latest version."
severity:
type: string
required: false
default: "8"
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"
error_severity:
type: string
required: false
default: "8"
description: "The minimum severity required to display an error"
baseline_version:
type: string
required: false
default: "1.1.2"
description: "version of phpcs baseline"
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
- name: Checkout - Before Merge
shell: bash
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
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
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