-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathTaskfile.yml
391 lines (350 loc) · 13.9 KB
/
Taskfile.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
version: "3"
includes:
dist: ./DistTasks.yml
tasks:
build:
desc: Build the project
cmds:
- go build -v {{.LDFLAGS}}
test:
desc: Run tests
cmds:
- task: go:test-unit
- task: test-integration
go:generate:
desc: Generate Go code
cmds:
- go get -u "github.com/go-bindata/go-bindata/[email protected]"
- go-bindata -nocompress -nometadata -o "./internal/rule/schema/schemadata/bindata.go" --pkg schemadata --prefix "./etc/schemas/" "./etc/schemas/"
- go-bindata -nocompress -nometadata -o "./internal/rule/schema/testdata/bindata.go" --pkg testdata --prefix "./internal/rule/schema/testdata/input/" "./internal/rule/schema/testdata/input/"
- go get -u golang.org/x/tools/cmd/[email protected]
- go generate ./...
- task: go:format
go:test-unit:
desc: Run unit tests
cmds:
- go test -short -run '{{ default ".*" .TEST_REGEX }}' {{ default "-v" .GOFLAGS }} -coverprofile=coverage_unit.txt {{ default .DEFAULT_GO_PACKAGES .GO_PACKAGES }}
test-integration:
desc: Run integration tests
cmds:
- task: build
- poetry install --no-root
- poetry run pytest test
check:
desc: Lint and check formatting of all files
cmds:
- task: go:check
- task: python:check
- task: docs:check
- task: config:check
- task: general:check-formatting
- task: check-spelling
- task: shell:check-mode
lint:
desc: Lint all files
cmds:
- task: go:vet
- task: go:lint
- task: python:lint
- task: docs:lint
- task: config:lint
check-formatting:
desc: Check formatting of all files
cmds:
- task: general:check-formatting
format:
desc: Format all files
cmds:
- task: go:format
- task: python:format
- task: general:format-prettier
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
go:check:
desc: Check for problems with Go code
deps:
- task: go:vet
- task: go:lint
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
go:vet:
desc: Check for errors in Go code
cmds:
- go vet {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
go:fix:
desc: Modernize usages of outdated APIs
cmds:
- go fix {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
go:lint:
desc: Lint Go code
cmds:
- |
PROJECT_PATH="$PWD"
# `go get` and `go list` commands must be run from a temporary folder to avoid polluting go.mod
cd "$(mktemp -d "${TMPDIR-${TMP-/tmp}}/task-temporary-XXXXX")"
go get golang.org/x/lint/golint
GOLINT_PATH="$(go list -f '{{"{{"}}.Target{{"}}"}}' golang.org/x/lint/golint || echo "false")"
# `golint` must be run from the module folder
cd "$PROJECT_PATH"
"$GOLINT_PATH" \
{{default "-min_confidence 0.8 -set_exit_status" .GO_LINT_FLAGS}} \
{{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
go:format:
desc: Format Go code
cmds:
- go fmt {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown-task/Taskfile.yml
markdown:lint:
desc: Check for problems in Markdown files
cmds:
- npx markdownlint-cli "**/*.md"
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown-task/Taskfile.yml
markdown:fix:
desc: Automatically correct linting violations in Markdown files where possible
cmds:
- npx markdownlint-cli --fix "**/*.md"
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown-task/Taskfile.yml
markdown:check-links:
desc: Check for broken links
deps:
- task: docs:generate
cmds:
- |
if [[ "{{.OS}}" == "Windows_NT" ]]; then
# npx --call uses the native shell, which makes it too difficult to use npx for this application on Windows,
# so the Windows user is required to have markdown-link-check installed and in PATH.
if ! which markdown-link-check &>/dev/null; then
echo "markdown-link-check not found or not in PATH. Please install: https://github.com/tcort/markdown-link-check#readme"
exit 1
fi
# Default behavior of the task on Windows is to exit the task when the first broken link causes a non-zero
# exit status, but it's better to check all links before exiting.
set +o errexit
STATUS=0
# Using -regex instead of -name to avoid Task's behavior of globbing even when quoted on Windows
# The odd method for escaping . in the regex is required for windows compatibility because mvdan.cc/sh gives
# \ characters special treatment on Windows in an attempt to support them as path separators.
for file in $(find . -regex ".*[.]md"); do
markdown-link-check \
--quiet \
--config "./.markdown-link-check.json" \
"$file"
STATUS=$(( $STATUS + $? ))
done
exit $STATUS
else
npx --package=markdown-link-check --call='
STATUS=0
for file in $(find . -regex ".*[.]md"); do
markdown-link-check \
--quiet \
--config "./.markdown-link-check.json" \
"$file"
STATUS=$(( $STATUS + $? ))
done
exit $STATUS
'
fi
python:check:
cmds:
- task: python:lint
python:lint:
desc: Lint Python code
cmds:
- poetry install --no-root
- poetry run flake8
python:format:
desc: Automatically formats Python files
cmds:
- poetry install --no-root
- poetry run black .
docs:generate:
desc: Create all generated documentation content
deps:
- task: docs:gen
docs:gen:
desc: Generate command reference
dir: ./docsgen
cmds:
# docs will generate examples using os.Args[0] so we need to call
# the generator `arduino-lint`
- go build -o arduino-lint{{exeExt}}
# we invoke `arduino-lint` like this instead of `./arduino-lint` to remove
# the `./` chars from the examples
- PATH=. arduino-lint ../docs/commands
- task: general:format-prettier
docs:build:
desc: Build documentation website contents
cmds:
- task: docs:gen
- poetry install --no-root
- poetry run mkdocs build --strict
docs:publish:
desc: Use Mike to build and push versioned docs
cmds:
- task: docs:gen
- poetry run mike deploy --update-aliases --push --remote {{.DOCS_REMOTE}} {{.DOCS_VERSION}} {{.DOCS_ALIAS}}
docs:serve:
desc: Run documentation website locally
cmds:
- task: docs:build
- poetry run mkdocs serve
docs:check:
desc: Lint and check formatting of documentation files
cmds:
- task: markdown:lint
- task: markdown:fix
- task: markdown:check-links
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-shell-task/Taskfile.yml
shell:check:
desc: Check for problems with shell scripts
cmds:
- |
if ! which shellcheck &>/dev/null; then
echo "shellcheck not installed or not in PATH. Please install: https://github.com/koalaman/shellcheck#installing"
exit 1
fi
- |
# There is something odd about shellcheck that causes the task to always exit on the first fail, despite any
# measures that would prevent this with any other command. So it's necessary to call shellcheck only once with
# the list of script paths as an argument. This could lead to exceeding the maximum command length on Windows if
# the repository contained a large number of scripts, but it's unlikely to happen in reality.
shellcheck \
--format={{default "tty" .SHELLCHECK_FORMAT}} \
$(
# The odd method for escaping . in the regex is required for windows compatibility because mvdan.cc/sh gives
# \ characters special treatment on Windows in an attempt to support them as path separators.
find . \
-path ".git" -prune -or \
\( \
-regextype posix-extended \
-regex '.*[.](bash|sh)' -and \
-type f \
\)
)
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-shell-task/Taskfile.yml
shell:format:
desc: Format shell script files
cmds:
- |
if ! which shfmt &>/dev/null; then
echo "shfmt not installed or not in PATH. Please install: https://github.com/mvdan/sh#shfmt"
exit 1
fi
- shfmt -w .
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-shell-task/Taskfile.yml
shell:check-mode:
desc: Check for non-executable shell scripts
cmds:
- |
EXIT_STATUS=0
while read -r nonExecutableScriptPath; do
# The while loop always runs once, even if no file was found
if [[ "$nonExecutableScriptPath" == "" ]]; then
continue
fi
echo "::error file=${nonExecutableScriptPath}::non-executable script file: $nonExecutableScriptPath";
EXIT_STATUS=1
done <<<"$(
# The odd approach to escaping `.` in the regex is required for windows compatibility because mvdan.cc/sh
# gives `\` characters special treatment on Windows in an attempt to support them as path separators.
find . \
-path ".git" -prune -or \
\( \
-regextype posix-extended \
-regex '.*[.](bash|sh)' -and \
-type f -and \
-not -executable \
-print \
\)
)"
exit $EXIT_STATUS
config:check:
desc: Lint and check formatting of configuration files
cmds:
- task: config:lint
config:lint:
desc: Lint configuration files
cmds:
- task: workflow:validate
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-workflows-task/Taskfile.yml
ci:validate:
desc: Validate GitHub Actions workflows against their JSON schema
vars:
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/github-workflow.json
WORKFLOW_SCHEMA_URL: https://json.schemastore.org/github-workflow
WORKFLOW_SCHEMA_PATH:
sh: mktemp -t workflow-schema-XXXXXXXXXX.json
WORKFLOWS_DATA_PATH: "./.github/workflows/*.{yml,yaml}"
cmds:
- |
wget \
--quiet \
--output-document="{{.WORKFLOW_SCHEMA_PATH}}" \
{{.WORKFLOW_SCHEMA_URL}}
- |
npx \
--package=ajv-cli \
--package=ajv-formats \
ajv validate \
--all-errors \
--strict=false \
-c ajv-formats \
-s "{{.WORKFLOW_SCHEMA_PATH}}" \
-d "{{.WORKFLOWS_DATA_PATH}}"
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-general-formatting-task/Taskfile.yml
general:check-formatting:
desc: Check basic formatting style of all files
cmds:
- |
if ! which ec &>/dev/null; then
echo "ec not found or not in PATH. Please install: https://github.com/editorconfig-checker/editorconfig-checker#installation"
exit 1
fi
- ec
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-prettier-formatting-task/Taskfile.yml
general:format-prettier:
desc: Format all supported files with Prettier
cmds:
- npx prettier --write .
check-spelling:
desc: Check for commonly misspelled words
cmds:
- poetry install --no-root
- poetry run codespell {{ .CODESPELL_SKIP_OPTION }} {{ .CODESPELL_IGNORE_WORDS_OPTION }}
correct-spelling:
desc: Correct commonly misspelled words where possible
cmds:
- poetry install --no-root
- poetry run codespell --write-changes {{ .CODESPELL_SKIP_OPTION }} {{ .CODESPELL_IGNORE_WORDS_OPTION }}
vars:
PROJECT_NAME: "arduino-lint"
DIST_DIR: "dist"
DEFAULT_GO_PACKAGES:
sh: echo `go list ./... | grep --invert-match 'github.com/arduino/arduino-lint/internal/rule/schema/schemadata' | tr '\n' ' '`
# build vars
COMMIT:
sh: echo "$(git log -n 1 --format=%h)"
TIMESTAMP:
sh: echo "$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
TIMESTAMP_SHORT:
sh: echo "{{now | date "20060102"}}"
TAG:
sh: echo "`git tag --points-at=HEAD 2> /dev/null`"
VERSION: "{{ if .NIGHTLY }}nightly-{{ .TIMESTAMP_SHORT }}{{ else if .TAG }}{{ .TAG }}{{ else }}snapshot{{ end }}"
CONFIGURATION_PACKAGE: "github.com/arduino/{{ .PROJECT_NAME }}/internal/configuration"
LDFLAGS: >-
-ldflags
'
-X {{ .CONFIGURATION_PACKAGE }}.version={{.VERSION}}
-X {{ .CONFIGURATION_PACKAGE }}.commit={{.COMMIT}}
-X {{ .CONFIGURATION_PACKAGE }}.buildTimestamp={{.TIMESTAMP}}
'
GOFLAGS: "-timeout 10m -v -coverpkg=./... -covermode=atomic"
DOCS_VERSION: dev
DOCS_ALIAS: ""
DOCS_REMOTE: "origin"
PRETTIER: [email protected]
CODESPELL_SKIP_OPTION: '--skip "./.git,go.mod,go.sum,./arduino-lint,./arduino-lint.exe,./internal/rule/rulefunction/testdata/libraries/MisspelledSentenceParagraphValue/library.properties,./site"'
CODESPELL_IGNORE_WORDS_OPTION: "--ignore-words ./etc/codespell-ignore-words-list.txt"