mirror of
https://github.com/graycoreio/github-actions-magento2.git
synced 2026-06-08 19:46:41 +00:00
fix: switch from tj-actions/changed-files to dorny/paths-filter
This commit is contained in:
@@ -45,70 +45,67 @@ inputs:
|
||||
default: "*"
|
||||
description: "The version of phpcs baseline to use (default: latest)."
|
||||
|
||||
head_repo:
|
||||
type: string
|
||||
required: true
|
||||
description: "The repository full name of the head branch. E.g.: mage-os/mageos-magento2"
|
||||
|
||||
head_ref:
|
||||
type: string
|
||||
required: true
|
||||
description: "The branch name of the head branch. E.g.: main"
|
||||
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Checkout head
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{github.event.pull_request.head.ref}}
|
||||
repository: ${{github.event.pull_request.head.repo.full_name}}
|
||||
ref: ${{ inputs.head_ref }}
|
||||
repository: ${{ inputs.head_repo }}
|
||||
|
||||
- name: Get all changed files
|
||||
uses: tj-actions/changed-files@v39
|
||||
id: changed-files-phpcs
|
||||
- uses: dorny/paths-filter@v2
|
||||
name: Filter changed files
|
||||
id: filter
|
||||
with:
|
||||
files_yaml: |
|
||||
app:
|
||||
- '**/*.php'
|
||||
- '**/*.phtml'
|
||||
- '**/*.graphqls'
|
||||
- '**/*.less'
|
||||
- '**/*.css'
|
||||
- '**/*.html'
|
||||
- '**/*.xml'
|
||||
- '**/*.js'
|
||||
list-files: shell
|
||||
filters: |
|
||||
phpcs:
|
||||
- added|modified: '**/**.{php,phtml,graphqls,less,css,html,xml,js}'
|
||||
|
||||
- name: Inform if no files have changed
|
||||
if: steps.changed-files-phpcs.outputs.app_any_changed == 'false'
|
||||
shell: bash
|
||||
run: |
|
||||
echo "No files relevant to PHPCS have changed. Skipping PHPCS run."
|
||||
echo "List all the files that have changed: ${{ steps.changed-files-phpcs.outputs.app_all_changed_files }}"
|
||||
|
||||
- name: Inform if relevant files have changed
|
||||
if: steps.changed-files-phpcs.outputs.app_any_changed == 'true'
|
||||
- name: Check changed files for PHPcs
|
||||
if: steps.filter.outputs.phpcs == 'true'
|
||||
shell: bash
|
||||
run: |
|
||||
echo "One or more files relevant to PHPCS have changed."
|
||||
echo "List all the files that have changed: ${{ steps.changed-files-phpcs.outputs.app_all_changed_files }}"
|
||||
echo "List all the files that have changed: ${{ steps.filter.outputs.phpcs_files }}"
|
||||
|
||||
- name: Setup PHP
|
||||
if: steps.changed-files-phpcs.outputs.app_any_changed == 'true'
|
||||
if: steps.filter.outputs.phpcs == 'true'
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: ${{ inputs.php_version }}
|
||||
tools: composer:v${{ inputs.composer_version }}
|
||||
coverage: none
|
||||
|
||||
- name: Create composer project
|
||||
if: steps.changed-files-phpcs.outputs.app_any_changed == 'true'
|
||||
- name: Install coding standards
|
||||
if: steps.filter.outputs.phpcs == 'true'
|
||||
shell: bash
|
||||
run: |
|
||||
composer create-project --no-plugins --no-dev \
|
||||
magento/magento-coding-standard \
|
||||
magento-coding-standard "${{ github.event.inputs.version || '*' }}"
|
||||
|
||||
- name: Register coding standards
|
||||
if: steps.changed-files-phpcs.outputs.app_any_changed == 'true'
|
||||
- name: Install phpcs baseline
|
||||
if: steps.filter.outputs.phpcs == 'true'
|
||||
working-directory: magento-coding-standard
|
||||
shell: bash
|
||||
run: |
|
||||
composer config --no-plugins allow-plugins.digitalrevolution/php-codesniffer-baseline true
|
||||
composer require --dev "digitalrevolution/php-codesniffer-baseline: ${{ github.event.inputs.baseline_version || '*' }}"
|
||||
|
||||
- name: Checkout base to generate baseline
|
||||
if: steps.changed-files-phpcs.outputs.app_any_changed == 'true'
|
||||
- name: Checkout base
|
||||
if: steps.filter.outputs.phpcs == 'true'
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{github.event.pull_request.base.ref}}
|
||||
@@ -118,17 +115,17 @@ runs:
|
||||
- name: Create phpcs.baseline.xml from base
|
||||
shell: bash
|
||||
working-directory: base
|
||||
if: steps.changed-files-phpcs.outputs.app_any_changed == 'true'
|
||||
if: steps.filter.outputs.phpcs == 'true'
|
||||
run: |
|
||||
php ${{ github.workspace }}/magento-coding-standard/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=phpcs.baseline.xml \
|
||||
${{ steps.changed-files-phpcs.outputs.app_all_changed_files }} || /bin/true
|
||||
${{ steps.filter.outputs.phpcs_files }} || /bin/true
|
||||
|
||||
- name: Copy baseline to head
|
||||
if: steps.changed-files-phpcs.outputs.app_any_changed == 'true'
|
||||
if: steps.filter.outputs.phpcs == 'true'
|
||||
shell: bash
|
||||
run: |
|
||||
cp ${{ github.workspace }}/base/phpcs.baseline.xml ${{ github.workspace }}/magento-coding-standard/phpcs.baseline.xml
|
||||
@@ -136,17 +133,17 @@ runs:
|
||||
# Since we ran phpcs in the base folder, the files in phpcs.baseline.xml contain the base folder in the path.
|
||||
# We need to remove /base/ so that the phpcs can locate the correct files.
|
||||
- name: Remove base dir from phpcs baseline
|
||||
if: steps.changed-files-phpcs.outputs.app_any_changed == 'true'
|
||||
if: steps.filter.outputs.phpcs == 'true'
|
||||
shell: bash
|
||||
run: |
|
||||
sed -i "s|/base/|/|" ${{ github.workspace }}/magento-coding-standard/phpcs.baseline.xml
|
||||
|
||||
- name: Execute phpcs on head for changed files
|
||||
shell: bash
|
||||
if: steps.changed-files-phpcs.outputs.app_any_changed == 'true'
|
||||
run: |
|
||||
if: steps.filter.outputs.phpcs == 'true'
|
||||
run: |
|
||||
php ${{ github.workspace }}/magento-coding-standard/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 }}") \
|
||||
${{ steps.changed-files-phpcs.outputs.app_all_changed_files }}
|
||||
${{ steps.filter.outputs.phpcs_files }}
|
||||
|
||||
Reference in New Issue
Block a user