Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: Publish Python release to PyPI

on:
push:
tags:
- "v*"

permissions:
contents: read

concurrency:
group: pypi-${{ github.ref }}
cancel-in-progress: false

jobs:
build:
name: Validate tag and build on Windows
runs-on: windows-2025
timeout-minutes: 30
defaults:
run:
shell: pwsh
env:
PYTHONUTF8: "1"
_TYPER_FORCE_DISABLE_TERMINAL: "1"
NO_COLOR: "1"
steps:
- name: Check out tagged source and main history
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false

- name: Set up uv
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
with:
version: "0.12.19"
python-version: "3.13"

- name: Install Python
run: uv python install 3.13

- name: Install locked dependencies
run: uv sync --locked --group dev

- name: Verify tag matches package version and merged source
run: |
$version = uv run --no-sync python -c "import pathlib, tomllib; print(tomllib.loads(pathlib.Path('pyproject.toml').read_text(encoding='utf-8'))['project']['version'])"
if ($env:GITHUB_REF_NAME -ne "v$version") {
throw "Tag $env:GITHUB_REF_NAME does not match package version $version."
}
git merge-base --is-ancestor HEAD origin/main
if ($LASTEXITCODE -ne 0) {
throw "The tagged commit is not on main."
}

- name: Check code
run: |
uv run --no-sync ruff check .
uv run --no-sync ruff format --check .
uv run --no-sync ty check

- name: Test
run: uv run --no-sync pytest -q

- name: Build distributions
run: uv build --out-dir dist

- name: Upload distributions
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: python-distributions
path: dist/
if-no-files-found: error

publish:
name: Publish to PyPI
needs: build
runs-on: ubuntu-latest
timeout-minutes: 10
environment: pypi
permissions:
id-token: write
steps:
- name: Download distributions
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: python-distributions
path: dist/

- name: Publish through OIDC
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
with:
packages-dir: dist/
87 changes: 87 additions & 0 deletions .github/workflows/testpypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Publish to TestPyPI

on:
workflow_dispatch:

permissions:
contents: read

concurrency:
group: testpypi-${{ github.ref }}
cancel-in-progress: false

jobs:
build:
name: Validate and build on Windows
runs-on: windows-2025
timeout-minutes: 30
defaults:
run:
shell: pwsh
env:
PYTHONUTF8: "1"
_TYPER_FORCE_DISABLE_TERMINAL: "1"
NO_COLOR: "1"
steps:
- name: Require main
run: |
if ($env:GITHUB_REF -ne 'refs/heads/main') {
throw 'Run TestPyPI publishing from main.'
}

- name: Check out source
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Set up uv
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
with:
version: "0.12.19"
python-version: "3.13"

- name: Install Python
run: uv python install 3.13

- name: Install locked dependencies
run: uv sync --locked --group dev

- name: Check code
run: |
uv run --no-sync ruff check .
uv run --no-sync ruff format --check .
uv run --no-sync ty check

- name: Test
run: uv run --no-sync pytest -q

- name: Build distributions
run: uv build --out-dir dist

- name: Upload distributions
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: python-distributions
path: dist/
if-no-files-found: error

publish:
name: Publish to TestPyPI
needs: build
runs-on: ubuntu-latest
timeout-minutes: 10
environment: testpypi
permissions:
id-token: write
steps:
- name: Download distributions
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: python-distributions
path: dist/

- name: Publish through OIDC
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
with:
repository-url: https://test.pypi.org/legacy/
packages-dir: dist/
4 changes: 3 additions & 1 deletion PROJECT.md
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,9 @@ tags without bypass exceptions; new tags can still be created. Release
immutability is enabled for future GitHub releases. Prepare a draft with all
assets and checksums before publishing it, since published assets and the
associated tag become immutable. Corrections require a new version. See
[the release protection guide](docs/releases.md). Publishing automation remains
[the release protection guide](docs/releases.md). Separate TestPyPI and PyPI
Python-package workflows are present but await account configuration and a
hosted publication check. Windows binary and GitHub Release automation remain
planned work.

## 22. PyPI
Expand Down
Loading