Skip to content

Commit 27f7506

Browse files
committed
Use npm to manage tool dependencies
Some of the project's development tool dependencies are 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 df9b5b5 commit 27f7506

10 files changed

+4049
-34
lines changed

.codespellrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[codespell]
44
# In the event of a false positive, add the problematic word, in all lowercase, to a comma-separated list here:
55
ignore-words-list = easly,pullrequest
6-
skip = ./.git,./.licenses,./go.mod,./go.sum,./package-lock.json,./poetry.lock,./yarn.lock
6+
skip = ./.git,./.licenses,node_modules,./go.mod,./go.sum,./package-lock.json,./poetry.lock,./yarn.lock
77
builtin = clear,informal,en-GB_to_en-US
88
check-filenames =
99
check-hidden =

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

Lines changed: 18 additions & 0 deletions
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?"
@@ -66,6 +74,11 @@ jobs:
6674
- name: Checkout repository
6775
uses: actions/checkout@v3
6876

77+
- name: Setup Node.js
78+
uses: actions/setup-node@v3
79+
with:
80+
node-version: ${{ env.NODE_VERSION }}
81+
6982
- name: Initialize markdownlint-cli problem matcher
7083
uses: xt0rted/markdownlint-problem-matcher@v2
7184

@@ -89,6 +102,11 @@ jobs:
89102
- name: Checkout repository
90103
uses: actions/checkout@v3
91104

105+
- name: Setup Node.js
106+
uses: actions/setup-node@v3
107+
with:
108+
node-version: ${{ env.NODE_VERSION }}
109+
92110
- name: Install Task
93111
uses: arduino/setup-task@v1
94112
with:

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

Lines changed: 9 additions & 0 deletions
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
create:
@@ -238,6 +242,11 @@ jobs:
238242
- name: Checkout repository
239243
uses: actions/checkout@v3
240244

245+
- name: Setup Node.js
246+
uses: actions/setup-node@v3
247+
with:
248+
node-version: ${{ env.NODE_VERSION }}
249+
241250
- name: Install Task
242251
uses: arduino/setup-task@v1
243252
with:

.github/workflows/check-taskfiles.yml

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
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
create:
711
push:
812
paths:
913
- ".github/workflows/check-taskfiles.ya?ml"
14+
- "package.json"
15+
- "package-lock.json"
1016
- "**/Taskfile.ya?ml"
1117
pull_request:
1218
paths:
1319
- ".github/workflows/check-taskfiles.ya?ml"
20+
- "package.json"
21+
- "package-lock.json"
1422
- "**/Taskfile.ya?ml"
1523
schedule:
1624
# Run every Tuesday at 8 AM UTC to catch breakage resulting from changes to the JSON schema.
@@ -62,6 +70,11 @@ jobs:
6270
- name: Checkout repository
6371
uses: actions/checkout@v3
6472

73+
- name: Setup Node.js
74+
uses: actions/setup-node@v3
75+
with:
76+
node-version: ${{ env.NODE_VERSION }}
77+
6578
- name: Download JSON schema for Taskfiles
6679
id: download-schema
6780
uses: carlosperate/download-file-action@v2
@@ -71,18 +84,17 @@ jobs:
7184
location: ${{ runner.temp }}/taskfile-schema
7285

7386
- name: Install JSON schema validator
74-
run: |
75-
sudo npm install \
76-
--global \
77-
ajv-cli \
78-
ajv-formats
87+
run: npm install
7988

8089
- name: Validate ${{ matrix.file }}
8190
run: |
8291
# See: https://github.com/ajv-validator/ajv-cli#readme
83-
ajv validate \
84-
--all-errors \
85-
--strict=false \
86-
-c ajv-formats \
87-
-s "${{ steps.download-schema.outputs.file-path }}" \
88-
-d "${{ matrix.file }}"
92+
npx \
93+
--package=ajv-cli \
94+
--package=ajv-formats \
95+
ajv validate \
96+
--all-errors \
97+
--strict=false \
98+
-c ajv-formats \
99+
-s "${{ steps.download-schema.outputs.file-path }}" \
100+
-d "${{ matrix.file }}"

.github/workflows/sync-labels.yml renamed to .github/workflows/sync-labels-npm.yml

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
1-
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/sync-labels.md
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/sync-labels-npm.md
22
name: Sync Labels
33

4+
env:
5+
# See: https://github.com/actions/setup-node/#readme
6+
NODE_VERSION: 16.x
7+
CONFIGURATIONS_FOLDER: .github/label-configuration-files
8+
CONFIGURATIONS_ARTIFACT: label-configuration-files
9+
410
# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
511
on:
612
push:
713
paths:
8-
- ".github/workflows/sync-labels.ya?ml"
14+
- ".github/workflows/sync-labels-npm.ya?ml"
915
- ".github/label-configuration-files/*.ya?ml"
16+
- "package.json"
17+
- "package-lock.json"
1018
pull_request:
1119
paths:
12-
- ".github/workflows/sync-labels.ya?ml"
20+
- ".github/workflows/sync-labels-npm.ya?ml"
1321
- ".github/label-configuration-files/*.ya?ml"
22+
- "package.json"
23+
- "package-lock.json"
1424
schedule:
1525
# Run daily at 8 AM UTC to sync with changes to shared label configurations.
1626
- cron: "0 8 * * *"
1727
workflow_dispatch:
1828
repository_dispatch:
1929

20-
env:
21-
CONFIGURATIONS_FOLDER: .github/label-configuration-files
22-
CONFIGURATIONS_ARTIFACT: label-configuration-files
23-
2430
jobs:
2531
check:
2632
runs-on: ubuntu-latest
@@ -31,6 +37,11 @@ jobs:
3137
- name: Checkout repository
3238
uses: actions/checkout@v3
3339

40+
- name: Setup Node.js
41+
uses: actions/setup-node@v3
42+
with:
43+
node-version: ${{ env.NODE_VERSION }}
44+
3445
- name: Download JSON schema for labels configuration file
3546
id: download-schema
3647
uses: carlosperate/download-file-action@v2
@@ -39,20 +50,19 @@ jobs:
3950
location: ${{ runner.temp }}/label-configuration-schema
4051

4152
- name: Install JSON schema validator
42-
run: |
43-
sudo npm install \
44-
--global \
45-
ajv-cli \
46-
ajv-formats
53+
run: npm install
4754

4855
- name: Validate local labels configuration
4956
run: |
5057
# See: https://github.com/ajv-validator/ajv-cli#readme
51-
ajv validate \
52-
--all-errors \
53-
-c ajv-formats \
54-
-s "${{ steps.download-schema.outputs.file-path }}" \
55-
-d "${{ env.CONFIGURATIONS_FOLDER }}/*.{yml,yaml}"
58+
npx \
59+
--package=ajv-cli \
60+
--package=ajv-formats \
61+
ajv validate \
62+
--all-errors \
63+
-c ajv-formats \
64+
-s "${{ steps.download-schema.outputs.file-path }}" \
65+
-d "${{ env.CONFIGURATIONS_FOLDER }}/*.{yml,yaml}"
5666
5767
download:
5868
needs: check
@@ -125,21 +135,27 @@ jobs:
125135
with:
126136
name: ${{ env.CONFIGURATIONS_ARTIFACT }}
127137

138+
- name: Setup Node.js
139+
uses: actions/setup-node@v3
140+
with:
141+
node-version: ${{ env.NODE_VERSION }}
142+
128143
- name: Merge label configuration files
129144
run: |
130145
# Merge all configuration files
131146
shopt -s extglob
132147
cat "${{ env.CONFIGURATIONS_FOLDER }}"/*.@(yml|yaml) > "${{ env.MERGED_CONFIGURATION_PATH }}"
133148
134149
- name: Install github-label-sync
135-
run: sudo npm install --global github-label-sync
150+
run: npm install
136151

137152
- name: Sync labels
138153
env:
139154
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
140155
run: |
141156
# See: https://github.com/Financial-Times/github-label-sync
142-
github-label-sync \
143-
--labels "${{ env.MERGED_CONFIGURATION_PATH }}" \
144-
${{ steps.dry-run.outputs.flag }} \
145-
${{ github.repository }}
157+
npx \
158+
github-label-sync \
159+
--labels "${{ env.MERGED_CONFIGURATION_PATH }}" \
160+
${{ steps.dry-run.outputs.flag }} \
161+
${{ github.repository }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ coverage_*.txt
44
/libraries-repository-engine
55
!/libraries-repository-engine/
66
/libraries-repository-engine.exe
7+
/node_modules/
78
/repository
89
!/repository/
910
/repository.exe

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22

33
/.licenses/
44
/tests/testdata/test_sync/golden/logs/
5+
node_modules/

Taskfile.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ tasks:
139139
desc: Check for broken links
140140
deps:
141141
- task: docs:generate
142+
- task: npm:install-deps
142143
cmds:
143144
- |
144145
if [[ "{{.OS}}" == "Windows_NT" ]]; then
@@ -194,15 +195,25 @@ tasks:
194195
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown-task/Taskfile.yml
195196
markdown:fix:
196197
desc: Automatically correct linting violations in Markdown files where possible
198+
deps:
199+
- task: npm:install-deps
197200
cmds:
198201
- npx markdownlint-cli --fix "**/*.md"
199202

200203
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown-task/Taskfile.yml
201204
markdown:lint:
202205
desc: Check for problems in Markdown files
206+
deps:
207+
- task: npm:install-deps
203208
cmds:
204209
- npx markdownlint-cli "**/*.md"
205210

211+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/npm-task/Taskfile.yml
212+
npm:install-deps:
213+
desc: Install dependencies managed by npm
214+
cmds:
215+
- npm install
216+
206217
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/poetry-task/Taskfile.yml
207218
poetry:install-deps:
208219
desc: Install dependencies managed by Poetry
@@ -228,6 +239,8 @@ tasks:
228239
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-prettier-formatting-task/Taskfile.yml
229240
general:format-prettier:
230241
desc: Format all supported files with Prettier
242+
deps:
243+
- task: npm:install-deps
231244
cmds:
232245
- npx prettier --write .
233246

0 commit comments

Comments
 (0)