Skip to content

Commit 6b2ab67

Browse files
authored
ci: optimize branching pipeline, harden release, update PyPI publishing flow (#320)
1 parent 8b26dbc commit 6b2ab67

98 files changed

Lines changed: 3840 additions & 2065 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
name: CI
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
pull_request:
9+
branches:
10+
- main
11+
12+
concurrency:
13+
group: pr-${{ github.head_ref || github.sha }}
14+
cancel-in-progress: true
15+
16+
jobs:
17+
lint:
18+
name: Lint (ruff)
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- uses: actions/checkout@v4
23+
24+
- name: Set up Python
25+
uses: actions/setup-python@v5
26+
with:
27+
python-version: "3.10"
28+
29+
- name: Install Poetry
30+
run: pipx install poetry
31+
32+
- name: Configure Poetry
33+
run: poetry config virtualenvs.in-project true
34+
35+
- name: Cache virtualenv
36+
uses: actions/cache@v4
37+
with:
38+
path: .venv
39+
key: venv-lint-${{ runner.os }}-3.10-${{ hashFiles('poetry.lock') }}
40+
41+
- name: Install dependencies
42+
run: poetry install --with dev
43+
44+
- name: Run ruff check
45+
run: poetry run ruff check .
46+
47+
- name: Run ruff format check
48+
run: poetry run ruff format --check .
49+
50+
typecheck:
51+
name: Type check (pyright)
52+
runs-on: ubuntu-latest
53+
54+
steps:
55+
- uses: actions/checkout@v4
56+
57+
- name: Set up Python
58+
uses: actions/setup-python@v5
59+
with:
60+
python-version: "3.10"
61+
62+
- name: Install Poetry
63+
run: pipx install poetry
64+
65+
- name: Configure Poetry
66+
run: poetry config virtualenvs.in-project true
67+
68+
- name: Cache virtualenv
69+
uses: actions/cache@v4
70+
with:
71+
path: .venv
72+
key: venv-typecheck-${{ runner.os }}-3.10-${{ hashFiles('poetry.lock') }}
73+
74+
- name: Install dependencies
75+
run: poetry install --with dev
76+
77+
- name: Run pyright
78+
run: poetry run pyright
79+
80+
build:
81+
name: Build package
82+
runs-on: ubuntu-latest
83+
84+
steps:
85+
- uses: actions/checkout@v4
86+
87+
- name: Set up Python
88+
uses: actions/setup-python@v5
89+
with:
90+
python-version: "3.10"
91+
92+
- name: Install Poetry
93+
run: pipx install poetry
94+
95+
- name: Configure Poetry
96+
run: poetry config virtualenvs.in-project true
97+
98+
- name: Cache virtualenv
99+
uses: actions/cache@v4
100+
with:
101+
path: .venv
102+
key: venv-build-${{ runner.os }}-3.10-${{ hashFiles('poetry.lock') }}
103+
104+
- name: Install dependencies
105+
run: poetry install --only main
106+
107+
- name: Build package
108+
run: poetry build
109+
110+
- name: Check package
111+
run: |
112+
python -m pip install --upgrade twine
113+
twine check dist/*
114+
115+
tests:
116+
name: Tests (Python ${{ matrix.python-version }}, ${{ matrix.os }})
117+
runs-on: ${{ matrix.os }}
118+
strategy:
119+
fail-fast: false
120+
matrix:
121+
os: [ubuntu-latest, windows-latest, macos-latest]
122+
python-version: ["3.10", "3.11", "3.12", "3.13"]
123+
124+
steps:
125+
- uses: actions/checkout@v4
126+
127+
- name: Set up Python
128+
uses: actions/setup-python@v5
129+
with:
130+
python-version: ${{ matrix.python-version }}
131+
132+
- name: Install Poetry
133+
run: pipx install poetry
134+
135+
- name: Configure Poetry
136+
run: poetry config virtualenvs.in-project true
137+
138+
- name: Cache virtualenv
139+
uses: actions/cache@v4
140+
with:
141+
path: .venv
142+
key: venv-tests-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}
143+
144+
- name: Install dependencies
145+
run: poetry install
146+
147+
- name: Run unit tests
148+
run: poetry run pytest tests/ -v

.github/workflows/docs.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Docs
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
# Only run on PRs that touch docs-related files to keep checks fast.
7+
paths:
8+
- "docs/**"
9+
- "README.md"
10+
- "pyproject.toml"
11+
- "deeptab/**"
12+
push:
13+
# No paths filter here: tag pushes must always build docs regardless of
14+
# which files changed in the tagged commit. Paths filters in GitHub Actions
15+
# apply to both branches and tags under the same push: block, so a tag
16+
# like v1.7.0 would be silently skipped if docs files weren't in that commit.
17+
branches:
18+
- main
19+
tags:
20+
- "v*"
21+
22+
concurrency:
23+
group: docs-${{ github.head_ref || github.ref }}
24+
cancel-in-progress: true
25+
26+
jobs:
27+
build-docs:
28+
name: Build docs (Sphinx)
29+
runs-on: ubuntu-latest
30+
31+
steps:
32+
- uses: actions/checkout@v4
33+
34+
- name: Install system dependencies
35+
run: sudo apt-get update && sudo apt-get install -y pandoc
36+
37+
- name: Set up Python
38+
uses: actions/setup-python@v5
39+
with:
40+
python-version: "3.10"
41+
42+
- name: Install Poetry
43+
run: pipx install poetry
44+
45+
- name: Configure Poetry
46+
run: poetry config virtualenvs.in-project true
47+
48+
- name: Cache virtualenv
49+
uses: actions/cache@v4
50+
with:
51+
path: .venv
52+
key: venv-docs-${{ runner.os }}-3.10-${{ hashFiles('poetry.lock') }}
53+
54+
- name: Install package and docs dependencies
55+
run: poetry install --with docs
56+
57+
- name: Build Sphinx docs
58+
run: poetry run sphinx-build -b html docs/ docs/_build/html -W --keep-going
59+
60+
# ── Triggered on push to main ──────────────────────────────────────────
61+
# RTD listens to its own webhook and publishes "latest" automatically.
62+
# The step below is informational; actual publishing is done by RTD.
63+
- name: Notify latest/dev docs will be published
64+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
65+
run: echo "Docs build succeeded. RTD will publish the 'latest' version."
66+
67+
# ── Triggered on a release tag ─────────────────────────────────────────
68+
# RTD listens to tag pushes and publishes a versioned snapshot automatically
69+
# when "Build tags" is enabled in the RTD project settings.
70+
- name: Notify stable/versioned docs will be published
71+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
72+
run: |
73+
TAG="${GITHUB_REF_NAME}"
74+
echo "Docs build succeeded for tag ${TAG}. RTD will publish the '${TAG}' versioned docs."

.github/workflows/pr-tests.yml

Lines changed: 0 additions & 48 deletions
This file was deleted.

.github/workflows/publish-pypi.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Publish to PyPI
2+
3+
# Triggered when a maintainer pushes a stable release tag (e.g. v1.7.0).
4+
# RC tags (v1.7.0rc1) are handled by publish-testpypi.yml instead.
5+
#
6+
# Requires the "pypi-publish" GitHub Environment with tag-based protection.
7+
# Uses OIDC trusted publishing — no PYPI_TOKEN secret required.
8+
9+
on:
10+
push:
11+
tags:
12+
- "v*.*.*"
13+
14+
permissions:
15+
contents: write
16+
id-token: write
17+
18+
jobs:
19+
publish:
20+
runs-on: ubuntu-latest
21+
environment: pypi-publish
22+
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v4
26+
27+
- name: Set up Python
28+
uses: actions/setup-python@v5
29+
with:
30+
python-version: "3.10"
31+
32+
- name: Install Poetry
33+
run: pipx install poetry
34+
35+
- name: Configure Poetry
36+
run: poetry config virtualenvs.in-project true
37+
38+
- name: Cache virtualenv
39+
uses: actions/cache@v4
40+
with:
41+
path: .venv
42+
key: venv-publish-${{ runner.os }}-3.10-${{ hashFiles('poetry.lock') }}
43+
44+
- name: Install dependencies
45+
run: poetry install --only main
46+
47+
- name: Check tag matches pyproject version
48+
run: |
49+
VERSION=$(python3 -c "import tomllib; d=tomllib.load(open('pyproject.toml','rb')); print(d['tool']['poetry']['version'])")
50+
TAG="${GITHUB_REF_NAME#v}"
51+
52+
echo "pyproject version: $VERSION"
53+
echo "git tag version: $TAG"
54+
55+
if [ "$VERSION" != "$TAG" ]; then
56+
echo "❌ Tag version and pyproject.toml version do not match."
57+
exit 1
58+
fi
59+
60+
- name: Build package
61+
run: poetry build
62+
63+
- name: Check package
64+
run: |
65+
python -m pip install --upgrade twine
66+
twine check dist/*
67+
68+
- name: Test wheel install
69+
run: |
70+
python -m venv /tmp/deeptab-wheel-test
71+
source /tmp/deeptab-wheel-test/bin/activate
72+
pip install dist/*.whl
73+
python -c "import deeptab; print(deeptab.__version__)"
74+
75+
- name: Publish to PyPI
76+
uses: pypa/gh-action-pypi-publish@release/v1
77+
78+
- name: Create GitHub Release
79+
uses: softprops/action-gh-release@v2
80+
with:
81+
prerelease: false
82+
generate_release_notes: true
83+
files: dist/*

0 commit comments

Comments
 (0)