Skip to content

Commit 6147e1f

Browse files
committed
ci: add GitHub Actions workflows for testing and publishing
Add test.yml workflow to run tests across Python 3.10-3.14 on PRs and pushes to main. Add publish.yml workflow to automatically publish to PyPI on version tags with version verification.
1 parent ff355a7 commit 6147e1f

2 files changed

Lines changed: 107 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Publish to PyPI
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*.*.*"
7+
8+
jobs:
9+
publish:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
id-token: write
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Install uv
22+
uses: astral-sh/setup-uv@v5
23+
with:
24+
version: "latest"
25+
26+
- name: Cache uv dependencies
27+
uses: actions/cache@v4
28+
with:
29+
path: ~/.cache/uv
30+
key: ${{ runner.os }}-uv-${{ hashFiles('uv.lock') }}
31+
restore-keys: |
32+
${{ runner.os }}-uv-
33+
34+
- name: Set up Python
35+
uses: actions/setup-python@v5
36+
with:
37+
python-version: "3.12"
38+
39+
- name: Extract version from tag
40+
id: tag_version
41+
run: |
42+
TAG_VERSION=${GITHUB_REF#refs/tags/v}
43+
echo "version=$TAG_VERSION" >> $GITHUB_OUTPUT
44+
echo "Extracted version: $TAG_VERSION"
45+
46+
- name: Verify tag matches pyproject.toml version
47+
run: |
48+
PYPROJECT_VERSION=$(uv run python -c "import tomllib; f=open('pyproject.toml', 'rb'); data=tomllib.load(f); print(data['project']['version'])")
49+
if [ "$PYPROJECT_VERSION" != "${{ steps.tag_version.outputs.version }}" ]; then
50+
echo "Error: Tag version (${{ steps.tag_version.outputs.version }}) does not match pyproject.toml version ($PYPROJECT_VERSION)"
51+
exit 1
52+
fi
53+
echo "Version match confirmed: $PYPROJECT_VERSION"
54+
55+
- name: Install dependencies
56+
run: uv sync --all-extras
57+
58+
- name: Run tests
59+
run: uv run tox
60+
61+
- name: Build package
62+
run: uv build
63+
64+
- name: Publish to PyPI
65+
uses: pypa/gh-action-pypi-publish@release/v1

.github/workflows/test.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Test
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Install uv
21+
uses: astral-sh/setup-uv@v5
22+
with:
23+
version: "latest"
24+
25+
- name: Cache uv dependencies
26+
uses: actions/cache@v4
27+
with:
28+
path: ~/.cache/uv
29+
key: ${{ runner.os }}-uv-${{ hashFiles('uv.lock') }}
30+
restore-keys: |
31+
${{ runner.os }}-uv-
32+
33+
- name: Set up Python ${{ matrix.python-version }}
34+
uses: actions/setup-python@v5
35+
with:
36+
python-version: ${{ matrix.python-version }}
37+
38+
- name: Install dependencies
39+
run: uv sync --all-extras
40+
41+
- name: Run tox
42+
run: uv run tox -e py${{ matrix.python-version | replace('.', '') }}

0 commit comments

Comments
 (0)