Skip to content

Commit 2c6c40f

Browse files
ci: tag-triggered release workflow with TestPyPI dry-run support
build job runs tests, uv build, twine check, uploads artifacts with no OIDC; publish job (needs build) holds id-token: write scoped to itself alone; manual dispatches default to TestPyPI so a mistaken run cannot touch PyPI; tag pushes publish to PyPI and attach artifacts to a GitHub release.
1 parent 5197be4 commit 2c6c40f

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: release
2+
3+
on:
4+
push:
5+
tags: ["v*"]
6+
workflow_dispatch:
7+
inputs:
8+
registry:
9+
description: "Target registry for this manual run"
10+
type: choice
11+
options: [testpypi, pypi]
12+
default: testpypi
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
- uses: astral-sh/setup-uv@v5
20+
- run: uv sync --extra dev --frozen
21+
- run: uv run pytest -q
22+
- run: uv build
23+
# Validate metadata before anything is uploaded; twine runs ephemerally.
24+
- run: uvx twine check dist/*
25+
- uses: actions/upload-artifact@v4
26+
with:
27+
name: dist
28+
path: dist/
29+
if-no-files-found: error
30+
31+
publish:
32+
needs: build
33+
runs-on: ubuntu-latest
34+
# OIDC for PyPI trusted publishing, scoped to this job only: the build
35+
# job (which runs third-party build-backend code) cannot mint credentials.
36+
permissions:
37+
id-token: write
38+
steps:
39+
- uses: actions/download-artifact@v4
40+
with:
41+
name: dist
42+
path: dist/
43+
- uses: astral-sh/setup-uv@v5
44+
- name: Publish (manual runs default to TestPyPI; tag pushes go to PyPI)
45+
run: |
46+
if [[ "${{ github.event_name }}" == "workflow_dispatch" && "${{ inputs.registry }}" == "testpypi" ]]; then
47+
uv publish --publish-url https://test.pypi.org/legacy/
48+
else
49+
uv publish
50+
fi
51+
52+
github-release:
53+
if: startsWith(github.ref, 'refs/tags/v')
54+
needs: publish
55+
runs-on: ubuntu-latest
56+
permissions:
57+
contents: write
58+
steps:
59+
- uses: actions/checkout@v4
60+
- uses: actions/download-artifact@v4
61+
with:
62+
name: dist
63+
path: dist/
64+
- run: gh release create "$GITHUB_REF_NAME" dist/* --title "$GITHUB_REF_NAME" --generate-notes
65+
env:
66+
GH_TOKEN: ${{ github.token }}

0 commit comments

Comments
 (0)