Skip to content

Commit b7d77f1

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 c7987fb commit b7d77f1

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,20 @@ 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+
# TODO: add paths of all npm-managed projects in the repository here.
67+
- path: .
68+
6169
steps:
6270
- name: Checkout repository
6371
uses: actions/checkout@v4
@@ -74,7 +82,7 @@ jobs:
7482
version: 3.x
7583

7684
- name: Validate package.json
77-
run: task --silent npm:validate
85+
run: task --silent npm:validate PROJECT_PATH="${{ matrix.project.path }}"
7886

7987
check-sync:
8088
name: check-sync (${{ matrix.project.path }})

Taskfile.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,8 @@ tasks:
732732
cmds:
733733
- npm install
734734

735+
# Parameter variables:
736+
# - PROJECT_PATH: path of the npm-managed project. Default value: "./"
735737
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-npm-task/Taskfile.yml
736738
npm:validate:
737739
desc: Validate npm configuration files against their JSON schema
@@ -768,7 +770,8 @@ tasks:
768770
STYLELINTRC_SCHEMA_URL: https://json.schemastore.org/stylelintrc.json
769771
STYLELINTRC_SCHEMA_PATH:
770772
sh: task utility:mktemp-file TEMPLATE="stylelintrc-schema-XXXXXXXXXX.json"
771-
INSTANCE_PATH: "**/package.json"
773+
INSTANCE_PATH: >-
774+
{{default "." .PROJECT_PATH}}/package.json
772775
PROJECT_FOLDER:
773776
sh: pwd
774777
WORKING_FOLDER:

workflow-templates/assets/check-npm-task/Taskfile.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ vars:
66
SCHEMA_DRAFT_4_AJV_CLI_VERSION: 3.3.0
77

88
tasks:
9+
# Parameter variables:
10+
# - PROJECT_PATH: path of the npm-managed project. Default value: "./"
911
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-npm-task/Taskfile.yml
1012
npm:validate:
1113
desc: Validate npm configuration files against their JSON schema
@@ -42,7 +44,8 @@ tasks:
4244
STYLELINTRC_SCHEMA_URL: https://json.schemastore.org/stylelintrc.json
4345
STYLELINTRC_SCHEMA_PATH:
4446
sh: task utility:mktemp-file TEMPLATE="stylelintrc-schema-XXXXXXXXXX.json"
45-
INSTANCE_PATH: "**/package.json"
47+
INSTANCE_PATH: >-
48+
{{default "." .PROJECT_PATH}}/package.json
4649
PROJECT_FOLDER:
4750
sh: pwd
4851
WORKING_FOLDER:

workflow-templates/check-npm-task.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,20 @@ 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+
# TODO: add paths of all npm-managed projects in the repository here.
67+
- path: .
68+
6169
steps:
6270
- name: Checkout repository
6371
uses: actions/checkout@v4
@@ -74,7 +82,7 @@ jobs:
7482
version: 3.x
7583

7684
- name: Validate package.json
77-
run: task --silent npm:validate
85+
run: task --silent npm:validate PROJECT_PATH="${{ matrix.project.path }}"
7886

7987
check-sync:
8088
name: check-sync (${{ matrix.project.path }})

0 commit comments

Comments
 (0)