-
Notifications
You must be signed in to change notification settings - Fork 6
213 lines (172 loc) · 7.36 KB
/
reusable-code-quality.yml
File metadata and controls
213 lines (172 loc) · 7.36 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
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@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- 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@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- name: Check existence of composer.json file
id: check_composer_file
run: echo "files_exists=$(test -f composer.json && echo true || echo false)" >> "$GITHUB_OUTPUT"
- name: Set up PHP environment
if: steps.check_composer_file.outputs.files_exists == 'true'
uses: shivammathur/setup-php@7c071dfe9dc99bdf297fa79cb49ea005b9fcadbc # 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@65e4f84970763564f46a70b8a54b90d033b3bdda" # 4.0.0
env:
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
- name: Check existence of vendor/bin/parallel-lint file
id: check_linter_file
run: echo "files_exists=$(test -f vendor/bin/parallel-lint && echo true || echo false)" >> "$GITHUB_OUTPUT"
- 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@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- name: Setup node
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # 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@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- name: Check existence of config file
id: check_files
run: echo "files_exists=$(test -f .typos.toml && echo true || echo false)" >> "$GITHUB_OUTPUT"
- name: Check spelling
if: steps.check_files.outputs.files_exists == 'true'
uses: crate-ci/typos@5374cbf686e897b15713110e233094e2874de7ef # v1.46.1
phpcs:
name: PHPCS
runs-on: ubuntu-latest
steps:
- name: Check out source code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- name: Check existence of composer.json & phpcs.xml.dist files
id: check_files
run: echo "files_exists=$([ -f composer.json ] && [ -f phpcs.xml.dist ] && echo true || echo false)" >> "$GITHUB_OUTPUT"
- name: Set up PHP environment
if: steps.check_files.outputs.files_exists == 'true'
uses: shivammathur/setup-php@7c071dfe9dc99bdf297fa79cb49ea005b9fcadbc # 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@65e4f84970763564f46a70b8a54b90d033b3bdda" # 4.0.0
env:
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
- name: Check existence of vendor/bin/phpcs file
id: check_phpcs_binary_file
run: echo "files_exists=$(test -f vendor/bin/phpcs && echo true || echo false)" >> "$GITHUB_OUTPUT"
- 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@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- name: Check existence of composer.json file
id: check_files
run: echo "files_exists=$(test -f composer.json && echo true || echo false)" >> "$GITHUB_OUTPUT"
- name: Set up PHP environment
if: steps.check_files.outputs.files_exists == 'true'
uses: shivammathur/setup-php@7c071dfe9dc99bdf297fa79cb49ea005b9fcadbc # 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@65e4f84970763564f46a70b8a54b90d033b3bdda" # 4.0.0
env:
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
- name: Check existence of vendor/bin/phpstan file
id: check_phpstan_binary_file
run: echo "files_exists=$(test -f vendor/bin/phpstan && echo true || echo false)" >> "$GITHUB_OUTPUT"
- name: Run PHPStan
if: steps.check_phpstan_binary_file.outputs.files_exists == 'true'
run: composer phpstan