diff --git a/.github/workflows/check-poetry-task.yml b/.github/workflows/check-poetry-task.yml new file mode 100644 index 00000000..f3dfea7a --- /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 8bb973b3..673bdd38 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 cf38f37f..dd7b4c5b 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 diff --git a/poetry.lock b/poetry.lock index d712e319..eb43353d 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 15d253de..a416e7f7 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"