forked from stdlib-js/stdlib
-
Notifications
You must be signed in to change notification settings - Fork 0
327 lines (275 loc) · 13 KB
/
lint_changed_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
#/
# @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_changed_files
# Workflow triggers:
on:
push:
branches:
- develop
pull_request:
types:
- opened
- synchronize
- reopened
# Global permissions:
permissions:
# Allow read-only access to the repository contents:
contents: read
# Workflow jobs:
jobs:
# Define a job for linting committed code...
process:
# Define a display name:
name: 'Lint Changed Files'
# 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@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
# Specify whether to remove untracked files before checking out the repository:
clean: true
# Limit clone depth to the last 1000 commits:
fetch-depth: 1000
# 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@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1
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
# Get list of changed files:
- name: 'Get list of changed files'
id: changed-files
continue-on-error: true
run: |
if [ -n "${{ github.event.pull_request.number }}" ]; then
# Get the list of changed files in pull request:
ancestor_commit=$(git merge-base ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }})
files=$(git diff --diff-filter=AM --name-only $ancestor_commit ${{ github.event.pull_request.head.sha }})
else
# Get changed files by comparing the current commit to the commit before the push event or with its parent:
if [ "${{ github.event.before }}" == "0000000000000000000000000000000000000000" ]; then
files=$(git diff --diff-filter=AM --name-only HEAD~ ${{ github.event.after }})
else
files=$(git diff --diff-filter=AM --name-only ${{ github.event.before }} ${{ github.event.after }})
fi
fi
files=$(echo "$files" | tr '\n' ' ' | sed 's/ $//')
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.changed-files.outputs.files }}" || "${lint_filenames}"
# Lint Markdown files:
- name: 'Lint Markdown files'
if: success() || failure()
run: |
files=$(echo "${{ steps.changed-files.outputs.files }}" | tr ' ' '\n' | grep -E '\.md$' | tr '\n' ' ' | sed 's/ $//')
if [ -n "${files}" ]; then
make lint-markdown-files FILES="${files}"
fi
# Lint shell script files:
- name: 'Lint shell script files'
if: 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' ' ' | sed 's/ $//')
if [[ -n "${files}" ]]; then
# Install shellcheck:
make install-deps-shellcheck
# Lint shell scripts:
make FILES="${files}" lint-shell-files
fi
# Lint package.json files:
- name: 'Lint package.json files'
if: 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.changed-files.outputs.files }}" | tr ' ' '\n' | grep 'package\.json$' | grep -v 'datapackage\.json$' | tr '\n' ' ' | sed 's/ $//')
if [ -n "${files}" ]; then
echo "Linting package.json files that have changed..."
printf "${files}" | "${lint_package_json}" --split=" "
else
echo "No package.json files to lint."
fi
# Lint REPL help files...
- name: 'Lint REPL help files'
if: 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.changed-files.outputs.files }} | tr ' ' '\n' | grep 'repl\.txt$' | tr '\n' ' ' | sed 's/ $//')
if [ -n "${files}" ]; then
printf "${files}" | "${lint_repl_help}" --split=" "
fi
# Lint JavaScript files:
- name: 'Lint JavaScript files'
if: 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"
# Lint JavaScript source files:
files=$(echo "${{ steps.changed-files.outputs.files }}" | tr ' ' '\n' | grep '\.js$' | grep -v -e '/examples' -e '/test' -e '/benchmark' -e '^dist/' | tr '\n' ' ' | sed 's/ $//')
if [[ -n "${files}" ]]; then
make lint-javascript-files FILES="${files}"
fi
# Lint JavaScript command-line interfaces...
file=$(echo ${{ steps.changed-files.outputs.files }} | tr ' ' '\n' | grep '\.js$' | grep -E '/bin/cli$' | tr '\n' ' ' | sed 's/ $//')
if [[ -n "${file}" ]]; then
make lint-javascript-files FILES="${file}"
fi
# Lint JavaScript example files:
files=$(echo "${{ steps.changed-files.outputs.files }}" | tr ' ' '\n' | grep '/examples/.*\.js$' | tr '\n' ' ' | sed 's/ $//')
if [[ -n "${files}" ]]; then
make lint-javascript-files FILES="${files}" ESLINT_CONF="${eslint_examples_conf}"
fi
# Lint JavaScript test files:
files=$(echo "${{ steps.changed-files.outputs.files }}" | tr ' ' '\n' | grep '/test/.*\.js$' | tr '\n' ' ' | sed 's/ $//')
if [[ -n "${files}" ]]; then
make lint-javascript-files FILES="${files}" ESLINT_CONF="${eslint_tests_conf}"
fi
# Lint JavaScript benchmark files:
files=$(echo "${{ steps.changed-files.outputs.files }}" | tr ' ' '\n' | grep '/benchmark/.*\.js$' | tr '\n' ' ' | sed 's/ $//')
if [[ -n "${files}" ]]; then
make lint-javascript-files FILES="${files}" ESLINT_CONF="${eslint_benchmarks_conf}"
fi
# Lint Python files:
- name: 'Lint Python files'
if: success() || failure()
run: |
files=$(echo "${{ steps.changed-files.outputs.files }}" | tr ' ' '\n' | grep -E '\.py$' | tr '\n' ' ' | sed 's/ $//')
if [[ -n "${files}" ]]; then
# Install Python dependencies:
make install-deps-python
# Lint Python files:
make lint-python-files FILES="${files}"
fi
# Check for R files:
- name: 'Check for R files'
if: success() || failure()
id: check-r-files
run: |
files=$(echo "${{ steps.changed-files.outputs.files }}" | tr ' ' '\n' | grep -E '\.R$' | tr '\n' ' ' | sed 's/ $//')
if [[ -n "${files}" ]]; then
# Add space-separated list of R files to output:
echo "files=${files}" >> $GITHUB_OUTPUT
else
# Add empty string to output:
echo "files=" >> $GITHUB_OUTPUT
fi
# Setup R:
- name: 'Setup R'
if: ( success() || failure() ) && steps.check-r-files.outputs.files != ''
# Pin action to full length commit SHA
uses: r-lib/actions/setup-r@55acd27e7b238c53bbe735b7a459c203a3b3d579 # v2.6.4
with:
r-version: '3.5.3'
# Lint R files:
- name: 'Lint R files'
if: ( success() || failure() ) && steps.check-r-files.outputs.files != ''
run: |
# Install R dependencies:
make install-deps-r
# Lint R files:
make lint-r-files FILES="${{ steps.check-r-files.outputs.files }}"
# Lint C files:
- name: 'Lint C files'
if: success() || failure()
run: |
# Determine root directory:
root=$(git rev-parse --show-toplevel)
# 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"
# Install cppcheck if C files have changed:
files=$(echo "${{ steps.changed-files.outputs.files }}" | tr ' ' '\n' | grep -E '\.c$|\.h$' | tr '\n' ' ' | sed 's/ $//')
if [[ -n "${files}" ]]; then
make install-deps-cppcheck
fi
# Lint C source files...
files=$(echo "${{ steps.changed-files.outputs.files }}" | tr ' ' '\n' | grep -E '\.c$' | grep -v -e '/examples' -e '/test' -e '/benchmark' | tr '\n' ' ' | sed 's/ $//')
if [[ -n "${files}" ]]; then
make lint-c-files FILES="${files}"
fi
# Lint C example files...
files=$(echo "${{ steps.changed-files.outputs.files }}" | tr ' ' '\n' | grep '/examples/.*\.c$' | tr '\n' ' ' | sed 's/ $//')
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.changed-files.outputs.files }}" | tr ' ' '\n' | grep '/test/fixtures/.*\.c$' | tr '\n' ' ' | sed 's/ $//')
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.changed-files.outputs.files }}" | tr ' ' '\n' | grep '/benchmark/.*\.c$' | tr '\n' ' ' | sed 's/ $//')
if [[ -n "${files}" ]]; then
make lint-c-files FILES="${files}" CPPCHECK_SUPPRESSIONS_LIST="${cppcheck_benchmarks_suppressions_list}"
fi
# Lint TypeScript declarations files:
- name: 'Lint TypeScript declarations files'
if: success() || failure()
run: |
files=$(echo "${{ steps.changed-files.outputs.files }}" | tr ' ' '\n' | grep -E '\.d\.ts$' | tr '\n' ' ' | sed 's/ $//')
if [[ -n "${files}" ]]; then
make lint-typescript-declarations-files FILES="${files}"
fi
# Lint license headers:
- name: 'Lint license headers'
if: success() || failure()
run: |
files=$(echo "${{ steps.changed-files.outputs.files }}")
if [[ -n "${files}" ]]; then
make lint-license-headers-files FILES="${files}"
fi