-
Notifications
You must be signed in to change notification settings - Fork 27
139 lines (127 loc) · 3.88 KB
/
release-python.yml
File metadata and controls
139 lines (127 loc) · 3.88 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
name: Release Python client
on:
workflow_dispatch:
inputs:
version:
description: "Version to publish, matching clients/python/pyproject.toml"
required: true
type: string
repository:
description: "Package index"
required: true
default: "testpypi"
type: choice
options:
- testpypi
- pypi
dry_run:
description: "Build and validate without publishing"
required: true
default: true
type: boolean
permissions:
contents: read
jobs:
build:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
env:
VERSION: ${{ inputs.version }}
defaults:
run:
working-directory: clients/python
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.sha }}
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Verify version input
run: |
set -Eeuo pipefail
python -m pip install -U packaging
# Validate PEP 440 (accepts 0.2.0, 0.2.0rc1, 0.2.0.dev1, 0.2.0a1, 0.2.0.post1, ...).
# Reject hyphenated forms like 0.2.0-dev that PyPI normalises into something
# the operator did not type, since "version input == pyproject.toml" then
# silently disagrees with what the wheel publishes as.
python -c "
import os, sys
from packaging.version import Version, InvalidVersion
v = os.environ['VERSION']
try:
parsed = Version(v)
except InvalidVersion as e:
sys.exit(f'invalid PEP 440 version: {v!r} ({e})')
if str(parsed) != v:
sys.exit(f'version {v!r} is not in PEP 440 canonical form (would normalise to {str(parsed)!r})')
"
actual=$(python - <<'PY'
import tomllib
print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])
PY
)
test "$actual" = "$VERSION" || {
echo "version input $VERSION != pyproject.toml $actual"
exit 1
}
- name: Build distribution
run: |
set -Eeuo pipefail
python -m pip install -U build twine
python -m build
python -m twine check dist/*
- name: Verify built wheel installs
run: |
set -Eeuo pipefail
python -m venv /tmp/pgque-python-wheel-check
. /tmp/pgque-python-wheel-check/bin/activate
python -m pip install dist/*.whl
python - <<'PY'
import importlib.metadata as md
import pgque
assert md.version('pgque-py')
assert hasattr(pgque, 'PgqueClient')
PY
- name: Upload distributions
if: ${{ !inputs.dry_run }}
uses: actions/upload-artifact@v4
with:
name: python-dist
path: clients/python/dist/*
if-no-files-found: error
publish-testpypi:
if: ${{ !inputs.dry_run && inputs.repository == 'testpypi' }}
needs: build
runs-on: ubuntu-latest
environment: testpypi
permissions:
contents: read
id-token: write
steps:
- uses: actions/download-artifact@v4
with:
name: python-dist
path: dist
- name: Publish to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist
repository-url: https://test.pypi.org/legacy/
publish-pypi:
if: ${{ !inputs.dry_run && inputs.repository == 'pypi' }}
needs: build
runs-on: ubuntu-latest
environment: pypi
permissions:
contents: read
id-token: write
steps:
- uses: actions/download-artifact@v4
with:
name: python-dist
path: dist
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist