Skip to content

Commit ec3d12e

Browse files
committed
Only validate package.json files in specified paths
The project infrastructure validates the package.json npm configuration files against their JSON schema. Previously, in order to provide validation coverage for all package.json files in any locations in the repository, a "globstar" was used to cause the validator to recursively search the entire file tree under the repository. That approach is problematic because the repository contains externally maintained files (e.g., the npm packages under the node_modules folder). Searching and validating these files is inefficient at best and the cause of spurious failures at worst. This is avoided by targeting the search. Support for a repository maintainer to configure any number of specific locations of npm-managed projects in the "Check npm" workflow has been added, so this system is used to target the validations. When the `npm:validate` task is ran by a contributor on their local clone, it defaults to the root of the repository, but the path can be configured by setting the PROJECT_PATH taskfile variable via an argument to the task invocation command.
1 parent f0c9ef6 commit ec3d12e

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

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

+15-3
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,18 @@ jobs:
5252
echo "result=$RESULT" >> $GITHUB_OUTPUT
5353
5454
validate:
55+
name: validate (${{ matrix.project.path }})
5556
needs: run-determination
5657
if: needs.run-determination.outputs.result == 'true'
5758
runs-on: ubuntu-latest
5859
permissions:
5960
contents: read
6061

62+
strategy:
63+
fail-fast: false
64+
matrix:
65+
project:
66+
- path: .
6167

6268
steps:
6369
- name: Checkout repository
@@ -75,15 +81,21 @@ jobs:
7581
version: 3.x
7682

7783
- name: Validate package.json
78-
run: task --silent npm:validate
84+
run: task --silent npm:validate PROJECT_PATH="${{ matrix.project.path }}"
7985

8086
check-sync:
87+
name: check-sync (${{ matrix.project.path }})
8188
needs: run-determination
8289
if: needs.run-determination.outputs.result == 'true'
8390
runs-on: ubuntu-latest
8491
permissions:
8592
contents: read
8693

94+
strategy:
95+
fail-fast: false
96+
matrix:
97+
project:
98+
- path: .
8799

88100
steps:
89101
- name: Checkout repository
@@ -101,7 +113,7 @@ jobs:
101113
version: 3.x
102114

103115
- name: Install npm dependencies
104-
run: task npm:install-deps
116+
run: task npm:install-deps PROJECT_PATH="${{ matrix.project.path }}"
105117

106118
- name: Check package-lock.json
107-
run: git diff --color --exit-code package-lock.json
119+
run: git diff --color --exit-code "${{ matrix.project.path }}/package-lock.json"

Taskfile.yml

+8-1
Original file line numberDiff line numberDiff line change
@@ -313,13 +313,19 @@ tasks:
313313
-i \
314314
"{{.FILE_PATH}}"
315315
316+
# Parameter variables:
317+
# - PROJECT_PATH: path of the npm-managed project. Default value: "./"
316318
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/npm-task/Taskfile.yml
317319
npm:install-deps:
318320
desc: Install dependencies managed by npm
319321
run: once
322+
dir: |
323+
"{{default "./" .PROJECT_PATH}}"
320324
cmds:
321325
- npm install
322326

327+
# Parameter variables:
328+
# - PROJECT_PATH: path of the npm-managed project. Default value: "./"
323329
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-npm-task/Taskfile.yml
324330
npm:validate:
325331
desc: Validate npm configuration files against their JSON schema
@@ -356,7 +362,8 @@ tasks:
356362
STYLELINTRC_SCHEMA_URL: https://json.schemastore.org/stylelintrc.json
357363
STYLELINTRC_SCHEMA_PATH:
358364
sh: task utility:mktemp-file TEMPLATE="stylelintrc-schema-XXXXXXXXXX.json"
359-
INSTANCE_PATH: "**/package.json"
365+
INSTANCE_PATH: >-
366+
{{default "." .PROJECT_PATH}}/package.json
360367
PROJECT_FOLDER:
361368
sh: pwd
362369
WORKING_FOLDER:

0 commit comments

Comments
 (0)