Skip to content

Commit 87fe77f

Browse files
committed
fix: switch from tj-actions/changed-files to dorny/paths-filter
1 parent 168696e commit 87fe77f

File tree

1 file changed

+36
-39
lines changed

1 file changed

+36
-39
lines changed

coding-standard-baseline/action.yml

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -45,70 +45,67 @@ inputs:
4545
default: "*"
4646
description: "The version of phpcs baseline to use (default: latest)."
4747

48+
head_repo:
49+
type: string
50+
required: true
51+
description: "The repository full name of the head branch. E.g.: mage-os/mageos-magento2"
52+
53+
head_ref:
54+
type: string
55+
required: true
56+
description: "The branch name of the head branch. E.g.: main"
57+
4858
runs:
4959
using: composite
5060
steps:
5161
- name: Checkout head
5262
uses: actions/checkout@v4
5363
with:
54-
ref: ${{github.event.pull_request.head.ref}}
55-
repository: ${{github.event.pull_request.head.repo.full_name}}
64+
ref: ${{ inputs.head_ref }}
65+
repository: ${{ inputs.head_repo }}
5666

57-
- name: Get all changed files
58-
uses: tj-actions/changed-files@v39
59-
id: changed-files-phpcs
67+
- uses: dorny/paths-filter@v2
68+
name: Filter changed files
69+
id: filter
6070
with:
61-
files_yaml: |
62-
app:
63-
- '**/*.php'
64-
- '**/*.phtml'
65-
- '**/*.graphqls'
66-
- '**/*.less'
67-
- '**/*.css'
68-
- '**/*.html'
69-
- '**/*.xml'
70-
- '**/*.js'
71-
72-
- name: Inform if no files have changed
73-
if: steps.changed-files-phpcs.outputs.app_any_changed == 'false'
74-
shell: bash
75-
run: |
76-
echo "No files relevant to PHPCS have changed. Skipping PHPCS run."
77-
echo "List all the files that have changed: ${{ steps.changed-files-phpcs.outputs.app_all_changed_files }}"
71+
list-files: shell
72+
filters: |
73+
phpcs:
74+
- added|modified: '**/**.{php,phtml,graphqls,less,css,html,xml,js}'
7875
79-
- name: Inform if relevant files have changed
80-
if: steps.changed-files-phpcs.outputs.app_any_changed == 'true'
76+
- name: Check changed files for PHPcs
77+
if: steps.filter.outputs.phpcs == 'true'
8178
shell: bash
8279
run: |
8380
echo "One or more files relevant to PHPCS have changed."
84-
echo "List all the files that have changed: ${{ steps.changed-files-phpcs.outputs.app_all_changed_files }}"
81+
echo "List all the files that have changed: ${{ steps.filter.outputs.phpcs_files }}"
8582
8683
- name: Setup PHP
87-
if: steps.changed-files-phpcs.outputs.app_any_changed == 'true'
84+
if: steps.filter.outputs.phpcs == 'true'
8885
uses: shivammathur/setup-php@v2
8986
with:
9087
php-version: ${{ inputs.php_version }}
9188
tools: composer:v${{ inputs.composer_version }}
9289
coverage: none
9390

94-
- name: Create composer project
95-
if: steps.changed-files-phpcs.outputs.app_any_changed == 'true'
91+
- name: Install coding standards
92+
if: steps.filter.outputs.phpcs == 'true'
9693
shell: bash
9794
run: |
9895
composer create-project --no-plugins --no-dev \
9996
magento/magento-coding-standard \
10097
magento-coding-standard "${{ github.event.inputs.version || '*' }}"
10198
102-
- name: Register coding standards
103-
if: steps.changed-files-phpcs.outputs.app_any_changed == 'true'
99+
- name: Install phpcs baseline
100+
if: steps.filter.outputs.phpcs == 'true'
104101
working-directory: magento-coding-standard
105102
shell: bash
106103
run: |
107104
composer config --no-plugins allow-plugins.digitalrevolution/php-codesniffer-baseline true
108105
composer require --dev "digitalrevolution/php-codesniffer-baseline: ${{ github.event.inputs.baseline_version || '*' }}"
109106
110-
- name: Checkout base to generate baseline
111-
if: steps.changed-files-phpcs.outputs.app_any_changed == 'true'
107+
- name: Checkout base
108+
if: steps.filter.outputs.phpcs == 'true'
112109
uses: actions/checkout@v4
113110
with:
114111
ref: ${{github.event.pull_request.base.ref}}
@@ -118,35 +115,35 @@ runs:
118115
- name: Create phpcs.baseline.xml from base
119116
shell: bash
120117
working-directory: base
121-
if: steps.changed-files-phpcs.outputs.app_any_changed == 'true'
118+
if: steps.filter.outputs.phpcs == 'true'
122119
run: |
123120
php ${{ github.workspace }}/magento-coding-standard/vendor/bin/phpcs --standard=Magento2 \
124121
$([ -n "${{ inputs.severity }}" ] && echo "--severity=${{ inputs.severity }}") \
125122
$([ -n "${{ inputs.warning_severity }}" ] && echo "--warning-severity=${{ inputs.warning_severity }}") \
126123
$([ -n "${{ inputs.error_severity }}" ] && echo "--error-severity=${{ inputs.error_severity }}") \
127124
--report=\\DR\\CodeSnifferBaseline\\Reports\\Baseline --report-file=phpcs.baseline.xml \
128-
${{ steps.changed-files-phpcs.outputs.app_all_changed_files }} || /bin/true
125+
${{ steps.filter.outputs.phpcs_files }} || /bin/true
129126
130127
- name: Copy baseline to head
131-
if: steps.changed-files-phpcs.outputs.app_any_changed == 'true'
128+
if: steps.filter.outputs.phpcs == 'true'
132129
shell: bash
133130
run: |
134131
cp ${{ github.workspace }}/base/phpcs.baseline.xml ${{ github.workspace }}/magento-coding-standard/phpcs.baseline.xml
135132
136133
# Since we ran phpcs in the base folder, the files in phpcs.baseline.xml contain the base folder in the path.
137134
# We need to remove /base/ so that the phpcs can locate the correct files.
138135
- name: Remove base dir from phpcs baseline
139-
if: steps.changed-files-phpcs.outputs.app_any_changed == 'true'
136+
if: steps.filter.outputs.phpcs == 'true'
140137
shell: bash
141138
run: |
142139
sed -i "s|/base/|/|" ${{ github.workspace }}/magento-coding-standard/phpcs.baseline.xml
143140
144141
- name: Execute phpcs on head for changed files
145142
shell: bash
146-
if: steps.changed-files-phpcs.outputs.app_any_changed == 'true'
147-
run: |
143+
if: steps.filter.outputs.phpcs == 'true'
144+
run: |
148145
php ${{ github.workspace }}/magento-coding-standard/vendor/bin/phpcs --standard=Magento2 \
149146
$([ -n "${{ inputs.severity }}" ] && echo "--severity=${{ inputs.severity }}") \
150147
$([ -n "${{ inputs.warning_severity }}" ] && echo "--warning-severity=${{ inputs.warning_severity }}") \
151148
$([ -n "${{ inputs.error_severity }}" ] && echo "--error-severity=${{ inputs.error_severity }}") \
152-
${{ steps.changed-files-phpcs.outputs.app_all_changed_files }}
149+
${{ steps.filter.outputs.phpcs_files }}

0 commit comments

Comments
 (0)