Repository navigation
123 lines (111 loc) · 3.29 KB
/
Copy pathpython-publish.yml
File metadata and controls
123 lines (111 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
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.2
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.3.2
with:
version: '0.13.5'
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.2
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.3
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/'
}}