Skip to content

Commit d70b760

Browse files
committed
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 These tasks are executed by the GitHub Actions workflow on any push or pull request that modifies relevant files, and periodically to check for breakage caused by external changes.
1 parent 3290c6c commit d70b760

File tree

3 files changed

+128
-0
lines changed

3 files changed

+128
-0
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
name: Check Poetry
2+
3+
on:
4+
create:
5+
push:
6+
paths:
7+
- ".github/workflows/check-poetry-task.ya?ml"
8+
- "poetry.lock"
9+
- "pyproject.toml"
10+
- "Taskfile.ya?ml"
11+
pull_request:
12+
paths:
13+
- ".github/workflows/check-poetry-task.ya?ml"
14+
- "poetry.lock"
15+
- "pyproject.toml"
16+
- "Taskfile.ya?ml"
17+
schedule:
18+
# Run periodically to catch breakage caused by external changes.
19+
- cron: "0 11 * * THU"
20+
workflow_dispatch:
21+
repository_dispatch:
22+
23+
jobs:
24+
run-determination:
25+
runs-on: ubuntu-latest
26+
permissions: {}
27+
outputs:
28+
result: ${{ steps.determination.outputs.result }}
29+
steps:
30+
- name: Determine if the rest of the workflow should run
31+
id: determination
32+
run: |
33+
RELEASE_BRANCH_REGEX="^refs/heads/((v[0-9]+)|([0-9]+\.[0-9]+\.x))$"
34+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
35+
if [[
36+
"${{ github.event_name }}" != "create" ||
37+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
38+
]]; then
39+
# Run the other jobs.
40+
RESULT="true"
41+
else
42+
# There is no need to run the other jobs.
43+
RESULT="false"
44+
fi
45+
46+
echo "result=$RESULT" >> $GITHUB_OUTPUT
47+
48+
validate:
49+
needs: run-determination
50+
if: needs.run-determination.outputs.result == 'true'
51+
runs-on: ubuntu-latest
52+
permissions:
53+
contents: read
54+
55+
steps:
56+
- name: Checkout repository
57+
uses: actions/checkout@v4
58+
59+
- name: Install Python
60+
uses: actions/setup-python@v5
61+
with:
62+
python-version-file: pyproject.toml
63+
64+
- name: Install Task
65+
uses: arduino/setup-task@v2
66+
with:
67+
repo-token: ${{ secrets.GITHUB_TOKEN }}
68+
version: 3.x
69+
70+
- name: Validate pyproject.toml
71+
run: |
72+
task \
73+
--silent \
74+
poetry:validate
75+
76+
check-sync:
77+
needs: run-determination
78+
if: needs.run-determination.outputs.result == 'true'
79+
runs-on: ubuntu-latest
80+
permissions:
81+
contents: read
82+
83+
steps:
84+
- name: Checkout repository
85+
uses: actions/checkout@v4
86+
87+
- name: Install Python
88+
uses: actions/setup-python@v5
89+
with:
90+
python-version-file: pyproject.toml
91+
92+
- name: Install Task
93+
uses: arduino/setup-task@v2
94+
with:
95+
repo-token: ${{ secrets.GITHUB_TOKEN }}
96+
version: 3.x
97+
98+
- name: Sync lockfile
99+
run: |
100+
task \
101+
--silent \
102+
poetry:sync
103+
104+
- name: Check if lockfile was out of sync
105+
run: |
106+
git diff \
107+
--color \
108+
--exit-code \
109+
poetry.lock

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
[![Check Prettier Formatting status](https://github.com/arduino/arduinoOTA/actions/workflows/check-prettier-formatting-task.yml/badge.svg)](https://github.com/arduino/arduinoOTA/actions/workflows/check-prettier-formatting-task.yml)
88
[![Spell Check status](https://github.com/arduino/arduinoOTA/actions/workflows/spell-check-task.yml/badge.svg)](https://github.com/arduino/arduinoOTA/actions/workflows/spell-check-task.yml)
99
[![Check Markdown status](https://github.com/arduino/arduinoOTA/actions/workflows/check-markdown-task.yml/badge.svg)](https://github.com/arduino/arduinoOTA/actions/workflows/check-markdown-task.yml)
10+
[![Check Poetry status](https://github.com/arduino/arduinoOTA/actions/workflows/check-poetry-task.yml/badge.svg)](https://github.com/arduino/arduinoOTA/actions/workflows/check-poetry-task.yml)
1011
[![Check Taskfiles status](https://github.com/arduino/arduinoOTA/actions/workflows/check-taskfiles.yml/badge.svg)](https://github.com/arduino/arduinoOTA/actions/workflows/check-taskfiles.yml)
1112
[![Check Workflows status](https://github.com/arduino/arduinoOTA/actions/workflows/check-workflows-task.yml/badge.svg)](https://github.com/arduino/arduinoOTA/actions/workflows/check-workflows-task.yml)
1213
[![Check YAML status](https://github.com/arduino/arduinoOTA/actions/workflows/check-yaml-task.yml/badge.svg)](https://github.com/arduino/arduinoOTA/actions/workflows/check-yaml-task.yml)

Taskfile.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,24 @@ tasks:
385385
poetry install \
386386
{{if .POETRY_GROUPS}} --only {{.POETRY_GROUPS}} {{end}}
387387
388+
poetry:sync:
389+
desc: Sync poetry.lock
390+
deps:
391+
- task: poetry:install
392+
cmds:
393+
- |
394+
poetry lock \
395+
--no-cache
396+
397+
poetry:validate:
398+
desc: Validate pyproject.toml
399+
deps:
400+
- task: poetry:install
401+
cmds:
402+
- |
403+
poetry check \
404+
--lock
405+
388406
# Make a temporary file named according to the passed TEMPLATE variable and print the path passed to stdout
389407
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
390408
utility:mktemp-file:

0 commit comments

Comments
 (0)