Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent uncontrolled file tree recursion while validating configuration files #419

Merged
merged 4 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions .github/workflows/check-npm-task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,20 @@ jobs:
echo "result=$RESULT" >> $GITHUB_OUTPUT

validate:
name: validate (${{ matrix.project.path }})
needs: run-determination
if: needs.run-determination.outputs.result == 'true'
runs-on: ubuntu-latest
permissions:
contents: read

strategy:
fail-fast: false
matrix:
project:
# TODO: add paths of all npm-managed projects in the repository here.
- path: .

steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -74,15 +82,23 @@ 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 }})
needs: run-determination
if: needs.run-determination.outputs.result == 'true'
runs-on: ubuntu-latest
permissions:
contents: read

strategy:
fail-fast: false
matrix:
project:
# TODO: add paths of all npm-managed projects in the repository here.
- path: .

steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -99,7 +115,7 @@ jobs:
version: 3.x

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

- name: Check package-lock.json
run: git diff --color --exit-code package-lock.json
run: git diff --color --exit-code "${{ matrix.project.path }}/package-lock.json"
22 changes: 19 additions & 3 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"{{.WORKFLOW_TEMPLATES_PATH}}/test-python-poetry-task.yml" \
"{{.WORKFLOWS_PATH}}"

# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-workflows-task/Taskfile.yml

Check warning on line 75 in Taskfile.yml

View workflow job for this annotation

GitHub Actions / Generate problem matcher output

75:121 [line-length] line too long (131 > 120 characters)
ci:validate:
desc: Validate GitHub Actions workflows against their JSON schema
vars:
Expand Down Expand Up @@ -359,7 +359,10 @@
SCHEMA_URL: https://json.schemastore.org/dependabot-2.0
SCHEMA_PATH:
sh: task utility:mktemp-file TEMPLATE="dependabot-schema-XXXXXXXXXX.json"
DATA_PATH: "**/dependabot.yml"
# The Dependabot configuration file for the repository.
DATA_PATH: ".github/dependabot.yml"
# The asset Dependabot configuration files.
ASSETS_DATA_PATH: "workflow-templates/assets/dependabot/**/dependabot.yml"
PROJECT_FOLDER:
sh: pwd
WORKING_FOLDER:
Expand All @@ -372,6 +375,12 @@
--all-errors \
-s "{{.SCHEMA_PATH}}" \
-d "{{.PROJECT_FOLDER}}/{{.DATA_PATH}}"
- |
cd "{{.WORKING_FOLDER}}" # Workaround for https://github.com/npm/cli/issues/3210
npx ajv-cli@{{.SCHEMA_DRAFT_4_AJV_CLI_VERSION}} validate \
--all-errors \
-s "{{.SCHEMA_PATH}}" \
-d "{{.PROJECT_FOLDER}}/{{.ASSETS_DATA_PATH}}"

docs:generate:
desc: Create all generated documentation content
Expand Down Expand Up @@ -401,7 +410,7 @@
-s "{{.SCHEMA_PATH}}" \
-d "{{.PROJECT_FOLDER}}/{{.DATA_PATH}}"

# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-files-task/Taskfile.yml

Check warning on line 413 in Taskfile.yml

View workflow job for this annotation

GitHub Actions / Generate problem matcher output

413:121 [line-length] line too long (127 > 120 characters)
general:check-filenames:
desc: Check for non-portable filenames
cmds:
Expand Down Expand Up @@ -434,7 +443,7 @@
echo
echo "Prohibited characters found in filenames"
echo "See:"
echo "https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions:~:text=except%20for%20the%20following"

Check warning on line 446 in Taskfile.yml

View workflow job for this annotation

GitHub Actions / Generate problem matcher output

446:121 [line-length] line too long (142 > 120 characters)
false
}
- |
Expand Down Expand Up @@ -467,11 +476,11 @@
echo
echo "Reserved filenames found"
echo "See:"
echo "https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions:~:text=use%20the%20following-,reserved%20names,-for%20the%20name"

Check warning on line 479 in Taskfile.yml

View workflow job for this annotation

GitHub Actions / Generate problem matcher output

479:121 [line-length] line too long (169 > 120 characters)
false
}

# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-general-formatting-task/Taskfile.yml

Check warning on line 483 in Taskfile.yml

View workflow job for this annotation

GitHub Actions / Generate problem matcher output

483:121 [line-length] line too long (140 > 120 characters)
general:check-formatting:
desc: Check basic formatting style of all files
cmds:
Expand All @@ -482,7 +491,7 @@
fi
- ec

# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/spell-check-task/Taskfile.yml

Check warning on line 494 in Taskfile.yml

View workflow job for this annotation

GitHub Actions / Generate problem matcher output

494:121 [line-length] line too long (127 > 120 characters)
general:check-spelling:
desc: Check for commonly misspelled words
deps:
Expand All @@ -490,7 +499,7 @@
cmds:
- poetry run codespell

# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-files-task/Taskfile.yml

Check warning on line 502 in Taskfile.yml

View workflow job for this annotation

GitHub Actions / Generate problem matcher output

502:121 [line-length] line too long (127 > 120 characters)
general:check-symlinks:
desc: Check for bad symlinks
cmds:
Expand All @@ -517,7 +526,7 @@
false
}

# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/spell-check-task/Taskfile.yml

Check warning on line 529 in Taskfile.yml

View workflow job for this annotation

GitHub Actions / Generate problem matcher output

529:121 [line-length] line too long (127 > 120 characters)
general:correct-spelling:
desc: Correct commonly misspelled words where possible
deps:
Expand Down Expand Up @@ -696,7 +705,7 @@
SCHEMA_URL: https://raw.githubusercontent.com/DavidAnson/markdownlint/main/schema/markdownlint-config-schema.json
SCHEMA_PATH:
sh: task utility:mktemp-file TEMPLATE="markdownlint-schema-XXXXXXXXXX.json"
DATA_PATH: "**/.markdownlint.{yml,yaml}"
DATA_PATH: "workflow-templates/assets/check-markdown/.markdownlint.yml"
deps:
- task: npm:install-deps
cmds:
Expand All @@ -713,12 +722,18 @@
-s "{{.SCHEMA_PATH}}" \
-d "{{.DATA_PATH}}"

# Parameter variables:
# - PROJECT_PATH: path of the npm-managed project. Default value: "./"
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/npm-task/Taskfile.yml
npm:install-deps:
desc: Install dependencies managed by npm
dir: |
"{{default "./" .PROJECT_PATH}}"
cmds:
- npm install

# Parameter variables:
# - PROJECT_PATH: path of the npm-managed project. Default value: "./"
# 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
Expand Down Expand Up @@ -755,7 +770,8 @@
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 "." .PROJECT_PATH}}/package.json
PROJECT_FOLDER:
sh: pwd
WORKING_FOLDER:
Expand Down
5 changes: 4 additions & 1 deletion workflow-templates/assets/check-npm-task/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ vars:
SCHEMA_DRAFT_4_AJV_CLI_VERSION: 3.3.0

tasks:
# Parameter variables:
# - PROJECT_PATH: path of the npm-managed project. Default value: "./"
# 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
Expand Down Expand Up @@ -42,7 +44,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 "." .PROJECT_PATH}}/package.json
PROJECT_FOLDER:
sh: pwd
WORKING_FOLDER:
Expand Down
4 changes: 4 additions & 0 deletions workflow-templates/assets/npm-task/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
version: "3"

tasks:
# Parameter variables:
# - PROJECT_PATH: path of the npm-managed project. Default value: "./"
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/npm-task/Taskfile.yml
npm:install-deps:
desc: Install dependencies managed by npm
dir: |
"{{default "./" .PROJECT_PATH}}"
cmds:
- npm install
5 changes: 5 additions & 0 deletions workflow-templates/check-npm-task.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ Install the [check-npm-task.yml](check-npm-task.yml) GitHub Actions workflow to

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

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:

- `jobs.validate.strategy.matrix.project[].path`
- `jobs.check-sync.strategy.matrix.project[].path`

## Readme badge

Markdown badge:
Expand Down
22 changes: 19 additions & 3 deletions workflow-templates/check-npm-task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,20 @@ jobs:
echo "result=$RESULT" >> $GITHUB_OUTPUT

validate:
name: validate (${{ matrix.project.path }})
needs: run-determination
if: needs.run-determination.outputs.result == 'true'
runs-on: ubuntu-latest
permissions:
contents: read

strategy:
fail-fast: false
matrix:
project:
# TODO: add paths of all npm-managed projects in the repository here.
- path: .

steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -74,15 +82,23 @@ 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 }})
needs: run-determination
if: needs.run-determination.outputs.result == 'true'
runs-on: ubuntu-latest
permissions:
contents: read

strategy:
fail-fast: false
matrix:
project:
# TODO: add paths of all npm-managed projects in the repository here.
- path: .

steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -99,7 +115,7 @@ jobs:
version: 3.x

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

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