Skip to content

Commit b1a469f

Browse files
authored
Merge pull request #60 from per1234/poetry
Use Poetry for Python dependencies management
2 parents c7340de + f465429 commit b1a469f

File tree

7 files changed

+393
-11
lines changed

7 files changed

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

.github/workflows/libraries_report-size-deltas.yml

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,39 @@ jobs:
3030
with:
3131
python-version: '3.11.6'
3232

33+
- name: Install Poetry
34+
run: pip install poetry
35+
3336
- name: Install dependencies
3437
run: |
35-
python -m pip install --upgrade pip
36-
pip install --requirement "${{ env.PYTHON_PROJECT_TESTS_PATH }}/requirements.txt"
38+
poetry install \
39+
--no-root
3740
3841
- name: Lint with flake8
3942
run: |
40-
pip install --quiet flake8
41-
pip install --quiet pep8-naming
42-
flake8 --config "${{ env.PYTHON_PROJECT_PATH }}/.flake8" --show-source "${{ env.PYTHON_PROJECT_PATH }}"
43+
poetry run \
44+
flake8 \
45+
--config "${{ env.PYTHON_PROJECT_PATH }}/.flake8" \
46+
--show-source \
47+
"${{ env.PYTHON_PROJECT_PATH }}"
4348
4449
- name: Run Python unit tests and record code coverage data
4550
run: |
4651
export PYTHONPATH="${{ env.PYTHON_PROJECT_PATH }}"
47-
coverage run --source="${{ env.PYTHON_PROJECT_PATH }}" --module pytest "${{ env.PYTHON_PROJECT_TESTS_PATH }}"
52+
poetry run \
53+
coverage run \
54+
--source="${{ env.PYTHON_PROJECT_PATH }}" \
55+
--module pytest \
56+
"${{ env.PYTHON_PROJECT_TESTS_PATH }}"
4857
# Generate coverage data file for consumption by `codecov/codecov-action`.
49-
coverage xml -o "${{ github.workspace }}/${{ env.COVERAGE_DATA_FILENAME }}"
58+
poetry run \
59+
coverage xml \
60+
-o "${{ github.workspace }}/${{ env.COVERAGE_DATA_FILENAME }}"
5061
5162
- name: Display code coverage report
52-
run: coverage report
63+
run: |
64+
poetry run \
65+
coverage report
5366
5467
# A token is used to avoid intermittent spurious job failures caused by rate limiting.
5568
- name: Set up Codecov upload token

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# `arduino/report-size-deltas` action
22

33
[![Check npm status](https://github.com/arduino/report-size-deltas/actions/workflows/check-npm-task.yml/badge.svg)](https://github.com/arduino/report-size-deltas/actions/workflows/check-npm-task.yml)
4+
[![Check Poetry status](https://github.com/arduino/report-size-deltas/actions/workflows/check-poetry-task.yml/badge.svg)](https://github.com/arduino/report-size-deltas/actions/workflows/check-poetry-task.yml)
45
[![Check Taskfiles status](https://github.com/arduino/report-size-deltas/actions/workflows/check-taskfiles.yml/badge.svg)](https://github.com/arduino/report-size-deltas/actions/workflows/check-taskfiles.yml)
56
[![Tests](https://github.com/arduino/report-size-deltas/workflows/libraries/report-size-deltas%20workflow/badge.svg)](https://github.com/arduino/report-size-deltas/actions?workflow=libraries/report-size-deltas+workflow)
67
[![Integration Tests](https://github.com/arduino/report-size-deltas/actions/workflows/test-integration.yml/badge.svg)](https://github.com/arduino/report-size-deltas/actions/workflows/test-integration.yml)

Taskfile.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,23 @@ tasks:
117117
cmds:
118118
- poetry install --no-root
119119

120+
poetry:sync:
121+
desc: Sync poetry.lock
122+
cmds:
123+
- |
124+
poetry \
125+
lock \
126+
--no-cache \
127+
--no-update
128+
129+
poetry:validate:
130+
desc: Validate pyproject.toml
131+
cmds:
132+
- |
133+
poetry \
134+
check \
135+
--lock
136+
120137
# Make a temporary file named according to the passed TEMPLATE variable and print the path passed to stdout
121138
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
122139
utility:mktemp-file:

0 commit comments

Comments
 (0)