Skip to content

ci: bump ReadTheDocs build to ubuntu-24.04 and Python 3.12 (#146) #576

ci: bump ReadTheDocs build to ubuntu-24.04 and Python 3.12 (#146)

ci: bump ReadTheDocs build to ubuntu-24.04 and Python 3.12 (#146) #576

name: CI/CD Pipeline
on:
release:
types: [published]
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
inputs:
force_radas_rebuild:
description: "Regenerate radas_dir and overwrite the cached data (use when a dependency bump changed radas output and regression tests fail)"
type: boolean
default: false
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
# --- JOB 1: GENERATE RADAS DATA ---
radas:
name: Generate Radas Data
runs-on: ubuntu-latest
permissions:
contents: read
actions: write # allow deleting the cache entry on a forced rebuild
outputs:
cache-key: ${{ steps.radas-key.outputs.key }}
steps:
- uses: actions/checkout@v6
- name: Install Poetry
run: pipx install "poetry>=2,<3"
- name: Set up Python 3.12
uses: actions/setup-python@v6
with:
python-version: '3.12'
cache: 'poetry'
- name: Install dependencies
run: poetry install
# The radas output depends on the radas package version and
# radas_config.yaml, so key the cache on those rather than the whole
# poetry.lock (which busts on every unrelated dependency bump).
# N.b. it is possible that bumping some dependencies could change the
# radas result enough to affect the regression result. You might need
# manually regenerate the radas_dir in this case.
- name: Compute radas cache key
id: radas-key
run: |
radas_version=$(grep -A1 '^name = "radas"$' poetry.lock | grep '^version' | sed -E 's/.*"(.*)".*/\1/')
echo "key=radas-v${radas_version//!/-}-${{ hashFiles('radas_config.yaml') }}" >> "$GITHUB_OUTPUT"
# On a manual run with force_radas_rebuild, delete any existing cache
# entry for this key so the freshly generated data is saved in its place
# (actions/cache will not overwrite an existing key otherwise).
- name: Delete existing radas cache
if: ${{ github.event_name == 'workflow_dispatch' && inputs.force_radas_rebuild }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh cache delete "${{ steps.radas-key.outputs.key }}" --repo "${{ github.repository }}" \
|| echo "No existing cache for this key; fresh data will be generated."
- name: Cache radas results
id: radas-cache
uses: actions/cache@v5
with:
path: ./radas_dir
key: ${{ steps.radas-key.outputs.key }}
- name: Make radas data
if: steps.radas-cache.outputs.cache-hit != 'true'
run: poetry run radas -c radas_config.yaml
- name: Upload radas artifacts
uses: actions/upload-artifact@v7
with:
name: radas_dir
path: ./radas_dir
retention-days: 30
# --- JOB 2: TEST ---
# The heavy work: unit tests, regression tests and the packaged smoke test,
# run across the supported Python versions. Needs the radas data.
test:
name: Test (Python ${{ matrix.python-version }})
needs: radas
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ['3.12', '3.13', '3.14']
steps:
- uses: actions/checkout@v6
- name: Install Poetry
run: pipx install "poetry>=2,<3"
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
cache: 'poetry'
- name: Install dependencies
run: poetry install
- name: Restore radas data
uses: actions/cache/restore@v5
id: radas-restore
with:
path: ./radas_dir
key: ${{ needs.radas.outputs.cache-key }}
- name: Verify Cache
if: steps.radas-restore.outputs.cache-hit != 'true'
run: exit 1
- name: Run Tests
env:
MPLBACKEND: Agg
run: poetry run pytest tests --nbmake example_cases -m "not docs"
- name: Regression Tests
env:
MPLBACKEND: Agg
run: |
poetry run python tests/utils/regression_results.py
poetry run pytest --no-cov tests/test_regression_against_cases.py
- name: Upload regression results on failure
uses: actions/upload-artifact@v7
if: failure()
with:
name: regression_results-${{ matrix.python-version }}
path: tests/regression_results
- name: Smoke test package
env:
MPLBACKEND: Agg
run: |
poetry build -f wheel
python -m venv test_env
source test_env/bin/activate
pip install dist/*.whl
mkdir tmp_dir && cd tmp_dir
popcon ../example_cases/SPARC_PRD -d radas_dir WORKING_DIR/../radas_dir
# --- JOB 3: LINT ---
# pre-commit (ruff, mypy, variable-consistency check). Independent of the
# radas data, so it runs in parallel with everything else for fast feedback.
lint:
name: Lint (pre-commit)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Install Poetry
run: pipx install "poetry>=2,<3"
- name: Set up Python 3.12
uses: actions/setup-python@v6
with:
python-version: '3.12'
cache: 'poetry'
- name: Install dependencies
run: poetry install
- name: Pre-commit checks
run: poetry run pre-commit run --show-diff-on-failure --color=always --all-files
# --- JOB 4: DOCUMENTATION ---
# Sphinx build (warnings as errors), doctests and linkcheck. Notebooks are
# not executed (nbsphinx_execute = "never"), so this is independent of the
# radas data and runs in parallel with everything else.
docs:
name: Documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y pandoc
- name: Install Poetry
run: pipx install "poetry>=2,<3"
- name: Set up Python 3.12
uses: actions/setup-python@v6
with:
python-version: '3.12'
cache: 'poetry'
- name: Install dependencies
run: poetry install
- name: Documentation tests
run: |
cd docs
poetry run sphinx-build --keep-going -Wnb html . _build/
poetry run make doctest
poetry run make linkcheck
# --- JOB 5: PREPARE RELEASE ---
build_release:
name: Build Release
if: startsWith(github.ref, 'refs/tags')
needs: [test, lint, docs]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Install Poetry
run: pipx install "poetry>=2,<3"
- name: Build distributions
run: poetry build
- name: Upload PyPI artifacts
uses: actions/upload-artifact@v7
with:
name: pypi-build
path: ./dist
retention-days: 1
# --- JOB 6: PUBLISH ---
publish:
name: Publish to PyPI
if: startsWith(github.ref, 'refs/tags')
needs: build_release
runs-on: ubuntu-latest
environment:
name: pypi-publish
url: https://pypi.org/project/cfspopcon/
permissions:
id-token: write
steps:
- name: Download artifacts
uses: actions/download-artifact@v8
with:
name: pypi-build
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist/