From d0d5bcaa639bcf32a1e8821ee1038e450006d851 Mon Sep 17 00:00:00 2001 From: Kirk Rodrigues <2454684+kirkrodrigues@users.noreply.github.com> Date: Wed, 23 Oct 2024 06:33:27 -0400 Subject: [PATCH 1/4] chore: Add Taskfile tasks to lint YAML files. --- .gitmodules | 3 +++ README.md | 38 ++++++++++++++++++++++++++++ Taskfile.yml | 19 ++++++++++++++ lint-requirements.txt | 1 + lint-tasks.yml | 56 ++++++++++++++++++++++++++++++++++++++++++ tools/yscope-dev-utils | 1 + 6 files changed, 118 insertions(+) create mode 100644 .gitmodules create mode 100644 README.md create mode 100644 Taskfile.yml create mode 100644 lint-requirements.txt create mode 100644 lint-tasks.yml create mode 160000 tools/yscope-dev-utils diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 000000000..2d96d0d8e --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "tools/yscope-dev-utils"] + path = tools/yscope-dev-utils + url = https://github.com/y-scope/yscope-dev-utils.git diff --git a/README.md b/README.md new file mode 100644 index 000000000..29901783f --- /dev/null +++ b/README.md @@ -0,0 +1,38 @@ +# Contributing +Follow the steps below to develop and contribute to the project. + +## Requirements +* Python 3 +* [Task] 3.38.0 or higher + +## Set up +Initialize and update submodules: +```shell +git submodule update --init --recursive +``` + +## Linting +Before submitting a pull request, ensure you’ve run the linting commands below and either fixed any +violations or suppressed the warning. + +To run all linting checks: +```shell +task lint:check +``` + +To run all linting checks AND automatically fix any fixable issues: +```shell +task lint:fix +``` + +### Running specific linters +The commands above run all linting checks, but for performance you may want to run a subset (e.g., +if you only changed C++ files, you don't need to run the YAML linting checks) using one of the tasks +in the table below. + +| Task | Description | +|-------------------------|----------------------------------------------------------| +| `lint:yml-check` | Runs the YAML linters. | +| `lint:yml-fix` | Runs the YAML linters and fixes some violations. | + +[Task]: https://taskfile.dev diff --git a/Taskfile.yml b/Taskfile.yml new file mode 100644 index 000000000..d0ff71756 --- /dev/null +++ b/Taskfile.yml @@ -0,0 +1,19 @@ +version: "3" + +includes: + lint: "lint-tasks.yml" + utils: "tools/yscope-dev-utils/taskfiles/utils.yml" + +vars: + G_BUILD_DIR: "{{.ROOT_DIR}}/build" + +tasks: + clean: + cmds: + - "rm -rf '{{.G_BUILD_DIR}}'" + + init: + internal: true + silent: true + run: "once" + cmds: ["mkdir -p '{{.G_BUILD_DIR}}'"] diff --git a/lint-requirements.txt b/lint-requirements.txt new file mode 100644 index 000000000..993e8b4fd --- /dev/null +++ b/lint-requirements.txt @@ -0,0 +1 @@ +yamllint>=1.35.1 diff --git a/lint-tasks.yml b/lint-tasks.yml new file mode 100644 index 000000000..57e1392c0 --- /dev/null +++ b/lint-tasks.yml @@ -0,0 +1,56 @@ +version: "3" + +vars: + G_LINT_VENV_DIR: "{{.G_BUILD_DIR}}/lint-venv" + +tasks: + check: + cmds: + - task: "yml-check" + + fix: + cmds: + - task: "yml-fix" + + yml: + aliases: + - "yml-check" + - "yml-fix" + deps: ["venv"] + cmds: + - |- + . "{{.G_LINT_VENV_DIR}}/bin/activate" + yamllint \ + --config-file "{{.ROOT_DIR}}/tools/yscope-dev-utils/lint-configs/.yamllint.yml" \ + --strict \ + .github \ + lint-tasks.yml \ + Taskfile.yml + + venv: + internal: true + vars: + CHECKSUM_FILE: "{{.G_BUILD_DIR}}/{{.TASK | replace \":\" \"#\"}}.md5" + OUTPUT_DIR: "{{.G_LINT_VENV_DIR}}" + sources: + - "{{.ROOT_DIR}}/Taskfile.yml" + - "{{.TASKFILE}}" + - "lint-requirements.txt" + generates: ["{{.CHECKSUM_FILE}}"] + deps: + - ":init" + - task: ":utils:validate-checksum" + vars: + CHECKSUM_FILE: "{{.CHECKSUM_FILE}}" + DATA_DIR: "{{.OUTPUT_DIR}}" + cmds: + - task: ":utils:create-venv" + vars: + LABEL: "lint" + OUTPUT_DIR: "{{.OUTPUT_DIR}}" + REQUIREMENTS_FILE: "lint-requirements.txt" + # This command must be last + - task: ":utils:compute-checksum" + vars: + DATA_DIR: "{{.OUTPUT_DIR}}" + OUTPUT_FILE: "{{.CHECKSUM_FILE}}" diff --git a/tools/yscope-dev-utils b/tools/yscope-dev-utils new file mode 160000 index 000000000..159768c7d --- /dev/null +++ b/tools/yscope-dev-utils @@ -0,0 +1 @@ +Subproject commit 159768c7d171595ed2cba17b758c10043a2efe96 From ecf16a8de84c0485f361180684872e5ea88f44e9 Mon Sep 17 00:00:00 2001 From: Kirk Rodrigues <2454684+kirkrodrigues@users.noreply.github.com> Date: Wed, 23 Oct 2024 06:39:18 -0400 Subject: [PATCH 2/4] Add .gitignore. --- .gitignore | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..78018ddd6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +# Build-related directories and files +.task +build + +# IDE-related directories and files +.idea From cb36ca25771babcdfe0e649a4b10d33e275b58d8 Mon Sep 17 00:00:00 2001 From: Kirk Rodrigues <2454684+kirkrodrigues@users.noreply.github.com> Date: Wed, 23 Oct 2024 06:48:44 -0400 Subject: [PATCH 3/4] Specify minimum version of Python. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 29901783f..ade08e545 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Follow the steps below to develop and contribute to the project. ## Requirements -* Python 3 +* Python 3.8 or higher * [Task] 3.38.0 or higher ## Set up From bb59b3d1b0d9abef972f5aada350283b21b19629 Mon Sep 17 00:00:00 2001 From: Kirk Rodrigues <2454684+kirkrodrigues@users.noreply.github.com> Date: Wed, 23 Oct 2024 06:58:20 -0400 Subject: [PATCH 4/4] Use exclude-list for yamllint. --- .yamllint.yaml | 5 +++++ lint-tasks.yml | 7 +------ 2 files changed, 6 insertions(+), 6 deletions(-) create mode 100644 .yamllint.yaml diff --git a/.yamllint.yaml b/.yamllint.yaml new file mode 100644 index 000000000..a2a528336 --- /dev/null +++ b/.yamllint.yaml @@ -0,0 +1,5 @@ +extends: "tools/yscope-dev-utils/lint-configs/.yamllint.yml" + +ignore: | + build/ + tools/yscope-dev-utils/ diff --git a/lint-tasks.yml b/lint-tasks.yml index 57e1392c0..2f2ff1492 100644 --- a/lint-tasks.yml +++ b/lint-tasks.yml @@ -20,12 +20,7 @@ tasks: cmds: - |- . "{{.G_LINT_VENV_DIR}}/bin/activate" - yamllint \ - --config-file "{{.ROOT_DIR}}/tools/yscope-dev-utils/lint-configs/.yamllint.yml" \ - --strict \ - .github \ - lint-tasks.yml \ - Taskfile.yml + yamllint --strict . venv: internal: true