From 00550f9eab62cbc447e9160667f03a25c5c277d7 Mon Sep 17 00:00:00 2001 From: per1234 Date: Mon, 8 Sep 2025 07:00:01 -0700 Subject: [PATCH 1/2] Add infrastructure for checking Poetry configuration files The project's Python package dependencies are managed using the "Poetry" tool. Tasks and a GitHub Actions workflow are added to maintain and check for problems in the Poetry configuration files. The tasks provide the following operations: * Check for problems with the data structure of the `pyproject.toml` Python project file * Update the `poetry.lock` file as may be required following manual modifications to `pyproject.toml`, or update of the "Poetry" application A GitHub Actions workflow is included to automatically run the tasks. The workflow is triggered on any push or pull that changes relevant project files, in order to avoid the introduction of problems with the project filesystem. It is also triggered periodically, in order to catch breakage caused by external changes. --- .github/workflows/check-poetry-task.yml | 119 ++++++++++++++++++++++++ README.md | 1 + Taskfile.yml | 23 +++++ 3 files changed, 143 insertions(+) create mode 100644 .github/workflows/check-poetry-task.yml diff --git a/.github/workflows/check-poetry-task.yml b/.github/workflows/check-poetry-task.yml new file mode 100644 index 000000000..f3dfea7ae --- /dev/null +++ b/.github/workflows/check-poetry-task.yml @@ -0,0 +1,119 @@ +# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-poetry-task.md +name: Check Poetry + +on: + create: + push: + paths: + - ".github/workflows/check-poetry-task.ya?ml" + - "go.mod" + - "go.sum" + - "poetry.lock" + - "pyproject.toml" + - "Taskfile.ya?ml" + pull_request: + paths: + - ".github/workflows/check-poetry-task.ya?ml" + - "go.mod" + - "go.sum" + - "poetry.lock" + - "pyproject.toml" + - "Taskfile.ya?ml" + schedule: + # Run periodically to catch breakage caused by external changes. + - cron: "0 11 * * THU" + workflow_dispatch: + repository_dispatch: + +jobs: + run-determination: + runs-on: ubuntu-latest + permissions: {} + outputs: + result: ${{ steps.determination.outputs.result }} + steps: + - name: Determine if the rest of the workflow should run + id: determination + run: | + RELEASE_BRANCH_REGEX="^refs/heads/((v[0-9]+)|([0-9]+\.[0-9]+\.x))$" + # The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead. + if [[ + "${{ github.event_name }}" != "create" || + "${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX + ]]; then + # Run the other jobs. + RESULT="true" + else + # There is no need to run the other jobs. + RESULT="false" + fi + + echo "result=$RESULT" >>$GITHUB_OUTPUT + + validate: + needs: run-determination + if: needs.run-determination.outputs.result == 'true' + runs-on: ubuntu-latest + permissions: + contents: read + + steps: + - name: Checkout repository + uses: actions/checkout@v5 + + - name: Install Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + - name: Install Python + uses: actions/setup-python@v5 + with: + python-version-file: pyproject.toml + + - name: Install Task + uses: arduino/setup-task@v2 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + version: 3.x + + - name: Validate configuration + run: | + task \ + --silent \ + poetry:validate + + check-sync: + needs: run-determination + if: needs.run-determination.outputs.result == 'true' + runs-on: ubuntu-latest + permissions: + contents: read + + steps: + - name: Checkout repository + uses: actions/checkout@v5 + + - name: Install Python + uses: actions/setup-python@v5 + with: + python-version-file: pyproject.toml + + - name: Install Task + uses: arduino/setup-task@v2 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + version: 3.x + + - name: Sync lockfile + run: | + task \ + --silent \ + poetry:sync + + - name: Check if lockfile was out of sync + run: | + git diff \ + --color \ + --exit-code \ + poetry.lock diff --git a/README.md b/README.md index 8bb973b32..673bdd382 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ [![Publish Tester Build status](https://github.com/arduino/arduino-lint/actions/workflows/publish-go-tester-task.yml/badge.svg)](https://github.com/arduino/arduino-lint/actions/workflows/publish-go-tester-task.yml) [![Publish Nightly Build status](https://github.com/arduino/arduino-lint/actions/workflows/publish-go-nightly-task.yml/badge.svg)](https://github.com/arduino/arduino-lint/actions/workflows/publish-go-nightly-task.yml) [![Check npm status](https://github.com/arduino/arduino-lint/actions/workflows/check-npm-task.yml/badge.svg)](https://github.com/arduino/arduino-lint/actions/workflows/check-npm-task.yml) +[![Check Poetry status](https://github.com/arduino/arduino-lint/actions/workflows/check-poetry-task.yml/badge.svg)](https://github.com/arduino/arduino-lint/actions/workflows/check-poetry-task.yml) [![Check Python status](https://github.com/arduino/arduino-lint/actions/workflows/check-python-task.yml/badge.svg)](https://github.com/arduino/arduino-lint/actions/workflows/check-python-task.yml) [![Check Markdown status](https://github.com/arduino/arduino-lint/actions/workflows/check-markdown-task.yml/badge.svg)](https://github.com/arduino/arduino-lint/actions/workflows/check-markdown-task.yml) [![Spell Check status](https://github.com/arduino/arduino-lint/actions/workflows/spell-check-task.yml/badge.svg)](https://github.com/arduino/arduino-lint/actions/workflows/spell-check-task.yml) diff --git a/Taskfile.yml b/Taskfile.yml index cf38f37ff..dd7b4c5b9 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -104,6 +104,7 @@ tasks: GO_MODULE_PATH: ./ruledocsgen - task: markdown:lint - task: markdown:check-links + - task: poetry:validate - task: python:lint - task: shell:check vars: @@ -142,6 +143,7 @@ tasks: GO_MODULE_PATH: ./ruledocsgen - task: markdown:fix - task: npm:fix-config + - task: poetry:sync - task: python:format - task: shell:format vars: @@ -664,6 +666,16 @@ tasks: poetry install \ {{if .POETRY_GROUPS}} --only {{.POETRY_GROUPS}} {{end}} + # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-poetry-task/Taskfile.yml + poetry:sync: + desc: Sync Poetry lockfile + deps: + - task: poetry:install + cmds: + - | + poetry lock \ + --no-cache + # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/poetry-task/Taskfile.yml poetry:update-deps: desc: Update all dependencies managed by Poetry to their newest versions @@ -672,6 +684,17 @@ tasks: cmds: - poetry update + # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-poetry-task/Taskfile.yml + poetry:validate: + desc: Validate Poetry configuration + deps: + - task: poetry:install + cmds: + - | + poetry check \ + --lock \ + --strict + # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-python-task/Taskfile.yml python:format: desc: Format Python files From 786f70b807adea8fdbfc8771da4a0b4c08f736cd Mon Sep 17 00:00:00 2001 From: per1234 Date: Mon, 8 Sep 2025 07:27:35 -0700 Subject: [PATCH 2/2] Migrate Poetry configuration from deprecated `tool.poetry.dev-dependencies` table Originally Poetry supported two distinct dependency types, each defined separately in the `pyproject.toml` file: * main: defined under the `tool.poetry.dependencies` table * dev: defined under the `tool.poetry.dev-dependencies` table This concept of dependency types was later made more flexible by allowing the user to define any number of arbitrary dependency "groups", with "dev" simply being one of those groups. A new table naming scheme was created to support this flexible dependency groups system. For the sake of backwards compatibility, Poetry does still support use of the `tool.poetry.dev-dependencies` table. However, it is deprecated and its use results in a warning. The project's Poetry configuration is hereby migrated to the modern format. --- poetry.lock | 4 ++-- pyproject.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/poetry.lock b/poetry.lock index d712e3196..eb43353d6 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 2.1.3 and should not be changed by hand. +# This file is automatically @generated by Poetry 2.1.4 and should not be changed by hand. [[package]] name = "anyio" @@ -2253,4 +2253,4 @@ cffi = ["cffi (>=1.17) ; python_version >= \"3.13\" and platform_python_implemen [metadata] lock-version = "2.1" python-versions = "~3.9" -content-hash = "127a59a7f71ef529856f463fbed9d4b060ac7c3ec23a1968471542076aa01e22" +content-hash = "f93a8d0391f7e7307aeac48fd1accc13281873501c79db3ce32e3aee7db691b2" diff --git a/pyproject.toml b/pyproject.toml index 15d253dec..a416e7f71 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,7 @@ poetry = "2.1.4" [tool.poetry.dependencies] python = "~3.9" -[tool.poetry.dev-dependencies] +[tool.poetry.group.dev.dependencies] black = "^25.1" codespell = "^2.4.1" flake8 = "^7.3.0"