Skip to content

Commit 0e986a4

Browse files
authored
Merge pull request #419 from per1234/avoid-uncontrolled-recursion
Prevent uncontrolled file tree recursion while validating configuration files
2 parents ce4ee80 + b7d77f1 commit 0e986a4

File tree

6 files changed

+70
-10
lines changed

6 files changed

+70
-10
lines changed

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

Lines changed: 19 additions & 3 deletions
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,15 +82,23 @@ 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:
88+
name: check-sync (${{ matrix.project.path }})
8089
needs: run-determination
8190
if: needs.run-determination.outputs.result == 'true'
8291
runs-on: ubuntu-latest
8392
permissions:
8493
contents: read
8594

95+
strategy:
96+
fail-fast: false
97+
matrix:
98+
project:
99+
# TODO: add paths of all npm-managed projects in the repository here.
100+
- path: .
101+
86102
steps:
87103
- name: Checkout repository
88104
uses: actions/checkout@v4
@@ -99,7 +115,7 @@ jobs:
99115
version: 3.x
100116

101117
- name: Install npm dependencies
102-
run: task npm:install-deps
118+
run: task npm:install-deps PROJECT_PATH="${{ matrix.project.path }}"
103119

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

Taskfile.yml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,10 @@ tasks:
359359
SCHEMA_URL: https://json.schemastore.org/dependabot-2.0
360360
SCHEMA_PATH:
361361
sh: task utility:mktemp-file TEMPLATE="dependabot-schema-XXXXXXXXXX.json"
362-
DATA_PATH: "**/dependabot.yml"
362+
# The Dependabot configuration file for the repository.
363+
DATA_PATH: ".github/dependabot.yml"
364+
# The asset Dependabot configuration files.
365+
ASSETS_DATA_PATH: "workflow-templates/assets/dependabot/**/dependabot.yml"
363366
PROJECT_FOLDER:
364367
sh: pwd
365368
WORKING_FOLDER:
@@ -372,6 +375,12 @@ tasks:
372375
--all-errors \
373376
-s "{{.SCHEMA_PATH}}" \
374377
-d "{{.PROJECT_FOLDER}}/{{.DATA_PATH}}"
378+
- |
379+
cd "{{.WORKING_FOLDER}}" # Workaround for https://github.com/npm/cli/issues/3210
380+
npx ajv-cli@{{.SCHEMA_DRAFT_4_AJV_CLI_VERSION}} validate \
381+
--all-errors \
382+
-s "{{.SCHEMA_PATH}}" \
383+
-d "{{.PROJECT_FOLDER}}/{{.ASSETS_DATA_PATH}}"
375384
376385
docs:generate:
377386
desc: Create all generated documentation content
@@ -696,7 +705,7 @@ tasks:
696705
SCHEMA_URL: https://raw.githubusercontent.com/DavidAnson/markdownlint/main/schema/markdownlint-config-schema.json
697706
SCHEMA_PATH:
698707
sh: task utility:mktemp-file TEMPLATE="markdownlint-schema-XXXXXXXXXX.json"
699-
DATA_PATH: "**/.markdownlint.{yml,yaml}"
708+
DATA_PATH: "workflow-templates/assets/check-markdown/.markdownlint.yml"
700709
deps:
701710
- task: npm:install-deps
702711
cmds:
@@ -713,12 +722,18 @@ tasks:
713722
-s "{{.SCHEMA_PATH}}" \
714723
-d "{{.DATA_PATH}}"
715724
725+
# Parameter variables:
726+
# - PROJECT_PATH: path of the npm-managed project. Default value: "./"
716727
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/npm-task/Taskfile.yml
717728
npm:install-deps:
718729
desc: Install dependencies managed by npm
730+
dir: |
731+
"{{default "./" .PROJECT_PATH}}"
719732
cmds:
720733
- npm install
721734

735+
# Parameter variables:
736+
# - PROJECT_PATH: path of the npm-managed project. Default value: "./"
722737
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-npm-task/Taskfile.yml
723738
npm:validate:
724739
desc: Validate npm configuration files against their JSON schema
@@ -755,7 +770,8 @@ tasks:
755770
STYLELINTRC_SCHEMA_URL: https://json.schemastore.org/stylelintrc.json
756771
STYLELINTRC_SCHEMA_PATH:
757772
sh: task utility:mktemp-file TEMPLATE="stylelintrc-schema-XXXXXXXXXX.json"
758-
INSTANCE_PATH: "**/package.json"
773+
INSTANCE_PATH: >-
774+
{{default "." .PROJECT_PATH}}/package.json
759775
PROJECT_FOLDER:
760776
sh: pwd
761777
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/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: 19 additions & 3 deletions
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,15 +82,23 @@ 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:
88+
name: check-sync (${{ matrix.project.path }})
8089
needs: run-determination
8190
if: needs.run-determination.outputs.result == 'true'
8291
runs-on: ubuntu-latest
8392
permissions:
8493
contents: read
8594

95+
strategy:
96+
fail-fast: false
97+
matrix:
98+
project:
99+
# TODO: add paths of all npm-managed projects in the repository here.
100+
- path: .
101+
86102
steps:
87103
- name: Checkout repository
88104
uses: actions/checkout@v4
@@ -99,7 +115,7 @@ jobs:
99115
version: 3.x
100116

101117
- name: Install npm dependencies
102-
run: task npm:install-deps
118+
run: task npm:install-deps PROJECT_PATH="${{ matrix.project.path }}"
103119

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

0 commit comments

Comments
 (0)