Skip to content

Commit e22b976

Browse files
committed
Use npm to manage tool dependencies
Some of the assets use tools sourced from the npm software registry. Previously, the version of the tools used was not controlled. This was problematic because: - A different version of the tool may be used on the contributor's machine than on the CI runner, resulting in confusing failures. - The project is immediately subject to disruption or breakage resulting from a release of the tool. --- These tools were installed via either of the following methods: `npx <pkg>` This approach has the following behaviors of interest: https://docs.npmjs.com/cli/v8/commands/npx#description > If any requested packages are not present in the local project dependencies, then they are installed to a folder in the npm cache, which is added to the PATH environment variable in the executed process. > Package names provided without a specifier will be matched with whatever version exists in the local project. Package names with a specifier will only be considered a match if they have the exact same name and version as the local dependency. This means that the version used was: 1. Whatever happens to be present in the local cache 2. The latest available version if it is not already present `npm install --global <pkg>` The latest available version of the package is used. --- The new approach is to specify the version of the tools via the standard npm metadata files (package.json + package-lock.json). This approach was chosen over the `npx <pkg>@<version>` alternative for the following reasons: - Enables automated updates via Dependabot PRs - Enables automated vulnerability alerts - Separates dependency management from the asset contents (i.e., no need to mess with the taskfile or workflow on every update) - Matches how we are already managing Python dependencies (pyproject.toml + poetry.lock)
1 parent 8aba048 commit e22b976

6 files changed

+1950
-51
lines changed

.github/workflows/check-action-metadata-task.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@ on:
1010
paths:
1111
- ".github/workflows/check-action-metadata-task.ya?ml"
1212
- "action.ya?ml"
13+
- "package.json"
14+
- "package-lock.json"
1315
- "Taskfile.ya?ml"
1416
pull_request:
1517
paths:
1618
- ".github/workflows/check-action-metadata-task.ya?ml"
1719
- "action.ya?ml"
20+
- "package.json"
21+
- "package-lock.json"
1822
- "Taskfile.ya?ml"
1923
schedule:
2024
# Run every Tuesday at 8 AM UTC to catch breakage from changes to the JSON schema.

.github/workflows/check-markdown-task.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ on:
1111
paths:
1212
- ".github/workflows/check-markdown-task.ya?ml"
1313
- ".markdown-link-check.json"
14+
- "package.json"
15+
- "package-lock.json"
1416
- "Taskfile.ya?ml"
1517
- "**/.markdownlint*"
1618
- "**.mdx?"
@@ -21,6 +23,8 @@ on:
2123
paths:
2224
- ".github/workflows/check-markdown-task.ya?ml"
2325
- ".markdown-link-check.json"
26+
- "package.json"
27+
- "package-lock.json"
2428
- "Taskfile.ya?ml"
2529
- "**/.markdownlint*"
2630
- "**.mdx?"
@@ -65,6 +69,11 @@ jobs:
6569
- name: Checkout repository
6670
uses: actions/checkout@v3
6771

72+
- name: Setup Node.js
73+
uses: actions/setup-node@v3
74+
with:
75+
node-version: ${{ env.NODE_VERSION }}
76+
6877
- name: Install Task
6978
uses: arduino/setup-task@v1
7079
with:

.github/workflows/check-tsconfig-task.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@ on:
1010
paths:
1111
- ".github/workflows/check-tsconfig-task.ya?ml"
1212
- "**/tsconfig*.json"
13+
- "package.json"
14+
- "package-lock.json"
1315
- "Taskfile.ya?ml"
1416
pull_request:
1517
paths:
1618
- ".github/workflows/check-tsconfig-task.ya?ml"
1719
- "**/tsconfig*.json"
20+
- "package.json"
21+
- "package-lock.json"
1822
- "Taskfile.ya?ml"
1923
schedule:
2024
# Run every Tuesday at 8 AM UTC to catch breakage from changes to the JSON schema.

Taskfile.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ tasks:
4141
vars:
4242
ACTION_METADATA_SCHEMA_PATH:
4343
sh: mktemp -t github-action-schema-XXXXXXXXXX.json
44+
deps:
45+
- task: npm:install-deps
4446
cmds:
4547
- wget --quiet --output-document="{{.ACTION_METADATA_SCHEMA_PATH}}" https://json.schemastore.org/github-action
4648
- npx ajv-cli validate --strict=false -s "{{.ACTION_METADATA_SCHEMA_PATH}}" -d "action.yml"
@@ -95,6 +97,8 @@ tasks:
9597
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-prettier-formatting-task/Taskfile.yml
9698
general:format-prettier:
9799
desc: Format all supported files with Prettier
100+
deps:
101+
- task: npm:install-deps
98102
cmds:
99103
- npx prettier --write .
100104

@@ -109,6 +113,7 @@ tasks:
109113
desc: Check for broken links
110114
deps:
111115
- task: docs:generate
116+
- task: npm:install-deps
112117
cmds:
113118
- |
114119
if [[ "{{.OS}}" == "Windows_NT" ]]; then
@@ -152,12 +157,16 @@ tasks:
152157
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown-task/Taskfile.yml
153158
markdown:fix:
154159
desc: Automatically correct linting violations in Markdown files where possible
160+
deps:
161+
- task: npm:install-deps
155162
cmds:
156163
- npx markdownlint-cli --fix "**/*.md"
157164

158165
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown-task/Taskfile.yml
159166
markdown:lint:
160167
desc: Check for problems in Markdown files
168+
deps:
169+
- task: npm:install-deps
161170
cmds:
162171
- npx markdownlint-cli "**/*.md"
163172

@@ -283,6 +292,8 @@ tasks:
283292
sh: task utility:mktemp-folder TEMPLATE="ts-validate-XXXXXXXXXX"
284293
WORKING_INSTANCE_PATH:
285294
sh: echo "{{.WORKING_FOLDER}}/$(basename "{{.INSTANCE_PATH}}")"
295+
deps:
296+
- task: npm:install-deps
286297
cmds:
287298
- |
288299
# TypeScript allows comments in tsconfig.json.

0 commit comments

Comments
 (0)