Skip to content

Commit beb4f4b

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 f3cea83 commit beb4f4b

35 files changed

+4093
-33
lines changed

.github/dependabot.yml

+9
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ updates:
2727
assignees:
2828
- per1234
2929

30+
- package-ecosystem: npm
31+
directory: /
32+
schedule:
33+
interval: daily
34+
labels:
35+
- "topic: infrastructure"
36+
assignees:
37+
- per1234
38+
3039
- package-ecosystem: pip
3140
directory: /
3241
schedule:

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

+18
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-markdown-task.md
22
name: Check Markdown
33

4+
env:
5+
# See: https://github.com/actions/setup-node/#readme
6+
NODE_VERSION: 16.x
7+
48
# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
59
on:
610
create:
711
push:
812
paths:
913
- ".github/workflows/check-markdown-task.ya?ml"
1014
- ".markdown-link-check.json"
15+
- "package.json"
16+
- "package-lock.json"
1117
- "Taskfile.ya?ml"
1218
- "**/.markdownlint*"
1319
- "**.mdx?"
@@ -18,6 +24,8 @@ on:
1824
paths:
1925
- ".github/workflows/check-markdown-task.ya?ml"
2026
- ".markdown-link-check.json"
27+
- "package.json"
28+
- "package-lock.json"
2129
- "Taskfile.ya?ml"
2230
- "**/.markdownlint*"
2331
- "**.mdx?"
@@ -63,6 +71,11 @@ jobs:
6371
- name: Checkout repository
6472
uses: actions/checkout@v3
6573

74+
- name: Setup Node.js
75+
uses: actions/setup-node@v3
76+
with:
77+
node-version: ${{ env.NODE_VERSION }}
78+
6679
- name: Initialize markdownlint-cli problem matcher
6780
uses: xt0rted/markdownlint-problem-matcher@v1
6881

@@ -84,6 +97,11 @@ jobs:
8497
- name: Checkout repository
8598
uses: actions/checkout@v3
8699

100+
- name: Setup Node.js
101+
uses: actions/setup-node@v3
102+
with:
103+
node-version: ${{ env.NODE_VERSION }}
104+
87105
- name: Install Task
88106
uses: arduino/setup-task@v1
89107
with:

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

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-npm-task.md
2+
name: Check npm
3+
4+
env:
5+
# See: https://github.com/actions/setup-node/#readme
6+
NODE_VERSION: 16.x
7+
8+
# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
9+
on:
10+
push:
11+
paths:
12+
- ".github/workflows/check-npm-task.ya?ml"
13+
- "**/package.json"
14+
- "**/package-lock.json"
15+
- "Taskfile.ya?ml"
16+
pull_request:
17+
paths:
18+
- ".github/workflows/check-npm-task.ya?ml"
19+
- "**/package.json"
20+
- "**/package-lock.json"
21+
- "Taskfile.ya?ml"
22+
schedule:
23+
# Run every Tuesday at 8 AM UTC to catch breakage resulting from changes to the JSON schema.
24+
- cron: "0 8 * * TUE"
25+
workflow_dispatch:
26+
repository_dispatch:
27+
28+
permissions:
29+
contents: read
30+
31+
jobs:
32+
validate:
33+
runs-on: ubuntu-latest
34+
35+
steps:
36+
- name: Checkout repository
37+
uses: actions/checkout@v3
38+
39+
- name: Setup Node.js
40+
uses: actions/setup-node@v3
41+
with:
42+
node-version: ${{ env.NODE_VERSION }}
43+
44+
- name: Install Task
45+
uses: arduino/setup-task@v1
46+
with:
47+
repo-token: ${{ secrets.GITHUB_TOKEN }}
48+
version: 3.x
49+
50+
- name: Validate package.json
51+
run: task npm:validate
52+
53+
check-sync:
54+
runs-on: ubuntu-latest
55+
56+
steps:
57+
- name: Checkout repository
58+
uses: actions/checkout@v3
59+
60+
- name: Setup Node.js
61+
uses: actions/setup-node@v3
62+
with:
63+
node-version: ${{ env.NODE_VERSION }}
64+
65+
- name: Install Task
66+
uses: arduino/setup-task@v1
67+
with:
68+
repo-token: ${{ secrets.GITHUB_TOKEN }}
69+
version: 3.x
70+
71+
- name: Install npm dependencies
72+
run: task npm:install-deps
73+
74+
- name: Check package-lock.json
75+
run: git diff --color --exit-code package-lock.json

.github/workflows/check-prettier-formatting-task.yml

+9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-prettier-formatting-task.md
22
name: Check Prettier Formatting
33

4+
env:
5+
# See: https://github.com/actions/setup-node/#readme
6+
NODE_VERSION: 16.x
7+
48
# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
59
on:
610
push:
@@ -209,6 +213,11 @@ jobs:
209213
- name: Checkout repository
210214
uses: actions/checkout@v3
211215

216+
- name: Setup Node.js
217+
uses: actions/setup-node@v3
218+
with:
219+
node-version: ${{ env.NODE_VERSION }}
220+
212221
- name: Install Task
213222
uses: arduino/setup-task@v1
214223
with:

.github/workflows/check-taskfiles.yml

+23-11
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-taskfiles.md
22
name: Check Taskfiles
33

4+
env:
5+
# See: https://github.com/actions/setup-node/#readme
6+
NODE_VERSION: 16.x
7+
48
# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
59
on:
610
push:
711
paths:
812
- ".github/workflows/check-taskfiles.ya?ml"
13+
- "package.json"
14+
- "package-lock.json"
915
- "**/Taskfile.ya?ml"
1016
pull_request:
1117
paths:
1218
- ".github/workflows/check-taskfiles.ya?ml"
19+
- "package.json"
20+
- "package-lock.json"
1321
- "**/Taskfile.ya?ml"
1422
schedule:
1523
# Run every Tuesday at 8 AM UTC to catch breakage resulting from changes to the JSON schema.
@@ -34,6 +42,11 @@ jobs:
3442
- name: Checkout repository
3543
uses: actions/checkout@v3
3644

45+
- name: Setup Node.js
46+
uses: actions/setup-node@v3
47+
with:
48+
node-version: ${{ env.NODE_VERSION }}
49+
3750
- name: Download JSON schema for Taskfiles
3851
id: download-schema
3952
uses: carlosperate/download-file-action@v1
@@ -43,18 +56,17 @@ jobs:
4356
location: ${{ runner.temp }}/taskfile-schema
4457

4558
- name: Install JSON schema validator
46-
run: |
47-
sudo npm install \
48-
--global \
49-
ajv-cli \
50-
ajv-formats
59+
run: npm install
5160

5261
- name: Validate ${{ matrix.file }}
5362
run: |
5463
# See: https://github.com/ajv-validator/ajv-cli#readme
55-
ajv validate \
56-
--all-errors \
57-
--strict=false \
58-
-c ajv-formats \
59-
-s "${{ steps.download-schema.outputs.file-path }}" \
60-
-d "${{ matrix.file }}"
64+
npx \
65+
--package=ajv-cli \
66+
--package=ajv-formats \
67+
ajv validate \
68+
--all-errors \
69+
--strict=false \
70+
-c ajv-formats \
71+
-s "${{ steps.download-schema.outputs.file-path }}" \
72+
-d "${{ matrix.file }}"

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

+9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Source: https://github.com/arduino/tooling-project-assets/blob/master/workflow-templates/check-workflows-task.md
22
name: Check Workflows
33

4+
env:
5+
# See: https://github.com/actions/setup-node/#readme
6+
NODE_VERSION: 16.x
7+
48
# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
59
on:
610
push:
@@ -27,6 +31,11 @@ jobs:
2731
- name: Checkout repository
2832
uses: actions/checkout@v3
2933

34+
- name: Setup Node.js
35+
uses: actions/setup-node@v3
36+
with:
37+
node-version: ${{ env.NODE_VERSION }}
38+
3039
- name: Install Task
3140
uses: arduino/setup-task@v1
3241
with:

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
/node_modules/
12
__pycache__/
23
.idea/

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[![Check Issue Templates status](https://github.com/arduino/tooling-project-assets/actions/workflows/check-issue-templates.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/check-issue-templates.yml)
55
[![Check Label Configuration status](https://github.com/arduino/tooling-project-assets/actions/workflows/check-labels.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/check-labels.yml)
66
[![Check markdownlint Configuration status](https://github.com/arduino/tooling-project-assets/actions/workflows/check-markdownlint.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/check-markdownlint.yml)
7+
[![Check npm status](https://github.com/arduino/tooling-project-assets/actions/workflows/check-npm-task.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/check-npm-task.yml)
78
[![Check General Formatting status](https://github.com/arduino/tooling-project-assets/actions/workflows/check-general-formatting-task.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/check-general-formatting-task.yml)
89
[![Check License status](https://github.com/arduino/tooling-project-assets/actions/workflows/check-license.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/check-license.yml)
910
[![Check Workflow Duplicates Sync status](https://github.com/arduino/tooling-project-assets/actions/workflows/check-dependabot-sync.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/check-dependabot-sync.yml)

0 commit comments

Comments
 (0)