Skip to content

Commit fc81d8f

Browse files
committed
Use npm to manage tool dependencies
Some of the project infrastructure uses 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 a1d43cb commit fc81d8f

10 files changed

+3467
-34
lines changed

.github/dependabot.yml

+9
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ updates:
1212
labels:
1313
- "topic: infrastructure"
1414

15+
- package-ecosystem: npm
16+
directory: /
17+
schedule:
18+
interval: daily
19+
labels:
20+
- "topic: infrastructure"
21+
assignees:
22+
- per1234
23+
1524
- package-ecosystem: pip
1625
directory: /
1726
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-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

+13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
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:
711
paths:
812
- ".github/workflows/*.ya?ml"
13+
- "package.json"
14+
- "package-lock.json"
915
- "Taskfile.ya?ml"
1016
pull_request:
1117
paths:
1218
- ".github/workflows/*.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.
@@ -25,6 +33,11 @@ jobs:
2533
- name: Checkout repository
2634
uses: actions/checkout@v3
2735

36+
- name: Setup Node.js
37+
uses: actions/setup-node@v3
38+
with:
39+
node-version: ${{ env.NODE_VERSION }}
40+
2841
- name: Install Task
2942
uses: arduino/setup-task@v1
3043
with:

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

+38-22
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
@@ -29,6 +35,11 @@ jobs:
2935
- name: Checkout repository
3036
uses: actions/checkout@v3
3137

38+
- name: Setup Node.js
39+
uses: actions/setup-node@v3
40+
with:
41+
node-version: ${{ env.NODE_VERSION }}
42+
3243
- name: Download JSON schema for labels configuration file
3344
id: download-schema
3445
uses: carlosperate/download-file-action@v1
@@ -37,20 +48,19 @@ jobs:
3748
location: ${{ runner.temp }}/label-configuration-schema
3849

3950
- name: Install JSON schema validator
40-
run: |
41-
sudo npm install \
42-
--global \
43-
ajv-cli \
44-
ajv-formats
51+
run: npm install
4552

4653
- name: Validate local labels configuration
4754
run: |
4855
# See: https://github.com/ajv-validator/ajv-cli#readme
49-
ajv validate \
50-
--all-errors \
51-
-c ajv-formats \
52-
-s "${{ steps.download-schema.outputs.file-path }}" \
53-
-d "${{ env.CONFIGURATIONS_FOLDER }}/*.{yml,yaml}"
56+
npx \
57+
--package=ajv-cli \
58+
--package=ajv-formats \
59+
ajv validate \
60+
--all-errors \
61+
-c ajv-formats \
62+
-s "${{ steps.download-schema.outputs.file-path }}" \
63+
-d "${{ env.CONFIGURATIONS_FOLDER }}/*.{yml,yaml}"
5464
5565
download:
5666
needs: check
@@ -119,21 +129,27 @@ jobs:
119129
with:
120130
name: ${{ env.CONFIGURATIONS_ARTIFACT }}
121131

132+
- name: Setup Node.js
133+
uses: actions/setup-node@v3
134+
with:
135+
node-version: ${{ env.NODE_VERSION }}
136+
122137
- name: Merge label configuration files
123138
run: |
124139
# Merge all configuration files
125140
shopt -s extglob
126141
cat "${{ env.CONFIGURATIONS_FOLDER }}"/*.@(yml|yaml) > "${{ env.MERGED_CONFIGURATION_PATH }}"
127142
128143
- name: Install github-label-sync
129-
run: sudo npm install --global github-label-sync
144+
run: npm install
130145

131146
- name: Sync labels
132147
env:
133148
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
134149
run: |
135150
# See: https://github.com/Financial-Times/github-label-sync
136-
github-label-sync \
137-
--labels "${{ env.MERGED_CONFIGURATION_PATH }}" \
138-
${{ steps.dry-run.outputs.flag }} \
139-
${{ github.repository }}
151+
npx \
152+
github-label-sync \
153+
--labels "${{ env.MERGED_CONFIGURATION_PATH }}" \
154+
${{ steps.dry-run.outputs.flag }} \
155+
${{ github.repository }}

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
[![Check Workflows status](https://github.com/arduino/arduinoOTA/actions/workflows/check-workflows-task.yml/badge.svg)](https://github.com/arduino/arduinoOTA/actions/workflows/check-workflows-task.yml)
1010
[![Check YAML status](https://github.com/arduino/arduinoOTA/actions/workflows/check-yaml-task.yml/badge.svg)](https://github.com/arduino/arduinoOTA/actions/workflows/check-yaml-task.yml)
1111
[![Check License status](https://github.com/arduino/arduinoOTA/actions/workflows/check-license.yml/badge.svg)](https://github.com/arduino/arduinoOTA/actions/workflows/check-license.yml)
12-
[![Sync Labels status](https://github.com/arduino/arduinoOTA/actions/workflows/sync-labels.yml/badge.svg)](https://github.com/arduino/arduinoOTA/actions/workflows/sync-labels.yml)
12+
[![Sync Labels status](https://github.com/arduino/arduinoOTA/actions/workflows/sync-labels-npm.yml/badge.svg)](https://github.com/arduino/arduinoOTA/actions/workflows/sync-labels-npm.yml)
1313

1414
**arduinoOTA** is a tool for uploading programs to [Arduino](https://arduino.cc/) boards over a network.
1515

Taskfile.yml

+15
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ tasks:
1111
WORKFLOW_SCHEMA_PATH:
1212
sh: task utility:mktemp-file TEMPLATE="workflow-schema-XXXXXXXXXX.json"
1313
WORKFLOWS_DATA_PATH: "./.github/workflows/*.{yml,yaml}"
14+
deps:
15+
- task: npm:install-deps
1416
cmds:
1517
- |
1618
wget \
@@ -47,6 +49,8 @@ tasks:
4749
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-prettier-formatting-task/Taskfile.yml
4850
general:format-prettier:
4951
desc: Format all supported files with Prettier
52+
deps:
53+
- task: npm:install-deps
5054
cmds:
5155
- npx prettier --write .
5256

@@ -71,6 +75,7 @@ tasks:
7175
desc: Check for broken links
7276
deps:
7377
- task: docs:generate
78+
- task: npm:install-deps
7479
cmds:
7580
- |
7681
if [[ "{{.OS}}" == "Windows_NT" ]]; then
@@ -126,15 +131,25 @@ tasks:
126131
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown-task/Taskfile.yml
127132
markdown:fix:
128133
desc: Automatically correct linting violations in Markdown files where possible
134+
deps:
135+
- task: npm:install-deps
129136
cmds:
130137
- npx markdownlint-cli --fix "**/*.md"
131138

132139
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown-task/Taskfile.yml
133140
markdown:lint:
134141
desc: Check for problems in Markdown files
142+
deps:
143+
- task: npm:install-deps
135144
cmds:
136145
- npx markdownlint-cli "**/*.md"
137146

147+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/npm-task/Taskfile.yml
148+
npm:install-deps:
149+
desc: Install dependencies managed by npm
150+
cmds:
151+
- npm install
152+
138153
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/poetry-task/Taskfile.yml
139154
poetry:install-deps:
140155
desc: Install dependencies managed by Poetry

0 commit comments

Comments
 (0)