-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathTaskfile.yml
300 lines (255 loc) · 8.71 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
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/...@v3.1.1"
- 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/stringer@v0.0.0-20201211192254-72fbef54948b
- 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_PACKAGES .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: check-spelling
lint:
desc: Lint all files
cmds:
- task: go:lint
- task: python:lint
- task: docs:lint
- task: config:lint
check-formatting:
desc: Check formatting of all files
cmds:
- task: go:check-formatting
- task: docs:check-formatting
- task: config:check-formatting
format:
desc: Format all files
cmds:
- task: go:format
- task: python:format
- task: docs:format
- task: config:format
go:check:
desc: Lint and check formatting of Go code
cmds:
- task: go:lint
- task: go:check-formatting
go:lint:
desc: Lint Go code
cmds:
- go vet {{ default .DEFAULT_PACKAGES .PACKAGES }}
- |
GOLINT_PATH="$(go list -f '{{"{{"}}.Target{{"}}"}}' golang.org/x/lint/golint || echo "false")"
"$GOLINT_PATH" {{.GOLINTFLAGS}} "{{ default .DEFAULT_TARGETS .TARGETS }}"
go:check-formatting:
desc: Check Go code formatting
cmds:
- |
RESULTS="$(gofmt -l {{ default .DEFAULT_PATHS .PATHS }})"
echo "$RESULTS"
test -z "$RESULTS"
go:format:
desc: Format Go code
cmds:
- gofmt -l -w {{ default .DEFAULT_PATHS .PATHS }}
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: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: docs:format
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: docs:check-formatting
- task: docs:check-links
docs:lint:
desc: Lint documentation files
cmds:
- task: docs:check-license
docs:check-license:
desc: Check if the license file is correctly formatted
cmds:
- |
EXPECTED_LICENSE_FILE="\"LICENSE.txt\""
EXPECTED_LICENSE_TYPE="\"GPL-3.0\"" # https://spdx.org/licenses/
# See: https://github.com/licensee/licensee
LICENSEE_OUTPUT="$(licensee detect --json --confidence=100)"
DETECTED_LICENSE_FILE="$(echo "$LICENSEE_OUTPUT" | jq .matched_files[0].filename | tr --delete '\r')"
echo "Detected license file: $DETECTED_LICENSE_FILE"
if [ "$DETECTED_LICENSE_FILE" != "$EXPECTED_LICENSE_FILE" ]; then
echo "ERROR: detected license file doesn't match expected: $EXPECTED_LICENSE_FILE"
exit 1
fi
DETECTED_LICENSE_TYPE="$(echo "$LICENSEE_OUTPUT" | jq .matched_files[0].matched_license | tr --delete '\r')"
echo "Detected license type: $DETECTED_LICENSE_TYPE"
if [ "$DETECTED_LICENSE_TYPE" != "$EXPECTED_LICENSE_TYPE" ]; then
echo "ERROR: detected license type doesn't match expected $EXPECTED_LICENSE_TYPE"
exit 1
fi
docs:check-links:
desc: Check for dead links in documentation
cmds:
- |
npx --package markdown-link-check --call '
STATUS=0
for file in $(find -name "*.md"); do
markdown-link-check --quiet "$file"
STATUS=$(( $STATUS + $? ))
done
exit $STATUS'
docs:check-formatting:
desc: Check formatting of documentation files
cmds:
- npx {{ .PRETTIER }} --check "**/*.md"
docs:format:
desc: Format documentation files
cmds:
- npx {{ .PRETTIER }} --write "**/*.md"
shell:lint:
desc: Lint shell scripts
cmds:
# https://github.com/koalaman/shellcheck
- |
shopt -s globstar # Needed to check all scripts recursively.
shellcheck ./**/*.sh
shell:check-formatting:
desc: Format shell scripts
cmds:
# https://github.com/mvdan/sh#shfmt
- shfmt -d .
shell:format:
desc: Format shell scripts
cmds:
- shfmt -l -w .
config:check:
desc: Lint and check formatting of configuration files
cmds:
- task: config:check-formatting
- task: config:lint
config:lint:
desc: Lint configuration files
cmds:
- task: workflow:validate
workflow:validate:
desc: Validate GitHub Actions workflows against JSON schema
cmds:
- wget --output-document={{ .WORKFLOW_SCHEMA_PATH }} https://json.schemastore.org/github-workflow
- npx ajv-cli validate --strict=false -s {{ .WORKFLOW_SCHEMA_PATH }} -d "./.github/workflows/*.{yml,yaml}"
config:check-formatting:
desc: Check formatting of configuration files
cmds:
- npx {{ .PRETTIER }} --check "**/*.{yml,yaml}"
- npx {{ .PRETTIER }} --check "**/*.json"
config:format:
desc: Format configuration files
cmds:
- npx {{ .PRETTIER }} --write "**/*.{yml,yaml}"
- npx {{ .PRETTIER }} --write "**/*.json"
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_PACKAGES:
sh: echo `go list ./... | tr '\n' ' '`
DEFAULT_PATHS:
sh: echo '`go list -f '{{"{{"}}.Dir{{"}}"}}' ./...`'
# 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"
GOLINTFLAGS: "-min_confidence 0.8 -set_exit_status"
DOCS_VERSION: dev
DOCS_ALIAS: ""
DOCS_REMOTE: "origin"
PRETTIER: prettier@2.1.2
WORKFLOW_SCHEMA_PATH: "$(mktemp -t gha-workflow-schema-XXXXXXXXXX.json)"
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"