forked from stdlib-js/stdlib
-
Notifications
You must be signed in to change notification settings - Fork 0
485 lines (415 loc) · 18.3 KB
/
lint_random_files.yml
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
#/
# @license Apache-2.0
#
# Copyright (c) 2022 The Stdlib Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#/
# Workflow name:
name: lint_random_files
# Workflow triggers:
on:
# Allow the workflow to be manually run:
workflow_dispatch:
inputs:
num:
type: string
description: 'Maximum number of files to lint:'
default: '100'
pattern:
description: 'Regular expression for files to include:'
default: .*
javascript:
type: boolean
description: 'Lint JavaScript and TypeScript'
default: true
markdown:
type: boolean
description: 'Lint Markdown'
default: true
json:
type: boolean
description: 'Lint JSON'
default: true
repl:
type: boolean
description: 'Lint REPL documentation and shell script files'
default: true
r:
type: boolean
description: 'Lint R'
default: true
c:
type: boolean
description: 'Lint C'
default: true
python:
type: boolean
description: 'Lint Python'
default: true
fix:
type: boolean
description: 'Fix lint errors and submit a PR (if possible)'
default: false
# Trigger the workflow every 24 hours:
schedule:
- cron: '0 0 * * *'
# Global permissions:
permissions:
# Allow read-only access to the repository contents:
contents: read
# Workflow jobs:
jobs:
# Define a job for linting committed code...
lint:
# Define a display name:
name: 'Lint Random Files'
# Ensure the job does not run on forks:
if: github.repository == 'stdlib-js/stdlib'
# Define the type of virtual host machine:
runs-on: ubuntu-latest
# Define the sequence of job steps...
steps:
# Checkout the repository:
- name: 'Checkout repository'
# Pin action to full length commit SHA
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
# Specify whether to remove untracked files before checking out the repository:
clean: true
# Limit clone depth to the most recent commit:
fetch-depth: 1
# Specify whether to download Git-LFS files:
lfs: false
timeout-minutes: 10
# Install Node.js:
- name: 'Install Node.js'
# Pin action to full length commit SHA
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: '20' # 'lts/*'
timeout-minutes: 5
# Install dependencies (accounting for possible network failures, etc, when installing node module dependencies):
- name: 'Install dependencies'
run: |
make install-node-modules || make install-node-modules || make install-node-modules
timeout-minutes: 15
# Initialize development environment:
- name: 'Initialize development environment'
run: |
make init
timeout-minutes: 5
# Pick random files from the `lib/node_modules/@stdlib` directory:
- name: 'Pick random files from the `lib/node_modules/@stdlib` directory'
id: random-files
run: |
name=""
if [ "${{ github.event.inputs.javascript }}" != "false" ]; then
name="${name} -name '*.js'"
fi
if [ "${{ github.event.inputs.markdown }}" != "false" ]; then
if [ -n "${name}" ]; then
name="${name} -o"
fi
name="${name} -name '*.md'"
fi
if [ "${{ github.event.inputs.json }}" != "false" ]; then
if [ -n "${name}" ]; then
name="${name} -o"
fi
name="${name} -name '*.json'"
fi
if [ "${{ github.event.inputs.repl }}" != "false" ]; then
if [ -n "${name}" ]; then
name="${name} -o"
fi
name="${name} -name '*.repl\.txt' -o -name '*.sh'"
fi
if [ "${{ github.event.inputs.r }}" != "false" ]; then
if [ -n "${name}" ]; then
name="${name} -o"
fi
name="${name} -name '*.R'"
fi
if [ "${{ github.event.inputs.c }}" != "false" ]; then
if [ -n "${name}" ]; then
name="${name} -o"
fi
name="${name} -name '*.c'"
fi
if [ "${{ github.event.inputs.javascript }}" != "false" ]; then
if [ -n "${name}" ]; then
name="${name} -o"
fi
name="${name} -name '*.ts'"
fi
if [ "${{ github.event.inputs.python }}" != "false" ]; then
if [ -n "${name}" ]; then
name="${name} -o"
fi
name="${name} -name '*.py'"
fi
command="find lib/node_modules/@stdlib -type f \( ${name} \) |
grep -E '${{ github.event.inputs.pattern }}' |
grep -v '/fixtures/bad/' |
shuf -n ${{ github.event.inputs.num || 100 }} | tr '\n' ','"
files=$(eval ${command})
echo "files=$files" >> $GITHUB_OUTPUT
# Lint file names:
- name: 'Lint file names'
run: |
# Determine root directory:
root=$(git rev-parse --show-toplevel)
# Define the path to a utility for linting filenames:
lint_filenames="${root}/lib/node_modules/@stdlib/_tools/lint/filenames/bin/cli"
# Lint filenames:
echo "${{ steps.random-files.outputs.files }}" | tr ',' '\n' | "${lint_filenames}"
# Lint files against EditorConfig:
- name: 'Lint against EditorConfig'
run: |
files=$(echo "${{ steps.random-files.outputs.files }}" | tr ',' ' ')
make lint-editorconfig-files FILES="${files}"
# Lint Markdown files:
- name: 'Lint Markdown files'
if: ( github.event.inputs.markdown != 'false' ) && ( success() || failure() )
run: |
files=$(echo "${{ steps.random-files.outputs.files }}" | tr ',' '\n' | grep -E '\.md$' | tr '\n' ' ')
if [ -n "${files}" ]; then
make lint-markdown-files FAST_FAIL=0 FILES="${files}"
fi
# Lint package.json files:
- name: 'Lint package.json files'
if: ( github.event.inputs.json != 'false' ) && ( success() || failure() )
run: |
# Determine root directory:
root=$(git rev-parse --show-toplevel)
# Define the path to a utility for linting package.json files:
lint_package_json="${root}/lib/node_modules/@stdlib/_tools/lint/pkg-json/bin/cli"
files=$(echo "${{ steps.random-files.outputs.files }}" | tr ',' '\n' | grep 'package\.json$' | grep -v 'datapackage\.json$' | tr '\n' ' ' | sed 's/ $//')
if [ -n "${files}" ]; then
printf "${files}" | "${lint_package_json}" --split=" "
fi
# Lint REPL help files...
- name: 'Lint REPL help files'
if: ( github.event.inputs.repl != 'false' ) && ( success() || failure() )
run: |
# Determine root directory:
root=$(git rev-parse --show-toplevel)
# Define the path to a utility for linting REPL help files:
lint_repl_help="${root}/lib/node_modules/@stdlib/_tools/lint/repl-txt/bin/cli"
files=$(echo "${{ steps.random-files.outputs.files }}" | tr ',' '\n' | grep 'repl\.txt$' | tr '\n' ' ' | sed 's/ $//')
if [ -n "${files}" ]; then
printf "${files}" | "${lint_repl_help}" --split=" "
fi
# Lint shell script files:
- name: 'Lint shell script files'
if: ( github.event.inputs.repl != 'false' ) && ( success() || failure() )
run: |
files=$(echo "${{ steps.random-files.outputs.files }}" | tr ',' '\n' | grep -vE '\.(js|md|json|ts|c|h)$' | while read -r file; do head -n1 "$file" | grep -q '^\#\!/usr/bin/env bash' && echo "$file"; done | tr '\n' ' ')
if [[ -n "${files}" ]]; then
# Install shellcheck:
make install-deps-shellcheck
# Lint shell scripts:
make FILES="${files}" lint-shell-files
fi
# Lint JavaScript files:
- name: 'Lint JavaScript files'
if: ( github.event.inputs.javascript != 'false' ) && ( success() || failure() )
run: |
# Determine root directory:
root=$(git rev-parse --show-toplevel)
# Define the path to ESLint configuration file for linting examples:
eslint_examples_conf="${root}/etc/eslint/.eslintrc.examples.js"
# Define the path to ESLint configuration file for linting tests:
eslint_tests_conf="${root}/etc/eslint/.eslintrc.tests.js"
# Define the path to ESLint configuration file for linting benchmarks:
eslint_benchmarks_conf="${root}/etc/eslint/.eslintrc.benchmarks.js"
# Set `FIX` variable to `1` to enable automatic fixing of lint errors, `0` to disable:
if [ "${{ github.event.inputs.fix }}" == "true" ]; then
FIX=1
else
FIX=0
fi
# Lint JavaScript source files:
files=$(echo "${{ steps.random-files.outputs.files }}" | tr ',' '\n' | grep '\.js$' | grep -v -e '/examples' -e '/test' -e '/benchmark' -e '^dist/' | tr '\n' ' ')
# Build native addons if present:
packages=$(echo "${files}" | tr ' ' '\n' | sed 's/^lib\/node_modules\///g' | sed 's/\/lib\/.*//g' | sort | uniq)
for pkg in ${packages}; do
if [ -f "lib/node_modules/${pkg}/binding.gyp" ]; then
NODE_ADDONS_PATTERN="${pkg}" make install-node-addons
fi
done
if [[ -n "${files}" ]]; then
make lint-javascript-files FIX="${FIX}" FAST_FAIL=0 FILES="${files}"
fi
# Lint JavaScript command-line interfaces...
file=$(echo "${{ steps.random-files.outputs.files }}" | tr ',' '\n' | grep '\.js$' | grep -E '/bin/cli$' | tr '\n' ' ')
if [[ -n "${file}" ]]; then
make lint-javascript-files FIX="${FIX}" FAST_FAIL=0 FILES="${file}"
fi
# Lint JavaScript example files:
files=$(echo "${{ steps.random-files.outputs.files }}" | tr ',' '\n' | grep '/examples/.*\.js$' | tr '\n' ' ')
if [[ -n "${files}" ]]; then
make lint-javascript-files FIX="${FIX}" FAST_FAIL=0 FILES="${files}" ESLINT_CONF="${eslint_examples_conf}"
fi
# Lint JavaScript test files:
files=$(echo "${{ steps.random-files.outputs.files }}" | tr ',' '\n' | grep '/test/.*\.js$' | tr '\n' ' ')
if [[ -n "${files}" ]]; then
make lint-javascript-files FIX="${FIX}" FAST_FAIL=0 FILES="${files}" ESLINT_CONF="${eslint_tests_conf}"
fi
# Lint JavaScript benchmark files:
files=$(echo "${{ steps.random-files.outputs.files }}" | tr ',' '\n' | grep '/benchmark/.*\.js$' | tr '\n' ' ')
if [[ -n "${files}" ]]; then
make lint-javascript-files FIX="${FIX}" FAST_FAIL=0 FILES="${files}" ESLINT_CONF="${eslint_benchmarks_conf}"
fi
# Lint Python files:
- name: 'Lint Python files'
if: ( github.event.inputs.python != 'false' ) && ( success() || failure() )
run: |
files=$(echo "${{ steps.random-files.outputs.files }}" | tr ',' '\n' | grep -E '\.py$' | tr '\n' ' ')
if [[ -n "${files}" ]]; then
# Install Python dependencies:
make install-deps-python
# Lint Python files:
make lint-python-files FAST_FAIL=0 FILES="${files}"
fi
# Setup R:
- name: 'Setup R'
if: ( github.event.inputs.r != 'false' ) && ( success() || failure() )
# Pin action to full length commit SHA
uses: r-lib/actions/setup-r@473c68190595b311a74f208fba61a8d8c0d4c247 # v2.11.1
with:
r-version: '4.3.3'
# Lint R files:
- name: 'Lint R files'
if: ( github.event.inputs.r != 'false' ) && ( success() || failure() )
run: |
files=$(echo "${{ steps.random-files.outputs.files }}" | tr ',' '\n' | grep -E '\.R$' | tr '\n' ' ')
if [[ -n "${files}" ]]; then
# Install R dependencies:
make install-deps-r
# Lint R files:
make lint-r-files FAST_FAIL=0 FILES="${files}"
fi
# Lint C files:
- name: 'Lint C files'
id: lint-c
if: ( github.event.inputs.c != 'false' ) && ( success() || failure() )
run: |
# Determine root directory:
root=$(git rev-parse --show-toplevel)
# Install Cppcheck:
make install-deps-cppcheck
# Define the path to cppcheck configuration file for linting examples:
cppcheck_examples_suppressions_list="${root}/etc/cppcheck/suppressions.examples.txt"
# Define the path to cppcheck configuration file for linting test fixtures:
cppcheck_tests_fixtures_suppressions_list="${root}/etc/cppcheck/suppressions.tests_fixtures.txt"
# Define the path to cppcheck configuration file for linting benchmarks:
cppcheck_benchmarks_suppressions_list="${root}/etc/cppcheck/suppressions.benchmarks.txt"
# Lint C source files...
files=$(echo "${{ steps.random-files.outputs.files }}" | tr ',' '\n' | grep -E '\.c$' | grep -v -e '/examples' -e '/test' -e '/benchmark' | tr '\n' ' ')
if [[ -n "${files}" ]]; then
make lint-c-files FILES="${files}"
fi
# Lint C example files...
files=$(echo "${{ steps.random-files.outputs.files }}" | tr ',' '\n' | grep '/examples/.*\.c$' | tr '\n' ' ')
if [[ -n "${files}" ]]; then
make lint-c-files FILES="${files}" CPPCHECK_SUPPRESSIONS_LIST="${cppcheck_examples_suppressions_list}"
fi
# Lint C test fixtures files...
files=$(echo "${{ steps.random-files.outputs.files }}" | tr ',' '\n' | grep '/test/fixtures/.*\.c$' | tr '\n' ' ')
if [[ -n "${files}" ]]; then
make lint-c-files FILES="${files}" CPPCHECK_SUPPRESSIONS_LIST="${cppcheck_tests_fixtures_suppressions_list}"
fi
# Lint C benchmark files...
files=$(echo "${{ steps.random-files.outputs.files }}" | tr ',' '\n' | grep '/benchmark/.*\.c$' | tr '\n' ' ')
if [[ -n "${files}" ]]; then
make lint-c-files FILES="${files}" CPPCHECK_SUPPRESSIONS_LIST="${cppcheck_benchmarks_suppressions_list}"
fi
# Create sub-issue for C linting failures:
- name: 'Create sub-issue for C lint failures'
if: ( github.event.inputs.c != 'false' ) && failure() && contains(steps.*.outcome, 'failure') && contains(steps.lint-c.outcome, 'failure')
env:
GITHUB_TOKEN: ${{ secrets.STDLIB_BOT_GITHUB_TOKEN }}
run: |
BODY_FILE="$GITHUB_WORKSPACE/lint_issue_body.md"
cat << EOF > "$BODY_FILE"
## C Linting Failures
Linting failures were detected in the automated lint workflow run.
### Workflow Details
- Run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
- Type: C Linting
- Date: $(date -u +"%Y-%m-%d %H:%M:%S UTC")
### Error Details
\`\`\`
$(grep -B 1 -A 2 "style:\|warning:\|error:" <<< "${{ steps.lint-c.outputs.stderr }}")
\`\`\`
EOF
. "$GITHUB_WORKSPACE/.github/workflows/scripts/create_sub_issue" \
'Fix C lint errors' \
"$BODY_FILE" \
"3235" # Number of C lint error tracking issue
rm "$BODY_FILE"
# Lint TypeScript declarations files:
- name: 'Lint TypeScript declarations files'
if: ( github.event.inputs.javascript != 'false' ) && ( success() || failure() )
run: |
files=$(echo "${{ steps.random-files.outputs.files }}" | tr ',' '\n' | grep -E '\.d\.ts$' | tr '\n' ' ')
if [[ -n "${files}" ]]; then
make TYPESCRIPT_DECLARATIONS_LINTER=eslint lint-typescript-declarations-files FAST_FAIL=0 FILES="${files}"
fi
# Lint license headers:
- name: 'Lint license headers'
if: success() || failure()
run: |
files=$(echo "${{ steps.random-files.outputs.files }}" | tr ',' ' ')
if [[ -n "${files}" ]]; then
make lint-license-headers-files FILES="${files}"
fi
# Disable Git hooks:
- name: 'Disable Git hooks'
if: ${{ github.event.inputs.fix == 'true' }} && ( success() || failure() )
run: |
rm -rf .git/hooks
# Import GPG key to sign commits:
- name: 'Import GPG key to sign commits'
if: ${{ github.event.inputs.fix == 'true' }} && ( success() || failure() )
# Pin action to full length commit SHA
uses: crazy-max/ghaction-import-gpg@cb9bde2e2525e640591a934b1fd28eef1dcaf5e5 # v6.2.0
with:
gpg_private_key: ${{ secrets.STDLIB_BOT_GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.STDLIB_BOT_GPG_PASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true
# Create a pull request with the fixes (if applicable):
- name: 'Create pull request'
if: ${{ github.event.inputs.fix == 'true' }} && ( success() || failure() )
id: cpr
# Pin action to full length commit SHA
uses: peter-evans/create-pull-request@67ccf781d68cd99b580ae25a5c18a1cc84ffff1f # v7.0.6
with:
title: 'style: fix lint errors'
add-paths: ${{ steps.random-files.outputs.files }}
body: |
This PR
- fixes lint errors
commit-message: 'style: resolve lint errors'
committer: 'stdlib-bot <[email protected]>'
signoff: true
token: ${{ secrets.PULL_REQUEST_TOKEN }}
labels: |
automated-pr
team-reviewers: |
reviewers
branch: 'fix-lint-errors'
delete-branch: true