-
Notifications
You must be signed in to change notification settings - Fork 6
223 lines (183 loc) · 7.69 KB
/
reusable-code-quality.yml
File metadata and controls
223 lines (183 loc) · 7.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
name: Code Quality Checks
on:
workflow_call:
inputs:
parallel-lint-excludes:
description: 'Additional folders for parallel-lint to exclude, separated by newline'
type: string
required: false
default: ''
permissions:
contents: read
# Cancels all previous workflow runs for the same branch that have not yet completed.
concurrency:
# The concurrency group contains the workflow name and the branch name.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
actionlint:
name: Lint GitHub Actions workflows
runs-on: ubuntu-latest
steps:
- name: Check out source code
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
- name: Add problem matcher
run: |
curl -s -o .github/actionlint-matcher.json https://raw.githubusercontent.com/rhysd/actionlint/main/.github/actionlint-matcher.json
echo "::add-matcher::.github/actionlint-matcher.json"
- name: Check workflow files
uses: docker://rhysd/actionlint:latest
with:
args: -color -shellcheck=
lint:
name: Lint PHP files
runs-on: ubuntu-latest
steps:
- name: Check out source code
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
- name: Check existence of composer.json file
id: check_composer_file
uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 # v3
with:
files: "composer.json"
- name: Set up PHP environment
if: steps.check_composer_file.outputs.files_exists == 'true'
uses: shivammathur/setup-php@44454db4f0199b8b9685a5d763dc37cbf79108e1 # v2
with:
php-version: 'latest'
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
tools: cs2pr
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Install Composer dependencies & cache dependencies
if: steps.check_composer_file.outputs.files_exists == 'true'
uses: "ramsey/composer-install@3cf229dc2919194e9e36783941438d17239e8520" # v3
env:
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
with:
# Bust the cache at least once a month - output format: YYYY-MM.
custom-cache-suffix: $(date -u "+%Y-%m")
- name: Check existence of vendor/bin/parallel-lint file
id: check_linter_file
uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 # v3
with:
files: "vendor/bin/parallel-lint"
- name: Run Linter
if: steps.check_linter_file.outputs.files_exists == 'true'
run: |
EXCLUDES=("--exclude vendor" "--exclude .git")
ADDITIONAL_EXCLUDES=${ADDITIONAL_EXCLUDES%$'\n'}
IFS=$'\n';
ADDITIONAL_EXCLUDES=($ADDITIONAL_EXCLUDES)
for i in "${ADDITIONAL_EXCLUDES[@]}"; do
if [ ! -z "$i" ]; then
EXCLUDES+=("--exclude $i")
fi
done
unset IFS;
echo "Providing excludes: ${EXCLUDES[*]}"
vendor/bin/parallel-lint -j 10 . --show-deprecated ${EXCLUDES[@]} --checkstyle | cs2pr
env:
ADDITIONAL_EXCLUDES: ${{ inputs.parallel-lint-excludes }}
lint-gherkin:
name: Lint Gherkin Feature files
runs-on: ubuntu-latest
steps:
- name: Check out source code
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
- name: Setup node
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6
- name: Download lint rules
run: curl https://raw.githubusercontent.com/wp-cli/.github/refs/heads/main/.gherkin-lintrc -o $RUNNER_TEMP/.gherkin-lintrc
- name: Run linter
run: npx --yes gherkin-lint -c $RUNNER_TEMP/.gherkin-lintrc
lint-spellcheck:
name: Spell check
runs-on: ubuntu-latest
steps:
- name: Check out source code
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
- name: Check existence of config file
id: check_files
uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 # v3
with:
files: ".typos.toml"
- name: Check spelling
if: steps.check_files.outputs.files_exists == 'true'
uses: crate-ci/typos@65120634e79d8374d1aa2f27e54baa0c364fff5a # v1.42.1
phpcs:
name: PHPCS
runs-on: ubuntu-latest
steps:
- name: Check out source code
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
- name: Check existence of composer.json & phpcs.xml.dist files
id: check_files
uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 # v3
with:
files: "composer.json, phpcs.xml.dist"
- name: Set up PHP environment
if: steps.check_files.outputs.files_exists == 'true'
uses: shivammathur/setup-php@44454db4f0199b8b9685a5d763dc37cbf79108e1 # v2
with:
php-version: 'latest'
tools: cs2pr
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Install Composer dependencies & cache dependencies
if: steps.check_files.outputs.files_exists == 'true'
uses: "ramsey/composer-install@3cf229dc2919194e9e36783941438d17239e8520" # v3
env:
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
with:
# Bust the cache at least once a month - output format: YYYY-MM.
custom-cache-suffix: $(date -u "+%Y-%m")
- name: Check existence of vendor/bin/phpcs file
id: check_phpcs_binary_file
uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 # v3
with:
files: "vendor/bin/phpcs"
- name: Run PHPCS
if: steps.check_phpcs_binary_file.outputs.files_exists == 'true'
run: vendor/bin/phpcs -q --report=full --report-checkstyle=/tmp/phpcs-checkstyle-report.xml
- name: Convert PHPCS report to PR comments
if: always()
run: |
if [ -f /tmp/phpcs-checkstyle-report.xml ]; then
cs2pr /tmp/phpcs-checkstyle-report.xml
fi
phpstan:
name: PHPStan
runs-on: ubuntu-latest
steps:
- name: Check out source code
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
- name: Check existence of composer.json & phpcs.xml.dist files
id: check_files
uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 # v3
with:
files: "composer.json"
- name: Set up PHP environment
if: steps.check_files.outputs.files_exists == 'true'
uses: shivammathur/setup-php@44454db4f0199b8b9685a5d763dc37cbf79108e1 # v2
with:
php-version: 'latest'
tools: cs2pr
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Install Composer dependencies & cache dependencies
if: steps.check_files.outputs.files_exists == 'true'
uses: "ramsey/composer-install@3cf229dc2919194e9e36783941438d17239e8520" # v3
env:
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
with:
# Bust the cache at least once a month - output format: YYYY-MM.
custom-cache-suffix: $(date -u "+%Y-%m")
- name: Check existence of vendor/bin/phpstan file
id: check_phpstan_binary_file
uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 # v3
with:
files: "vendor/bin/phpstan"
- name: Run PHPStan
if: steps.check_phpstan_binary_file.outputs.files_exists == 'true'
run: composer phpstan