-
Notifications
You must be signed in to change notification settings - Fork 1
257 lines (229 loc) · 9.62 KB
/
Copy pathpublish-python-sdk.yml
File metadata and controls
257 lines (229 loc) · 9.62 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
name: Publish Python Packages
on:
workflow_dispatch:
inputs:
package:
description: "Package to publish (honua-sdk, honua-admin, or both)"
required: true
default: "both"
type: choice
options:
- honua-sdk
- honua-admin
- both
dry_run:
description: "Run build and validation only (skip publish)"
required: false
default: true
type: boolean
push:
tags:
- "python-sdk-v*"
- "python-admin-v*"
env:
PYTHON_VERSION: "3.11"
# Least-privilege default for GITHUB_TOKEN; the publish jobs escalate to
# id-token: write at job level for PyPI Trusted Publishing.
permissions:
contents: read
jobs:
pre-publish-typecheck:
# Run mypy on the same Python matrix as ci.yml *before* uploading any
# distribution. ci.yml's typecheck job only blocks PR merges; without
# this gate a tag pushed against a green PR could still publish if a
# later change regressed 3.12 / 3.13. Running here keeps the publish
# smoke aligned with the broader CI matrix.
runs-on: ubuntu-latest
if: >
(github.event_name == 'push' && (startsWith(github.ref_name, 'python-sdk-v') || startsWith(github.ref_name, 'python-admin-v')))
|| github.event_name == 'workflow_dispatch'
strategy:
# Keep all matrix cells running so a 3.12 regression doesn't mask
# whether 3.13 (or 3.11) is also affected; one signal per Python
# version is more actionable than a single short-circuited failure.
fail-fast: false
matrix:
python-version: ["3.11", "3.12", "3.13"]
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Setup Python
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: |
packages/honua-sdk/pyproject.toml
packages/honua-admin/pyproject.toml
- name: Install packages
run: |
python -m pip install --upgrade pip
pip install -e "./packages/honua-sdk[grpc]"
pip install -e ./packages/honua-admin
pip install mypy
- name: Run mypy
run: |
python -m mypy \
packages/honua-sdk/honua_sdk \
packages/honua-admin/honua_admin
publish-honua-sdk:
needs: pre-publish-typecheck
if: >
(github.event_name == 'push' && startsWith(github.ref_name, 'python-sdk-v'))
|| (github.event_name == 'workflow_dispatch' && (github.event.inputs.package == 'honua-sdk' || github.event.inputs.package == 'both'))
runs-on: ubuntu-latest
environment: pypi-honua-sdk
# PyPI Trusted Publishing requires `id-token: write` so the action can mint
# an OIDC token and exchange it for a short-lived upload credential. The
# Trusted Publisher MUST be configured at:
# https://pypi.org/manage/project/honua-sdk/settings/publishing/
# with workflow `publish-python-sdk.yml` and environment `pypi-honua-sdk`
# bound to this repository. The per-package environment names keep the two
# publishers' OIDC configurations distinct — PyPI rejects two pending
# publishers with an identical repo/workflow/environment tuple.
# See: https://docs.pypi.org/trusted-publishers/
permissions:
contents: read
id-token: write
defaults:
run:
working-directory: packages/honua-sdk
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Setup Python
uses: actions/setup-python@v6
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: pip
cache-dependency-path: packages/honua-sdk/pyproject.toml
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[grpc]"
pip install pytest hatch
- name: Run compatibility gate
run: python scripts/compatibility_gate.py
working-directory: ${{ github.workspace }}
- name: Run SDK coverage gate
# A release must not ship a stale coverage claim (honua-sdk-python#182):
# fail the publish if compatibility/sdk-coverage.v1.json drifts from
# the SDK source, references a renamed/removed entrypoint, or uses a
# capability key honua-server no longer publishes.
env:
HONUA_CAPABILITY_KEY_LIST_URL: https://raw.githubusercontent.com/honua-io/honua-server/trunk/docs/gis/data/capability-keys.v1.json
run: python scripts/gen_sdk_coverage.py
working-directory: ${{ github.workspace }}
- name: Install honua-admin (for full smoke coverage)
run: pip install -e "${{ github.workspace }}/packages/honua-admin"
- name: Run SDK tests
# Exercise both packages so the publish smoke test mirrors CI; the prior
# `-k "not admin"` filter let admin regressions slip past sdk releases.
run: python -m pytest tests/ -q --tb=short
working-directory: ${{ github.workspace }}
env:
PYTHONPATH: ${{ github.workspace }}/packages/honua-sdk
- name: Validate tag version
if: github.event_name == 'push'
run: >
python "${GITHUB_WORKSPACE}/scripts/validate_publish_tag.py"
--pyproject pyproject.toml
--tag "${GITHUB_REF_NAME}"
--prefix python-sdk-v
- name: Build package
run: hatch build
- name: Upload package artifacts
uses: actions/upload-artifact@v7
with:
name: honua-sdk-dist-${{ github.run_id }}
path: packages/honua-sdk/dist/*
if-no-files-found: error
retention-days: 14
- name: Publish to PyPI (Trusted Publishing)
if: ${{ !(github.event_name == 'workflow_dispatch' && github.event.inputs.dry_run == 'true') }}
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: packages/honua-sdk/dist
skip-existing: true
publish-honua-admin:
needs: pre-publish-typecheck
if: >
(github.event_name == 'push' && startsWith(github.ref_name, 'python-admin-v'))
|| (github.event_name == 'workflow_dispatch' && (github.event.inputs.package == 'honua-admin' || github.event.inputs.package == 'both'))
runs-on: ubuntu-latest
environment: pypi-honua-admin
# PyPI Trusted Publishing requires `id-token: write` so the action can mint
# an OIDC token and exchange it for a short-lived upload credential. The
# Trusted Publisher MUST be configured at:
# https://pypi.org/manage/project/honua-admin/settings/publishing/
# with workflow `publish-python-sdk.yml` and environment `pypi-honua-admin`
# bound to this repository. The per-package environment names keep the two
# publishers' OIDC configurations distinct — PyPI rejects two pending
# publishers with an identical repo/workflow/environment tuple.
# See: https://docs.pypi.org/trusted-publishers/
permissions:
contents: read
id-token: write
defaults:
run:
working-directory: packages/honua-admin
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Setup Python
uses: actions/setup-python@v6
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: pip
cache-dependency-path: |
packages/honua-sdk/pyproject.toml
packages/honua-admin/pyproject.toml
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e "${{ github.workspace }}/packages/honua-sdk[grpc]"
pip install -e .
pip install pytest hatch
- name: Run compatibility gate
run: python scripts/compatibility_gate.py
working-directory: ${{ github.workspace }}
- name: Run SDK coverage gate
# A release must not ship a stale coverage claim (honua-sdk-python#182):
# fail the publish if compatibility/sdk-coverage.v1.json drifts from
# the SDK source, references a renamed/removed entrypoint, or uses a
# capability key honua-server no longer publishes.
env:
HONUA_CAPABILITY_KEY_LIST_URL: https://raw.githubusercontent.com/honua-io/honua-server/trunk/docs/gis/data/capability-keys.v1.json
run: python scripts/gen_sdk_coverage.py
working-directory: ${{ github.workspace }}
- name: Run tests
# Exercise the full suite (not just ``tests/admin/``) so the admin
# publish smoke mirrors the sdk job and CI; an sdk-side regression
# should block an admin release just as it blocks an sdk one, since
# honua-admin depends on honua-sdk. Both packages are installed above.
run: python -m pytest tests/ -q --tb=short
working-directory: ${{ github.workspace }}
env:
PYTHONPATH: ${{ github.workspace }}/packages/honua-sdk
- name: Validate tag version
if: github.event_name == 'push'
run: >
python "${GITHUB_WORKSPACE}/scripts/validate_publish_tag.py"
--pyproject pyproject.toml
--tag "${GITHUB_REF_NAME}"
--prefix python-admin-v
- name: Build package
run: hatch build
- name: Upload package artifacts
uses: actions/upload-artifact@v7
with:
name: honua-admin-dist-${{ github.run_id }}
path: packages/honua-admin/dist/*
if-no-files-found: error
retention-days: 14
- name: Publish to PyPI (Trusted Publishing)
if: ${{ !(github.event_name == 'workflow_dispatch' && github.event.inputs.dry_run == 'true') }}
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: packages/honua-admin/dist
skip-existing: true