From 5f5585117baa815e7e98f55c1328db8ddee186ce Mon Sep 17 00:00:00 2001 From: per1234 Date: Wed, 12 Mar 2025 04:43:46 -0700 Subject: [PATCH] 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. --- .github/workflows/check-npm-task.yml | 13 ++++++++++++- Taskfile.yml | 8 ++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/.github/workflows/check-npm-task.yml b/.github/workflows/check-npm-task.yml index 5ea5e21..c14ec5a 100644 --- a/.github/workflows/check-npm-task.yml +++ b/.github/workflows/check-npm-task.yml @@ -30,8 +30,15 @@ permissions: jobs: validate: + name: validate (${{ matrix.project.path }}) runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + project: + - path: . + steps: - name: Checkout repository uses: actions/checkout@v4 @@ -48,7 +55,11 @@ jobs: version: 3.x - name: Validate package.json - run: task --silent npm:validate + run: | + task \ + --silent \ + npm:validate \ + PROJECT_PATH="${{ matrix.project.path }}" check-sync: name: check-sync (${{ matrix.project.path }}) diff --git a/Taskfile.yml b/Taskfile.yml index e188e9f..f4c1fc0 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -252,7 +252,10 @@ tasks: # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-npm-task/Taskfile.yml npm:validate: - desc: Validate npm configuration files against their JSON schema + desc: | + Validate npm configuration files against their JSON schema. + Environment variable parameters: + PROJECT_PATH: Path of the npm-managed project (default: {{.DEFAULT_NPM_PROJECT_PATH}}). vars: # Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/package.json SCHEMA_URL: https://json.schemastore.org/package.json @@ -294,7 +297,8 @@ tasks: STYLELINTRC_SCHEMA_URL: https://json.schemastore.org/stylelintrc.json STYLELINTRC_SCHEMA_PATH: sh: task utility:mktemp-file TEMPLATE="stylelintrc-schema-XXXXXXXXXX.json" - INSTANCE_PATH: "package.json" + INSTANCE_PATH: >- + {{default .DEFAULT_NPM_PROJECT_PATH .PROJECT_PATH}}/package.json PROJECT_FOLDER: sh: pwd WORKING_FOLDER: