@@ -45,70 +45,67 @@ inputs:
45
45
default : " *"
46
46
description : " The version of phpcs baseline to use (default: latest)."
47
47
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
+
48
58
runs :
49
59
using : composite
50
60
steps :
51
61
- name : Checkout head
52
62
uses : actions/checkout@v4
53
63
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 }}
56
66
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
60
70
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}'
78
75
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'
81
78
shell : bash
82
79
run : |
83
80
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 }}"
85
82
86
83
- name : Setup PHP
87
- if : steps.changed-files-phpcs .outputs.app_any_changed == 'true'
84
+ if : steps.filter .outputs.phpcs == 'true'
88
85
uses : shivammathur/setup-php@v2
89
86
with :
90
87
php-version : ${{ inputs.php_version }}
91
88
tools : composer:v${{ inputs.composer_version }}
92
89
coverage : none
93
90
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'
96
93
shell : bash
97
94
run : |
98
95
composer create-project --no-plugins --no-dev \
99
96
magento/magento-coding-standard \
100
97
magento-coding-standard "${{ github.event.inputs.version || '*' }}"
101
98
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'
104
101
working-directory : magento-coding-standard
105
102
shell : bash
106
103
run : |
107
104
composer config --no-plugins allow-plugins.digitalrevolution/php-codesniffer-baseline true
108
105
composer require --dev "digitalrevolution/php-codesniffer-baseline: ${{ github.event.inputs.baseline_version || '*' }}"
109
106
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'
112
109
uses : actions/checkout@v4
113
110
with :
114
111
ref : ${{github.event.pull_request.base.ref}}
@@ -118,35 +115,35 @@ runs:
118
115
- name : Create phpcs.baseline.xml from base
119
116
shell : bash
120
117
working-directory : base
121
- if : steps.changed-files-phpcs .outputs.app_any_changed == 'true'
118
+ if : steps.filter .outputs.phpcs == 'true'
122
119
run : |
123
120
php ${{ github.workspace }}/magento-coding-standard/vendor/bin/phpcs --standard=Magento2 \
124
121
$([ -n "${{ inputs.severity }}" ] && echo "--severity=${{ inputs.severity }}") \
125
122
$([ -n "${{ inputs.warning_severity }}" ] && echo "--warning-severity=${{ inputs.warning_severity }}") \
126
123
$([ -n "${{ inputs.error_severity }}" ] && echo "--error-severity=${{ inputs.error_severity }}") \
127
124
--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
129
126
130
127
- name : Copy baseline to head
131
- if : steps.changed-files-phpcs .outputs.app_any_changed == 'true'
128
+ if : steps.filter .outputs.phpcs == 'true'
132
129
shell : bash
133
130
run : |
134
131
cp ${{ github.workspace }}/base/phpcs.baseline.xml ${{ github.workspace }}/magento-coding-standard/phpcs.baseline.xml
135
132
136
133
# Since we ran phpcs in the base folder, the files in phpcs.baseline.xml contain the base folder in the path.
137
134
# We need to remove /base/ so that the phpcs can locate the correct files.
138
135
- 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'
140
137
shell : bash
141
138
run : |
142
139
sed -i "s|/base/|/|" ${{ github.workspace }}/magento-coding-standard/phpcs.baseline.xml
143
140
144
141
- name : Execute phpcs on head for changed files
145
142
shell : bash
146
- if : steps.changed-files-phpcs .outputs.app_any_changed == 'true'
147
- run : |
143
+ if : steps.filter .outputs.phpcs == 'true'
144
+ run : |
148
145
php ${{ github.workspace }}/magento-coding-standard/vendor/bin/phpcs --standard=Magento2 \
149
146
$([ -n "${{ inputs.severity }}" ] && echo "--severity=${{ inputs.severity }}") \
150
147
$([ -n "${{ inputs.warning_severity }}" ] && echo "--warning-severity=${{ inputs.warning_severity }}") \
151
148
$([ -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