Skip to content

Commit b19f5ba

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 2b9ae98 commit b19f5ba

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,19 @@ 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: .
67+
6168
steps:
6269
- name: Checkout repository
6370
uses: actions/checkout@v4
@@ -74,15 +81,22 @@ jobs:
7481
version: 3.x
7582

7683
- name: Validate package.json
77-
run: task --silent npm:validate
84+
run: task --silent npm:validate PROJECT_PATH="${{ matrix.project.path }}"
7885

7986
check-sync:
87+
name: check-sync (${{ matrix.project.path }})
8088
needs: run-determination
8189
if: needs.run-determination.outputs.result == 'true'
8290
runs-on: ubuntu-latest
8391
permissions:
8492
contents: read
8593

94+
strategy:
95+
fail-fast: false
96+
matrix:
97+
project:
98+
- path: .
99+
86100
steps:
87101
- name: Checkout repository
88102
uses: actions/checkout@v4
@@ -99,7 +113,7 @@ jobs:
99113
version: 3.x
100114

101115
- name: Install npm dependencies
102-
run: task npm:install-deps
116+
run: task npm:install-deps PROJECT_PATH="${{ matrix.project.path }}"
103117

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

Taskfile.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ tasks:
1010
desc: Check for problems with the project
1111
deps:
1212
- task: npm:validate
13+
- task: general:check-spelling
14+
15+
fix:
16+
desc: Make automated corrections to the project's files
17+
deps:
18+
- task: general:correct-spelling
1319

1420
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/spell-check-task/Taskfile.yml
1521
general:check-spelling:
@@ -27,13 +33,19 @@ tasks:
2733
cmds:
2834
- poetry run codespell --write-changes
2935

36+
# Parameter variables:
37+
# - PROJECT_PATH: path of the npm-managed project. Default value: "./"
3038
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/npm-task/Taskfile.yml
3139
npm:install-deps:
3240
desc: Install dependencies managed by npm
33-
run: once
41+
dir: |
42+
"{{default "./" .PROJECT_PATH}}"
3443
cmds:
3544
- npm install
3645

46+
47+
# Parameter variables:
48+
# - PROJECT_PATH: path of the npm-managed project. Default value: "./"
3749
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-npm-task/Taskfile.yml
3850
npm:validate:
3951
desc: Validate npm configuration files against their JSON schema
@@ -70,7 +82,8 @@ tasks:
7082
STYLELINTRC_SCHEMA_URL: https://json.schemastore.org/stylelintrc.json
7183
STYLELINTRC_SCHEMA_PATH:
7284
sh: task utility:mktemp-file TEMPLATE="stylelintrc-schema-XXXXXXXXXX.json"
73-
INSTANCE_PATH: "**/package.json"
85+
INSTANCE_PATH: >-
86+
{{default "." .PROJECT_PATH}}/package.json
7487
PROJECT_FOLDER:
7588
sh: pwd
7689
WORKING_FOLDER:

0 commit comments

Comments
 (0)