Skip to content

Commit c7987fb

Browse files
committed
Add support to "Check npm" workflow for projects in subfolders
The "Check npm" workflow checks for problems with the npm configuration files of a repository. Previously this workflow assumed that a repository would only ever have these files in the root folder. However, a repository might also contain multiple separate npm-managed projects in arbitrary subfolders. Support for any repository structure is added to the workflow by using a job matrix to check the projects under an array of arbitrary paths that can be configured for the specific repository the template is installed in.
1 parent 36fc565 commit c7987fb

File tree

5 files changed

+33
-4
lines changed

5 files changed

+33
-4
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,20 @@ jobs:
7777
run: task --silent npm:validate
7878

7979
check-sync:
80+
name: check-sync (${{ matrix.project.path }})
8081
needs: run-determination
8182
if: needs.run-determination.outputs.result == 'true'
8283
runs-on: ubuntu-latest
8384
permissions:
8485
contents: read
8586

87+
strategy:
88+
fail-fast: false
89+
matrix:
90+
project:
91+
# TODO: add paths of all npm-managed projects in the repository here.
92+
- path: .
93+
8694
steps:
8795
- name: Checkout repository
8896
uses: actions/checkout@v4
@@ -99,7 +107,7 @@ jobs:
99107
version: 3.x
100108

101109
- name: Install npm dependencies
102-
run: task npm:install-deps
110+
run: task npm:install-deps PROJECT_PATH="${{ matrix.project.path }}"
103111

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

Taskfile.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,9 +722,13 @@ tasks:
722722
-s "{{.SCHEMA_PATH}}" \
723723
-d "{{.DATA_PATH}}"
724724
725+
# Parameter variables:
726+
# - PROJECT_PATH: path of the npm-managed project. Default value: "./"
725727
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/npm-task/Taskfile.yml
726728
npm:install-deps:
727729
desc: Install dependencies managed by npm
730+
dir: |
731+
"{{default "./" .PROJECT_PATH}}"
728732
cmds:
729733
- npm install
730734

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
version: "3"
33

44
tasks:
5+
# Parameter variables:
6+
# - PROJECT_PATH: path of the npm-managed project. Default value: "./"
57
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/npm-task/Taskfile.yml
68
npm:install-deps:
79
desc: Install dependencies managed by npm
10+
dir: |
11+
"{{default "./" .PROJECT_PATH}}"
812
cmds:
913
- npm install

workflow-templates/check-npm-task.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ Install the [check-npm-task.yml](check-npm-task.yml) GitHub Actions workflow to
2323

2424
Configure the version of Node.js used for development of the project in the `env.NODE_VERSION` field of `check-npm-task.yml`.
2525

26+
If the project contains **npm**-managed projects (i.e., a folder containing a `package.json` file) in paths other than the root of the repository, add their paths to the [job matrices](https://docs.github.com/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix) of `check-npm-task.yml` at:
27+
28+
- `jobs.validate.strategy.matrix.project[].path`
29+
- `jobs.check-sync.strategy.matrix.project[].path`
30+
2631
## Readme badge
2732

2833
Markdown badge:

workflow-templates/check-npm-task.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,20 @@ jobs:
7777
run: task --silent npm:validate
7878

7979
check-sync:
80+
name: check-sync (${{ matrix.project.path }})
8081
needs: run-determination
8182
if: needs.run-determination.outputs.result == 'true'
8283
runs-on: ubuntu-latest
8384
permissions:
8485
contents: read
8586

87+
strategy:
88+
fail-fast: false
89+
matrix:
90+
project:
91+
# TODO: add paths of all npm-managed projects in the repository here.
92+
- path: .
93+
8694
steps:
8795
- name: Checkout repository
8896
uses: actions/checkout@v4
@@ -99,7 +107,7 @@ jobs:
99107
version: 3.x
100108

101109
- name: Install npm dependencies
102-
run: task npm:install-deps
110+
run: task npm:install-deps PROJECT_PATH="${{ matrix.project.path }}"
103111

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

0 commit comments

Comments
 (0)