-
Notifications
You must be signed in to change notification settings - Fork 9
/
Taskfile.yml
359 lines (337 loc) · 14 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
# See: https://taskfile.dev/#/usage
version: "3"
vars:
# Path of the primary npm-managed project:
DEFAULT_NPM_PROJECT_PATH: ./
# Last version of ajv-cli with support for the JSON schema "Draft 4" specification
SCHEMA_DRAFT_4_AJV_CLI_VERSION: 3.3.0
tasks:
build:
desc: Build the project
deps:
- task: ts:build
check:
desc: Check for problems with the project
deps:
- task: general:check-spelling
- task: js:test
- task: npm:validate
- task: ts:validate
vars:
TSCONFIG_PATH: "./tsconfig.json"
fix:
desc: Make automated corrections to the project's files
deps:
- task: general:correct-spelling
- task: general:format-prettier
- task: markdown:toc
vars:
FILE_PATH: README.md
MAX_DEPTH: 3
- task: npm:install-deps
- task: poetry:sync
- task: ts:build
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-dependencies-task/Taskfile.yml
general:cache-dep-licenses:
desc: Cache dependency license metadata
deps:
- task: general:prepare-deps
cmds:
- |
if ! which licensed &>/dev/null; then
if [[ {{OS}} == "windows" ]]; then
echo "Licensed does not have Windows support."
echo "Please use Linux/macOS or download the dependencies cache from the GitHub Actions workflow artifact."
else
echo "licensed not found or not in PATH."
echo "Please install: https://github.com/github/licensed#as-an-executable"
fi
exit 1
fi
- licensed cache
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-dependencies-task/Taskfile.yml
general:check-dep-licenses:
desc: Check for unapproved dependency licenses
deps:
- task: general:cache-dep-licenses
cmds:
- licensed status
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/spell-check-task/Taskfile.yml
general:check-spelling:
desc: Check for commonly misspelled words
deps:
- task: poetry:install-deps
vars:
POETRY_GROUPS: dev
cmds:
- poetry run codespell
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/spell-check-task/Taskfile.yml
general:correct-spelling:
desc: Correct commonly misspelled words where possible
deps:
- task: poetry:install-deps
vars:
POETRY_GROUPS: dev
cmds:
- poetry run codespell --write-changes
# 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
deps:
- task: npm:install-deps
cmds:
- npx prettier --write .
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-npm-dependencies-task/Taskfile.yml
general:prepare-deps:
desc: Prepare project dependencies for license check
deps:
- task: npm:install-deps
js:test:
desc: |
Test the project's JavaScript/TypeScript code.
Environment variable parameters:
PROJECT_PATH: Path of the npm-managed project (default: {{.DEFAULT_NPM_PROJECT_PATH}}).
deps:
- task: npm:install-deps
dir: |
"{{default .DEFAULT_NPM_PROJECT_PATH .PROJECT_PATH}}"
cmds:
# See: https://jestjs.io/docs/ecmascript-modules#:~:text=Execute%20node%20with%20%2D%2Dexperimental%2Dvm%2Dmodules
- |
NODE_OPTIONS="$NODE_OPTIONS --experimental-vm-modules" \
npx \
jest \
--coverage
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-toc-task/Taskfile.yml
markdown:toc:
desc: |
Update the table of contents
Environment variable parameters:
FILE_PATH: Path of the file in which to update the ToC.
MAX_DEPTH: The maximum heading level for which to add ToC items.
deps:
- task: npm:install-deps
cmds:
- |
npx \
markdown-toc \
--bullets=- \
--maxdepth={{.MAX_DEPTH}} \
-i \
"{{.FILE_PATH}}"
# Parameter variables:
npm:install-deps:
desc: |
Install dependencies managed by npm.
Environment variable parameters:
PROJECT_PATH: Path of the npm-managed project (default: {{.DEFAULT_NPM_PROJECT_PATH}}).
dir: |
"{{default "./" .PROJECT_PATH}}"
cmds:
- npm install
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-npm-task/Taskfile.yml
npm:validate:
desc: |
Validate npm configuration files against their JSON schema.
Environment variable parameters:
PROJECT_PATH: Path of the npm-managed project (default: {{.DEFAULT_NPM_PROJECT_PATH}}).
deps:
- task: npm:install-deps
vars:
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/package.json
SCHEMA_URL: https://json.schemastore.org/package.json
SCHEMA_PATH:
sh: task utility:mktemp-file TEMPLATE="package-json-schema-XXXXXXXXXX.json"
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/ava.json
AVA_SCHEMA_URL: https://json.schemastore.org/ava.json
AVA_SCHEMA_PATH:
sh: task utility:mktemp-file TEMPLATE="ava-schema-XXXXXXXXXX.json"
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/base.json
BASE_SCHEMA_URL: https://json.schemastore.org/base.json
BASE_SCHEMA_PATH:
sh: task utility:mktemp-file TEMPLATE="base-schema-XXXXXXXXXX.json"
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/eslintrc.json
ESLINTRC_SCHEMA_URL: https://json.schemastore.org/eslintrc.json
ESLINTRC_SCHEMA_PATH:
sh: task utility:mktemp-file TEMPLATE="eslintrc-schema-XXXXXXXXXX.json"
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/jscpd.json
JSCPD_SCHEMA_URL: https://json.schemastore.org/jscpd.json
JSCPD_SCHEMA_PATH:
sh: task utility:mktemp-file TEMPLATE="jscpd-schema-XXXXXXXXXX.json"
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/npm-badges.json
NPM_BADGES_SCHEMA_URL: https://json.schemastore.org/npm-badges.json
NPM_BADGES_SCHEMA_PATH:
sh: task utility:mktemp-file TEMPLATE="npm-badges-schema-XXXXXXXXXX.json"
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/partial-eslint-plugins.json
PARTIAL_ESLINT_PLUGINS_SCHEMA_URL: https://json.schemastore.org/partial-eslint-plugins.json
PARTIAL_ESLINT_PLUGINS_PATH:
sh: task utility:mktemp-file TEMPLATE="partial-eslint-plugins-schema-XXXXXXXXXX.json"
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/prettierrc.json
PRETTIERRC_SCHEMA_URL: https://json.schemastore.org/prettierrc.json
PRETTIERRC_SCHEMA_PATH:
sh: task utility:mktemp-file TEMPLATE="prettierrc-schema-XXXXXXXXXX.json"
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/semantic-release.json
SEMANTIC_RELEASE_SCHEMA_URL: https://json.schemastore.org/semantic-release.json
SEMANTIC_RELEASE_SCHEMA_PATH:
sh: task utility:mktemp-file TEMPLATE="semantic-release-schema-XXXXXXXXXX.json"
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/stylelintrc.json
STYLELINTRC_SCHEMA_URL: https://json.schemastore.org/stylelintrc.json
STYLELINTRC_SCHEMA_PATH:
sh: task utility:mktemp-file TEMPLATE="stylelintrc-schema-XXXXXXXXXX.json"
INSTANCE_PATH: >-
{{default .DEFAULT_NPM_PROJECT_PATH .PROJECT_PATH}}/package.json
cmds:
- wget --quiet --output-document="{{.SCHEMA_PATH}}" {{.SCHEMA_URL}}
- wget --quiet --output-document="{{.AVA_SCHEMA_PATH}}" {{.AVA_SCHEMA_URL}}
- wget --quiet --output-document="{{.BASE_SCHEMA_PATH}}" {{.BASE_SCHEMA_URL}}
- wget --quiet --output-document="{{.ESLINTRC_SCHEMA_PATH}}" {{.ESLINTRC_SCHEMA_URL}}
- wget --quiet --output-document="{{.JSCPD_SCHEMA_PATH}}" {{.JSCPD_SCHEMA_URL}}
- wget --quiet --output-document="{{.NPM_BADGES_SCHEMA_PATH}}" {{.NPM_BADGES_SCHEMA_URL}}
- wget --quiet --output-document="{{.PARTIAL_ESLINT_PLUGINS_PATH}}" {{.PARTIAL_ESLINT_PLUGINS_SCHEMA_URL}}
- wget --quiet --output-document="{{.PRETTIERRC_SCHEMA_PATH}}" {{.PRETTIERRC_SCHEMA_URL}}
- wget --quiet --output-document="{{.SEMANTIC_RELEASE_SCHEMA_PATH}}" {{.SEMANTIC_RELEASE_SCHEMA_URL}}
- wget --quiet --output-document="{{.STYLELINTRC_SCHEMA_PATH}}" {{.STYLELINTRC_SCHEMA_URL}}
- |
npx \
--package=ajv-cli \
--package=ajv-formats \
ajv validate \
--all-errors \
--strict=false \
-s "{{.SCHEMA_PATH}}" \
-r "{{.AVA_SCHEMA_PATH}}" \
-r "{{.BASE_SCHEMA_PATH}}" \
-r "{{.ESLINTRC_SCHEMA_PATH}}" \
-r "{{.JSCPD_SCHEMA_PATH}}" \
-r "{{.NPM_BADGES_SCHEMA_PATH}}" \
-r "{{.PARTIAL_ESLINT_PLUGINS_PATH}}" \
-r "{{.PRETTIERRC_SCHEMA_PATH}}" \
-r "{{.SEMANTIC_RELEASE_SCHEMA_PATH}}" \
-r "{{.STYLELINTRC_SCHEMA_PATH}}" \
-d "{{.INSTANCE_PATH}}"
poetry:install:
desc: Install Poetry
run: once
vars:
PYTHON_PATH:
sh: task utility:normalize-path RAW_PATH="$(which python)"
cmds:
- |
if ! which pipx &>/dev/null; then
echo "pipx not found or not in PATH."
echo "Please install: https://pipx.pypa.io/stable/installation/#installing-pipx"
exit 1
fi
- |
if ! which yq &>/dev/null; then
echo "yq not found or not in PATH."
echo "Please install: https://github.com/mikefarah/yq/#install"
exit 1
fi
- |
pipx install \
--python "{{.PYTHON_PATH}}" \
"poetry==$( \
yq \
--input-format toml \
--output-format yaml \
'.tool.poetry.group.pipx.dependencies.poetry' \
< pyproject.toml
)"
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/poetry-task/Taskfile.yml
poetry:install-deps:
desc: |
Install dependencies managed by Poetry.
Environment variable parameters:
POETRY_GROUPS: Poetry dependency groups to install (default: install all dependencies).
run: when_changed
deps:
- task: poetry:install
cmds:
- |
poetry install \
{{if .POETRY_GROUPS}} --only {{.POETRY_GROUPS}} {{end}}
poetry:sync:
desc: Sync poetry.lock
deps:
- task: poetry:install
cmds:
- |
poetry lock \
--no-cache \
--no-update
ts:build:
desc: Build the action's TypeScript code.
deps:
- task: npm:install-deps
cmds:
- npx tsc
- npx ncc build
ts:validate:
desc: |
Validate TypeScript configuration file against its JSON schema
Environment variable parameters:
TSCONFIG_PATH: Path of the TypeScript configuration file (default: ./tsconfig.json).
vars:
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/tsconfig.json
SCHEMA_URL: https://json.schemastore.org/tsconfig.json
SCHEMA_PATH:
sh: task utility:mktemp-file TEMPLATE="tsconfig-schema-XXXXXXXXXX.json"
INSTANCE_PATH: '{{default "./tsconfig.json" .TSCONFIG_PATH}}'
WORKING_FOLDER:
sh: task utility:mktemp-folder TEMPLATE="ts-validate-XXXXXXXXXX"
WORKING_INSTANCE_PATH:
sh: echo "{{.WORKING_FOLDER}}/$(basename "{{.INSTANCE_PATH}}")"
deps:
- task: npm:install-deps
cmds:
- |
# TypeScript allows comments in tsconfig.json.
# ajv-cli did not support comments in JSON at the 3.x version in use (support was added in a later version).
npx strip-json-comments-cli \
--no-whitespace \
"{{.INSTANCE_PATH}}" \
> "{{.WORKING_INSTANCE_PATH}}"
- |
wget \
--quiet \
--output-document="{{.SCHEMA_PATH}}" \
{{.SCHEMA_URL}}
- |
cd "{{.WORKING_FOLDER}}" # Workaround for https://github.com/npm/cli/issues/3210
npx ajv-cli@{{.SCHEMA_DRAFT_4_AJV_CLI_VERSION}} validate \
--all-errors \
-s "{{.SCHEMA_PATH}}" \
-d "{{.WORKING_INSTANCE_PATH}}"
# Make a temporary file named according to the passed TEMPLATE variable and print the path passed to stdout
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
utility:mktemp-file:
vars:
RAW_PATH:
sh: mktemp --tmpdir "{{.TEMPLATE}}"
cmds:
- task: utility:normalize-path
vars:
RAW_PATH: "{{.RAW_PATH}}"
# Make a temporary folder named according to the passed TEMPLATE variable and print the path passed to stdout
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
utility:mktemp-folder:
vars:
RAW_PATH:
sh: mktemp --directory --tmpdir "{{.TEMPLATE}}"
cmds:
- task: utility:normalize-path
vars:
RAW_PATH: "{{.RAW_PATH}}"
# Print a normalized version of the path passed via the RAW_PATH variable to stdout
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
utility:normalize-path:
cmds:
- |
if [[ "{{.OS}}" == "Windows_NT" ]] && which cygpath &>/dev/null; then
# Even though the shell handles POSIX format absolute paths as expected, external applications do not.
# So paths passed to such applications must first be converted to Windows format.
cygpath -w "{{.RAW_PATH}}"
else
echo "{{.RAW_PATH}}"
fi