Skip to content

Commit 5f55851

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 187c483 commit 5f55851

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

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

+12-1
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,15 @@ permissions:
3030

3131
jobs:
3232
validate:
33+
name: validate (${{ matrix.project.path }})
3334
runs-on: ubuntu-latest
3435

36+
strategy:
37+
fail-fast: false
38+
matrix:
39+
project:
40+
- path: .
41+
3542
steps:
3643
- name: Checkout repository
3744
uses: actions/checkout@v4
@@ -48,7 +55,11 @@ jobs:
4855
version: 3.x
4956

5057
- name: Validate package.json
51-
run: task --silent npm:validate
58+
run: |
59+
task \
60+
--silent \
61+
npm:validate \
62+
PROJECT_PATH="${{ matrix.project.path }}"
5263
5364
check-sync:
5465
name: check-sync (${{ matrix.project.path }})

Taskfile.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,10 @@ tasks:
252252

253253
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-npm-task/Taskfile.yml
254254
npm:validate:
255-
desc: Validate npm configuration files against their JSON schema
255+
desc: |
256+
Validate npm configuration files against their JSON schema.
257+
Environment variable parameters:
258+
PROJECT_PATH: Path of the npm-managed project (default: {{.DEFAULT_NPM_PROJECT_PATH}}).
256259
vars:
257260
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/package.json
258261
SCHEMA_URL: https://json.schemastore.org/package.json
@@ -294,7 +297,8 @@ tasks:
294297
STYLELINTRC_SCHEMA_URL: https://json.schemastore.org/stylelintrc.json
295298
STYLELINTRC_SCHEMA_PATH:
296299
sh: task utility:mktemp-file TEMPLATE="stylelintrc-schema-XXXXXXXXXX.json"
297-
INSTANCE_PATH: "package.json"
300+
INSTANCE_PATH: >-
301+
{{default .DEFAULT_NPM_PROJECT_PATH .PROJECT_PATH}}/package.json
298302
PROJECT_FOLDER:
299303
sh: pwd
300304
WORKING_FOLDER:

0 commit comments

Comments
 (0)