Run CI in parallel jobs with a uv cache #21
2 changed files with 116 additions and 35 deletions
53
.forgejo/actions/setup/action.yaml
Normal file
53
.forgejo/actions/setup/action.yaml
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
name: Set up `velofy`
|
||||
description: Install R, `uv`, `nox`, and `pre-commit`
|
||||
|
||||
|
||||
runs:
|
||||
using: composite
|
||||
|
||||
steps:
|
||||
|
||||
- name: Install R via system packages
|
||||
shell: bash
|
||||
run: |
|
||||
apt-get update
|
||||
apt-get install --no-install-recommends \
|
||||
r-base-dev \
|
||||
r-cran-forecast \
|
||||
r-cran-zoo \
|
||||
-y
|
||||
|
||||
# Built wheels (e.g., `rpy2`) and Python versions
|
||||
# => A new key whenever the pinned dependencies or Python versions change
|
||||
# => Only the "lint" job in ci.yaml saves the cache
|
||||
- name: Restore the `uv` cache
|
||||
id: uv-cache
|
||||
uses: actions/cache/restore@v4
|
||||
with:
|
||||
path: |
|
||||
~/.cache/uv
|
||||
~/.local/share/uv/python
|
||||
key: uv-${{ runner.os }}-${{ hashFiles('uv.lock', 'pyproject.toml') }}
|
||||
restore-keys: uv-${{ runner.os }}-
|
||||
|
||||
# Tell the "lint" job in ci.yaml the key and if it must save the cache
|
||||
- name: Remember the `uv` cache key and if it was restored exactly
|
||||
shell: bash
|
||||
run: |
|
||||
echo "UV_CACHE_KEY=${{ steps.uv-cache.outputs.cache-primary-key }}" >> "$FORGEJO_ENV"
|
||||
echo "UV_CACHE_HIT=${{ steps.uv-cache.outputs.cache-hit }}" >> "$FORGEJO_ENV"
|
||||
|
||||
# All `SUPPORTED_PYTHONS` from the "classifiers" in pyproject.toml
|
||||
# => `nox` would otherwise pick the system's Python without headers
|
||||
- name: Install `uv` and all supported Python versions
|
||||
shell: bash
|
||||
run: |
|
||||
curl -LsSf https://astral.sh/uv/0.13.10/install.sh | sh
|
||||
echo "$HOME/.local/bin" >> "$FORGEJO_PATH"
|
||||
"$HOME/.local/bin/uv" python install $(grep -oP 'Programming Language :: Python :: \K3\.\d+' pyproject.toml)
|
||||
|
||||
# The jobs only use `nox` and `pre-commit` from the develop environment
|
||||
# => The `nox` sessions install `velofy` and its dependencies themselves
|
||||
- name: Install `nox` and `pre-commit`
|
||||
shell: bash
|
||||
run: '"$HOME/.local/bin/uv" sync --locked --only-group dev'
|
||||
|
|
@ -12,13 +12,26 @@ defaults:
|
|||
shell: bash
|
||||
|
||||
|
||||
# Same variables as in `.env` on `nehemiah`, the main development machine
|
||||
env:
|
||||
DATABASE_URI: postgresql://user:password@postgres:5432/db
|
||||
GOOGLE_MAPS_API_KEY: AIzaDummyKeyForTests # Fake key to mock the Google API
|
||||
R_LIBS: /usr/lib/R/site-library
|
||||
UV_NO_SYNC: "1" # Keep `uv run` from installing all groups (see the setup action)
|
||||
UV_PYTHON_PREFERENCE: only-managed # Only uv's Python has the headers to build `rpy2`
|
||||
|
||||
|
||||
jobs:
|
||||
checks:
|
||||
name: Checks (Python 3.14)
|
||||
|
||||
lint:
|
||||
name: Lint
|
||||
runs-on: debian-13
|
||||
|
||||
# Stop hanging jobs (e.g., a test waiting for a database lock)
|
||||
timeout-minutes: 20
|
||||
|
||||
# Throwaway database, reachable from the job as host `postgres`
|
||||
services:
|
||||
services: &database
|
||||
postgres:
|
||||
image: postgres:17
|
||||
env:
|
||||
|
|
@ -32,14 +45,6 @@ jobs:
|
|||
--health-timeout 5s
|
||||
--health-retries 15
|
||||
|
||||
# Same variables as in `.env` on `nehemiah`, the main development machine
|
||||
env:
|
||||
DATABASE_URI: postgresql://user:password@postgres:5432/db
|
||||
GOOGLE_MAPS_API_KEY: AIzaDummyKeyForTests # Fake key to mock the Google API
|
||||
R_LIBS: /usr/lib/R/site-library
|
||||
UV_PYTHON_PREFERENCE: only-managed # Only uv's Python has the headers to build `rpy2`
|
||||
|
||||
|
||||
steps:
|
||||
|
||||
- uses: actions/checkout@v6
|
||||
|
|
@ -50,24 +55,7 @@ jobs:
|
|||
if: forgejo.ref_name != 'develop' && forgejo.ref_name != 'main'
|
||||
run: "! git rev-list --merges origin/develop..HEAD | grep ."
|
||||
|
||||
- name: Install R via system packages
|
||||
run: |
|
||||
apt-get update
|
||||
apt-get install --no-install-recommends \
|
||||
r-base-dev \
|
||||
r-cran-forecast \
|
||||
r-cran-zoo \
|
||||
-y
|
||||
|
||||
# Same `uv` version as pinned in pyproject.toml
|
||||
- name: Install `uv` and `python3.14`
|
||||
run: |
|
||||
curl -LsSf https://astral.sh/uv/0.13.10/install.sh | sh
|
||||
echo "$HOME/.local/bin" >> "$FORGEJO_PATH"
|
||||
"$HOME/.local/bin/uv" python install 3.14
|
||||
|
||||
- name: Install `velofy` and its dependencies
|
||||
run: uv sync --locked
|
||||
- uses: ./.forgejo/actions/setup
|
||||
|
||||
- name: Ensure `nox -s format` changes nothing
|
||||
run: uv run nox -s format && git diff --exit-code
|
||||
|
|
@ -75,16 +63,56 @@ jobs:
|
|||
- name: Lint the source files
|
||||
run: uv run nox -s lint
|
||||
|
||||
- name: Run the test suite
|
||||
run: uv run nox -s test
|
||||
|
||||
- name: Test the code snippets in the docstrings with `xdoctest`
|
||||
run: uv run nox -s test-docstrings
|
||||
|
||||
- name: Check the type annotations at runtime with `typeguard`
|
||||
run: uv run nox -s test-types
|
||||
|
||||
- name: Run the `pre-commit` hooks not covered by `nox`
|
||||
run: uv run pre-commit run --all-files --show-diff-on-failure
|
||||
env:
|
||||
SKIP: local-format,local-lint,local-test,local-test-docstrings,local-test-types,no-commit-to-branch
|
||||
|
||||
# Only this job saves the `uv` cache that ./.forgejo/actions/setup restores
|
||||
# => Keep only what is expensive to rebuild, not wheels that are cheap to download
|
||||
- name: Shrink the `uv` cache
|
||||
if: env.UV_CACHE_HIT != 'true'
|
||||
run: uv cache prune --ci
|
||||
|
||||
- name: Save the `uv` cache
|
||||
if: env.UV_CACHE_HIT != 'true'
|
||||
uses: actions/cache/save@v4
|
||||
with:
|
||||
path: |
|
||||
~/.cache/uv
|
||||
~/.local/share/uv/python
|
||||
key: ${{ env.UV_CACHE_KEY }}
|
||||
|
||||
|
||||
tests:
|
||||
name: Tests (${{ matrix.session }})
|
||||
runs-on: debian-13
|
||||
|
||||
# Stop hanging jobs (e.g., a test waiting for a database lock)
|
||||
timeout-minutes: 20
|
||||
|
||||
# Run the sessions in parallel, each with its own database
|
||||
strategy:
|
||||
matrix:
|
||||
session:
|
||||
- test
|
||||
- test-types
|
||||
# One job per non-main Python version listed in the "classifiers"
|
||||
# in pyproject.toml => Keep in sync manually
|
||||
- test-with-3.13
|
||||
- test-with-3.15
|
||||
|
||||
# Same database as in the "lint" job
|
||||
services: *database
|
||||
|
||||
steps:
|
||||
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- uses: ./.forgejo/actions/setup
|
||||
|
||||
- name: Run the `nox` session
|
||||
run: uv run nox -s ${{ matrix.session }}
|
||||
|
|
|
|||
Loading…
Reference in a new issue