Skip to content

Python Publish

Python Publish #162

name: Python Publish
on:
workflow_run:
workflows: [CI]
types: [completed]
workflow_dispatch:
inputs:
version:
description: Development version, such as 0.6.1.dev1
required: true
type: string
run_id:
description: Successful CI run containing release-dists
required: true
type: string
concurrency:
group: >-
python-publish-${{
github.event_name == 'workflow_run'
&& github.event.workflow_run.head_branch
|| format('v{0}', inputs.version)
}}
cancel-in-progress: false
permissions:
contents: read
jobs:
validate:
name: Validate distributions
if: >-
github.event_name == 'workflow_dispatch' ||
github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-26.04
permissions:
actions: read
contents: read
steps:
- name: Retrieve tested distributions
uses: actions/download-artifact@v8.0.1
with:
name: release-dists
path: dist/
run-id: >-
${{
github.event_name == 'workflow_run'
&& github.event.workflow_run.id
|| inputs.run_id
}}
github-token: ${{ github.token }}
- name: Set up uv
uses: astral-sh/setup-uv@v10.0.1
with:
version: '0.12.1'
python-version: '3.14'
- name: Check distributions
run: uvx --from twine==7.0.0 twine check --strict dist/*
publish:
needs: validate
if: >-
github.event_name == 'workflow_dispatch' ||
(
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.event == 'push' &&
github.event.workflow_run.head_repository.full_name == github.repository &&
startsWith(github.event.workflow_run.head_branch, 'v')
)
runs-on: ubuntu-26.04
environment:
name: >-
${{
github.event_name == 'workflow_run' &&
!contains(github.event.workflow_run.head_branch, '.dev')
&& 'pypi' || 'testpypi'
}}
permissions:
actions: read
contents: read
id-token: write
attestations: write
steps:
- name: Retrieve tested distributions
uses: actions/download-artifact@v8.0.1
with:
name: release-dists
path: dist/
run-id: >-
${{
github.event_name == 'workflow_run'
&& github.event.workflow_run.id
|| inputs.run_id
}}
github-token: ${{ github.token }}
- name: Validate development version
if: github.event_name == 'workflow_dispatch'
env:
VERSION: ${{ inputs.version }}
run: '[[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.dev[0-9]+$ ]]'
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v4.2.2
with:
subject-path: dist/*
- name: Publish distributions
uses: pypa/gh-action-pypi-publish@v1.14.2
with:
packages-dir: dist/
repository-url: >-
${{
github.event_name == 'workflow_run' &&
!contains(github.event.workflow_run.head_branch, '.dev')
&& 'https://upload.pypi.org/legacy/'
|| 'https://test.pypi.org/legacy/'
}}