Skip to content

Commit 709714f

Browse files
committed
New Feature: Add GitHub Actions workflows for documentation and testing
1 parent b97aa4d commit 709714f

3 files changed

Lines changed: 142 additions & 1 deletion

File tree

.github/workflows/docs.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Docs
2+
3+
on:
4+
push:
5+
# Publish to dev/ on every push to main …
6+
branches: [main]
7+
# … and to a versioned directory on every release tag.
8+
tags: ["v*.*.*"]
9+
# Allow manual re-builds from the Actions tab.
10+
workflow_dispatch:
11+
12+
# Only one docs deployment should run at a time to avoid race conditions on
13+
# the gh-pages branch.
14+
concurrency:
15+
group: docs-${{ github.ref }}
16+
cancel-in-progress: true
17+
18+
permissions:
19+
contents: write # needed to push to gh-pages
20+
21+
jobs:
22+
build-and-deploy:
23+
name: Build & deploy docs
24+
runs-on: ubuntu-latest
25+
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@v4
29+
with:
30+
# Full history lets sphinx-gallery / git tools see tags correctly.
31+
fetch-depth: 0
32+
33+
# ── uv + Python ────────────────────────────────────────────────────────
34+
- name: Set up uv
35+
uses: astral-sh/setup-uv@v5
36+
with:
37+
python-version: "3.13"
38+
enable-cache: true
39+
40+
# ── Dependencies ───────────────────────────────────────────────────────
41+
# Install the package itself plus the [docs] optional-dependency group
42+
# (sphinx, pydata-sphinx-theme, sphinx-gallery, pillow).
43+
# sphinx-gallery transitively brings in matplotlib, which the custom
44+
# scraper (docs/_sg_html_scraper.py) needs to render thumbnails.
45+
- name: Install dependencies (with docs extras)
46+
run: uv sync --extra docs
47+
48+
# ── Sphinx build ───────────────────────────────────────────────────────
49+
# -W turns warnings into errors so broken cross-references are caught.
50+
# Remove -W if the gallery examples produce unavoidable warnings.
51+
- name: Build HTML documentation
52+
run: |
53+
uv run sphinx-build -b html docs build/html -W --keep-going
54+
55+
# ── Determine deployment target ─────────────────────────────────────────
56+
# Release tag (refs/tags/v1.2.3) → destination = "v1.2.3"
57+
# Everything else (push to main, manual dispatch) → destination = "dev"
58+
- name: Determine deployment directory
59+
id: target
60+
shell: bash
61+
run: |
62+
if [[ "${GITHUB_REF}" == refs/tags/v* ]]; then
63+
echo "dest_dir=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT"
64+
else
65+
echo "dest_dir=dev" >> "$GITHUB_OUTPUT"
66+
fi
67+
68+
# ── Deploy to gh-pages ────────────────────────────────────────────────
69+
# keep_files: true preserves all existing directories on the branch so
70+
# versioned releases accumulate rather than overwriting each other.
71+
# Only the target destination_dir is replaced on each run.
72+
- name: Deploy to GitHub Pages
73+
uses: peaceiris/actions-gh-pages@v4
74+
with:
75+
github_token: ${{ secrets.GITHUB_TOKEN }}
76+
publish_dir: ./build/html
77+
destination_dir: ${{ steps.target.outputs.dest_dir }}
78+
keep_files: true
79+
# Commit message makes the deployment easy to identify in the branch log.
80+
commit_message: |
81+
docs: deploy ${{ steps.target.outputs.dest_dir }} @ ${{ github.sha }}
82+

.github/workflows/tests.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
8+
# Cancel in-flight runs for the same branch so a new push doesn't queue
9+
# behind an older one.
10+
concurrency:
11+
group: tests-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
test:
16+
name: Python ${{ matrix.python-version }} / ${{ matrix.os }}
17+
runs-on: ${{ matrix.os }}
18+
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
os: [ubuntu-latest, macos-latest, windows-latest]
23+
python-version: ["3.12", "3.13"]
24+
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@v4
28+
29+
# ── uv + Python ────────────────────────────────────────────────────────
30+
- name: Set up uv
31+
uses: astral-sh/setup-uv@v5
32+
with:
33+
python-version: ${{ matrix.python-version }}
34+
# Cache the uv download / build cache between runs.
35+
enable-cache: true
36+
37+
# ── Dependencies ───────────────────────────────────────────────────────
38+
# uv sync installs the project + all dependency groups (including dev,
39+
# which pulls in playwright).
40+
- name: Install dependencies
41+
run: uv sync
42+
43+
# ── Playwright browsers ────────────────────────────────────────────────
44+
# Visual regression tests (test_visual.py) use headless Chromium.
45+
# They skip gracefully when no baselines exist, but the browser must be
46+
# present so the playwright fixture doesn't error on setup.
47+
- name: Install Playwright browsers (Linux)
48+
if: runner.os == 'Linux'
49+
run: uv run playwright install chromium --with-deps
50+
51+
- name: Install Playwright browsers (macOS / Windows)
52+
if: runner.os != 'Linux'
53+
run: uv run playwright install chromium
54+
55+
# ── Test suite ─────────────────────────────────────────────────────────
56+
- name: Run tests
57+
run: uv run pytest tests/ -v --tb=short
58+

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ packages = ["anyplotlib"]
99
name = "anyplotlib"
1010
version = "0.1.0"
1111
description = "A plotting library using python, javascript and anywidget for performant in browser plotting."
12-
requires-python = ">=3.12"
12+
requires-python = ">=3.10"
1313
dependencies = [
1414
"anywidget>=0.9.21",
1515
"colorcet>=3.0",
@@ -25,6 +25,7 @@ docs = [
2525
"pydata-sphinx-theme>=0.16",
2626
"sphinx-gallery>=0.18",
2727
"pillow>=10.0",
28+
"matplotlib>=3.9",
2829
]
2930

3031
[dependency-groups]

0 commit comments

Comments
 (0)