Skip to content
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

ci: Improve workflows #75

Merged
merged 8 commits into from
Sep 3, 2024
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
43 changes: 43 additions & 0 deletions .github/actions/setup-project/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Common Python + Poetry Setup

inputs:
dependency-groups:
description: 'A comma-separated list of dependency groups to install'
default: 'main'
python-version:
description: 'The Python version to use'
default: '3.10'

runs:
using: 'composite'

steps:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}

- name: Install poetry
shell: bash
run: |
python -m pip install poetry
poetry config virtualenvs.in-project true

- name: Get cache key
id: cache-key
shell: bash
run: |
key=$(echo "${{ inputs.dependency-groups }}" | sed 's/,/+/')
echo "key=$key" >> "$GITHUB_OUTPUT"

- name: Load cached venv
id: cache-dependencies
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-python-${{ inputs.python-version }}-groups-${{ steps.cache-key.outputs.key }}-${{ hashFiles('**/poetry.lock') }}

- name: Install dependencies
if: steps.cache-dependencies.outputs.cache-hit != 'true'
shell: bash
run: poetry install --with ${{ inputs.dependency-groups }}
13 changes: 3 additions & 10 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,10 @@ jobs:

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5

- uses: './.github/actions/setup-project'
with:
python-version: '3.10'

- name: Install dependencies
run: |
python -m pip install poetry
poetry config virtualenvs.in-project true
poetry install --with dev
dependency-groups: 'docs'

- name: Build documentation
run: |
Expand Down
15 changes: 4 additions & 11 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,15 @@ on:
push:

jobs:
deploy:
check:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Install dependencies
run: |
python -m pip install poetry
poetry config virtualenvs.in-project true
poetry install --with dev,test
- uses: './.github/actions/setup-project'
with:
dependency-groups: 'dev,test'

- uses: pre-commit/[email protected]

Expand Down
12 changes: 3 additions & 9 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,10 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5

- uses: './.github/actions/setup-project'
with:
python-version: '3.10'

- name: Install dependencies
run: |
python -m pip install poetry
poetry config virtualenvs.in-project true
poetry install --with dev
dependency-groups: 'dev'

- name: Prepare README
run: ./scripts/refactor_readme.py README.md
Expand Down
43 changes: 21 additions & 22 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,16 @@ jobs:

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5

- uses: './.github/actions/setup-project'
with:
python-version: '3.10'

- name: Install dependencies
run: |
python -m pip install poetry
poetry config virtualenvs.in-project true
poetry install --with dev
dependency-groups: 'dev'

- id: supported-versions
name: Get supported versions
run: echo "py-versions=$(poetry run ./scripts/supported_py_versions.py)" >> "$GITHUB_OUTPUT"
run: |
set -e
echo "py-versions=$(poetry run ./scripts/supported_py_versions.py)" >> "$GITHUB_OUTPUT"

test:
runs-on: ubuntu-latest
Expand All @@ -40,18 +35,22 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
- uses: './.github/actions/setup-project'
with:
python-version: "${{ matrix.py-version }}"

- name: Install dependencies
run: |
python -m pip install poetry
poetry config virtualenvs.in-project true

# Only install main dependencies
poetry install --with test
python-version: ${{ matrix.py-version }}
dependency-groups: 'test'

- name: Run unit tests
run: poetry run pytest

results:
runs-on: ubuntu-latest
needs: test
steps:
- run: |
result="${{ needs.test.result }}"
if [[ $result == "success" || $result == "skipped" ]]; then
exit 0
else
exit 1
fi