Skip to content

Use Poetry for Python dependencies management #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions .github/workflows/check-poetry-task.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
name: Check Poetry

env:
# See: https://github.com/actions/setup-python/tree/main#available-versions-of-python
PYTHON_VERSION: "3.11"

on:
create:
push:
paths:
- ".github/workflows/check-poetry-task.ya?ml"
- "**/poetry.lock"
- "**/pyproject.toml"
- "Taskfile.ya?ml"
pull_request:
paths:
- ".github/workflows/check-poetry-task.ya?ml"
- "**/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]+$"
# 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@v4

- name: Install Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install Poetry
run: pip install poetry

- name: Install Task
uses: arduino/setup-task@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
version: 3.x

- name: Validate pyproject.toml
run: task 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@v4

- name: Install Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install Poetry
run: pip install poetry

- name: Install Task
uses: arduino/setup-task@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
version: 3.x

- name: Sync lockfile
run: task poetry:sync

- name: Check if lockfile was out of sync
run: |
git \
diff \
--color \
--exit-code \
poetry.lock
29 changes: 21 additions & 8 deletions .github/workflows/libraries_report-size-deltas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,39 @@ jobs:
with:
python-version: '3.11.6'

- name: Install Poetry
run: pip install poetry

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --requirement "${{ env.PYTHON_PROJECT_TESTS_PATH }}/requirements.txt"
poetry install \
--no-root

- name: Lint with flake8
run: |
pip install --quiet flake8
pip install --quiet pep8-naming
flake8 --config "${{ env.PYTHON_PROJECT_PATH }}/.flake8" --show-source "${{ env.PYTHON_PROJECT_PATH }}"
poetry run \
flake8 \
--config "${{ env.PYTHON_PROJECT_PATH }}/.flake8" \
--show-source \
"${{ env.PYTHON_PROJECT_PATH }}"

- name: Run Python unit tests and record code coverage data
run: |
export PYTHONPATH="${{ env.PYTHON_PROJECT_PATH }}"
coverage run --source="${{ env.PYTHON_PROJECT_PATH }}" --module pytest "${{ env.PYTHON_PROJECT_TESTS_PATH }}"
poetry run \
coverage run \
--source="${{ env.PYTHON_PROJECT_PATH }}" \
--module pytest \
"${{ env.PYTHON_PROJECT_TESTS_PATH }}"
# Generate coverage data file for consumption by `codecov/codecov-action`.
coverage xml -o "${{ github.workspace }}/${{ env.COVERAGE_DATA_FILENAME }}"
poetry run \
coverage xml \
-o "${{ github.workspace }}/${{ env.COVERAGE_DATA_FILENAME }}"

- name: Display code coverage report
run: coverage report
run: |
poetry run \
coverage report

# A token is used to avoid intermittent spurious job failures caused by rate limiting.
- name: Set up Codecov upload token
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# `arduino/report-size-deltas` action

[![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)
[![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)
[![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)
[![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)
[![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)
Expand Down
17 changes: 17 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,23 @@ tasks:
cmds:
- poetry install --no-root

poetry:sync:
desc: Sync poetry.lock
cmds:
- |
poetry \
lock \
--no-cache \
--no-update

poetry:validate:
desc: Validate pyproject.toml
cmds:
- |
poetry \
check \
--lock

# Make a temporary file named according to the passed TEMPLATE variable and print the path passed to stdout
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
utility:mktemp-file:
Expand Down
Loading