Skip to content

Commit aee4992

Browse files
authored
Add CI workflow for testing and documentation
1 parent 1751058 commit aee4992

File tree

1 file changed

+130
-0
lines changed

1 file changed

+130
-0
lines changed

.github/workflows/main.yml

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
test:
11+
name: Tests and checks
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
python-version: [3.10, 3.11, 3.12, 3.13, 3.14]
16+
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
21+
- name: Set up Python ${{ matrix.python-version }}
22+
uses: actions/setup-python@v4
23+
with:
24+
python-version: ${{ matrix.python-version }}
25+
26+
- name: Cache pip
27+
uses: actions/cache@v4
28+
with:
29+
path: |
30+
~/.cache/pip
31+
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('**/pyproject.toml') }}
32+
restore-keys: |
33+
${{ runner.os }}-pip-${{ matrix.python-version }}-
34+
35+
- name: Cache pip wheels & pre-commit
36+
uses: actions/cache@v4
37+
with:
38+
path: |
39+
~/.cache/pip/wheels
40+
.wheelhouse
41+
~/.cache/pre-commit
42+
key: ${{ runner.os }}-pip-wheels-${{ matrix.python-version }}-${{ hashFiles('**/pyproject.toml') }}
43+
restore-keys: |
44+
${{ runner.os }}-pip-wheels-${{ matrix.python-version }}-
45+
46+
- name: Install build tools and uv
47+
run: |
48+
python -m pip install --upgrade pip setuptools wheel
49+
pip install uv
50+
51+
- name: Build wheelhouse for project and dev deps
52+
run: |
53+
# Build wheels for the project and development extras into .wheelhouse
54+
# This will be fast when the cache is warm.
55+
python -m pip wheel -w .wheelhouse "[dev]" || python -m pip wheel -w .wheelhouse ".[dev]"
56+
57+
- name: Create venv (uv)
58+
run: |
59+
# create a fresh .venv using uv
60+
uv venv
61+
62+
- name: Install project dev dependencies into venv from wheelhouse
63+
run: |
64+
# Install using only the local wheels for reproducibility / speed
65+
uv pip install --no-index --find-links .wheelhouse "[dev]" || uv pip install --no-index --find-links .wheelhouse ".[dev]"
66+
67+
- name: Run ruff (via uv)
68+
run: uv run ruff check .
69+
70+
- name: Check formatting with Black (via uv)
71+
run: uv run python -m black --check .
72+
73+
- name: Run mypy (via uv)
74+
run: uv run python -m mypy .
75+
76+
- name: Run pre-commit hooks (all files) via uv
77+
run: |
78+
uv run pre-commit install
79+
uv run pre-commit run --all-files
80+
81+
- name: Run tests (with coverage) via uv
82+
run: |
83+
uv run pytest -q --cov=python_project_deployment --cov-report=xml:coverage.xml --cov-report=html:htmlcov
84+
85+
- name: Upload coverage xml
86+
uses: actions/upload-artifact@v4
87+
with:
88+
name: coverage-xml
89+
path: coverage.xml
90+
91+
- name: Upload coverage HTML
92+
uses: actions/upload-artifact@v4
93+
with:
94+
name: coverage-html
95+
path: htmlcov
96+
97+
- name: Build Sphinx docs via uv
98+
run: |
99+
uv run python -m sphinx -b html docs docs/_build/html || true
100+
101+
- name: Upload docs artifact
102+
uses: actions/upload-artifact@v4
103+
with:
104+
name: docs-html
105+
path: docs/_build/html
106+
107+
deploy-docs:
108+
name: Publish docs to GitHub Pages
109+
runs-on: ubuntu-latest
110+
needs: test
111+
# Only deploy on pushes to main (avoid publishing from PRs)
112+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
113+
steps:
114+
- name: Checkout
115+
uses: actions/checkout@v4
116+
117+
- name: Download docs artifact
118+
uses: actions/download-artifact@v4
119+
with:
120+
name: docs-html
121+
path: docs/_build/html
122+
123+
- name: Upload pages artifact
124+
uses: actions/upload-pages-artifact@v1
125+
with:
126+
path: docs/_build/html
127+
128+
- name: Deploy to GitHub Pages
129+
uses: actions/deploy-pages@v1
130+
with: {}

0 commit comments

Comments
 (0)