Repository navigation
372 lines (345 loc) · 11.6 KB
/
Copy pathrelease.yml
File metadata and controls
372 lines (345 loc) · 11.6 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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
name: Build, test and publish the release files
# Builds the sdist and the Windows wheels, from the sdist, and tests each
# wheel against a PostgreSQL server. All files are uploaded as the workflow
# artifact "dist". On a version tag, the files are published to TestPyPI,
# installed from there and checked, and then published to PyPI after a
# manual approval of the deployment to the "pypi" environment. Publishing
# uses trusted publishing (no API tokens): the trusted publishers on PyPI
# and TestPyPI must name this workflow and the environments "pypi" and
# "testpypi", which only allow version tags.
on:
push:
tags:
- "[0-9]*"
pull_request:
paths:
- setup.py
- pyproject.toml
- MANIFEST.in
- ext/**
- .github/workflows/release.yml
- .github/actions/setup-postgres/**
workflow_dispatch:
permissions:
contents: read
jobs:
check-version:
name: Check the version
runs-on: ubuntu-26.04
timeout-minutes: 5
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Check out repository
uses: actions/checkout@v7
with:
persist-credentials: false
- name: Setup Python
uses: actions/setup-python@v7
with:
python-version: "3.15"
- name: Check the version
id: version
env:
REF_TYPE: ${{ github.ref_type }}
REF_NAME: ${{ github.ref_name }}
# the version must be in normalized form, since the indexes and the
# file names use that form; on a tag, it must equal the tag, and
# the changelog must have a dated entry for it (except dev versions)
run: |
pip install -q packaging
python - << "EOF"
import os
import re
import sys
import tomllib
from packaging.version import Version
with open("pyproject.toml", "rb") as f:
version = tomllib.load(f)["project"]["version"]
print("Version:", version)
errors = []
if str(Version(version)) != version:
errors.append(f"Version {version} is not in normalized form"
f" {Version(version)}")
if os.environ["REF_TYPE"] == "tag":
tag = os.environ["REF_NAME"]
if tag != version:
errors.append(f"Tag {tag} does not match version {version}")
if not Version(version).is_devrelease:
with open("docs/contents/changelog.rst") as f:
changelog = f.read()
heading = rf"^Version {re.escape(version)} \(\d{{4}}-\d\d-\d\d\)$"
if not re.search(heading, changelog, re.MULTILINE):
errors.append(f"No dated changelog entry for {version}")
for error in errors:
print(f"::error::{error}")
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
print(f"version={version}", file=f)
sys.exit(1 if errors else 0)
EOF
sdist:
name: Build the sdist
needs: check-version
runs-on: ubuntu-26.04
timeout-minutes: 10
steps:
- name: Check out repository
uses: actions/checkout@v7
with:
persist-credentials: false
- name: Install libpq
# setup.py needs pg_config, also for building the sdist
run: |
sudo apt-get update
sudo apt-get install -y libpq-dev
- name: Setup Python
uses: actions/setup-python@v7
with:
python-version: "3.15"
- name: Install build tools
run: pip install build twine
- name: Build the sdist
run: python -m build --sdist
- name: Check the sdist
run: |
twine check --strict dist/*
tar -tzf dist/*.tar.gz
- name: Upload the sdist
uses: actions/upload-artifact@v7
with:
name: sdist
path: dist/*.tar.gz
if-no-files-found: error
wheels:
name: Build and test the wheel for ${{ matrix.python }}
needs: sdist
runs-on: windows-2025
# installing PostgreSQL and running the tests take a few minutes
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
# the wheels of the build option in pyproject.toml, one job each,
# since the tests take about 90 seconds on Windows
python: [cp310, cp311, cp312, cp313, cp314, cp315]
env:
# the server of the setup-postgres action
PYGRESQL_DB: test
PYGRESQL_HOST: 127.0.0.1
PYGRESQL_USER: test
PYGRESQL_PASSWD: test
# connecting takes longer on Windows (see tests.yml)
PYGRESQL_TEST_TIMEOUT: 300
defaults:
run:
shell: bash
steps:
- name: Check out repository
# only for the setup-postgres action, the wheel is built from the sdist
uses: actions/checkout@v7
with:
persist-credentials: false
- name: Download the sdist
uses: actions/download-artifact@v8
with:
name: sdist
path: sdist
- name: Find the sdist
id: sdist
run: echo "path=$(ls sdist/*.tar.gz)" >> "$GITHUB_OUTPUT"
- name: Set up PostgreSQL
# with libpq and pg_config for the build and libpq.dll for the tests
uses: ./.github/actions/setup-postgres
- name: Build and test the wheel
uses: pypa/cibuildwheel@v4.3.5
with:
package-dir: ${{ steps.sdist.outputs.path }}
output-dir: wheelhouse
only: ${{ matrix.python }}-win_amd64
timeout-minutes: 15
- name: Show the server log
if: failure()
run: |
log="$PGDATA/server.log"
if [ -n "$PGDATA" ] && [ -f "$log" ]; then cat "$log"; fi
- name: Upload the wheel
uses: actions/upload-artifact@v7
with:
name: wheel-${{ matrix.python }}
path: wheelhouse/*.whl
if-no-files-found: error
dist:
name: Collect the release files
needs: [check-version, sdist, wheels]
runs-on: ubuntu-26.04
timeout-minutes: 5
steps:
- name: Download the sdist
uses: actions/download-artifact@v8
with:
name: sdist
path: dist
- name: Download the wheels
uses: actions/download-artifact@v8
with:
pattern: wheel-*
path: dist
merge-multiple: true
- name: Setup Python
uses: actions/setup-python@v7
with:
python-version: "3.15"
- name: Check the release files
env:
VERSION: ${{ needs.check-version.outputs.version }}
# the sdist and one wheel for each Python version, all with the
# version that was checked
run: |
pip install -q twine
ls -l dist
twine check --strict dist/*
for file in dist/*; do
case "${file#dist/}" in
"pygresql-$VERSION.tar.gz" | "pygresql-$VERSION-"*.whl) ;;
*) echo "::error::Unexpected file $file"; exit 1 ;;
esac
done
if [ "$(ls dist | wc -l)" != 7 ]; then
echo "::error::Expected the sdist and 6 wheels"
exit 1
fi
# libpq is not bundled yet (users need libpq.dll on the PATH)
for wheel in dist/*.whl; do
if python -m zipfile -l "$wheel" | grep -i "\.dll "; then
echo "::error::$wheel contains DLLs"
exit 1
fi
done
- name: Upload the release files
uses: actions/upload-artifact@v7
with:
name: dist
path: dist/*
if-no-files-found: error
publish-testpypi:
name: Publish to TestPyPI
needs: dist
# only for version tags (the environment also only allows these)
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-26.04
timeout-minutes: 10
environment:
name: testpypi
url: https://test.pypi.org/p/PyGreSQL
permissions:
# for trusted publishing
id-token: write
steps:
- name: Download the release files
uses: actions/download-artifact@v8
with:
name: dist
path: dist
- name: Publish to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
# so that a tag can be pushed again after a failure later on;
# files that are already there are not replaced
skip-existing: true
verify-testpypi:
name: Install from TestPyPI with ${{ matrix.python }}
needs: [check-version, publish-testpypi]
runs-on: windows-2025
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
# the ends of the range of the wheels
python: ["3.10", "3.15"]
env:
# the server of the setup-postgres action, for libpq (the smoke test
# does not use the test configuration with the PYGRESQL_* variables);
# these also replace the PGUSER and PGPASSWORD of the runner image
PGHOST: 127.0.0.1
PGPORT: 5432
PGDATABASE: test
PGUSER: test
PGPASSWORD: test
defaults:
run:
shell: bash
steps:
- name: Check out repository
# only for the setup-postgres action
uses: actions/checkout@v7
with:
persist-credentials: false
- name: Set up PostgreSQL
uses: ./.github/actions/setup-postgres
- name: Setup Python
uses: actions/setup-python@v7
with:
python-version: ${{ matrix.python }}
- name: Install the wheel from TestPyPI
env:
VERSION: ${{ needs.check-version.outputs.version }}
# only the wheel, not the sdist; new files can take a few minutes
# to become available on the index
run: |
for attempt in 1 2 3 4 5 6 7 8 9 10; do
if pip install --no-cache-dir --only-binary :all: \
--index-url https://test.pypi.org/simple/ \
"pygresql==$VERSION"; then
exit 0
fi
echo "Attempt $attempt failed, waiting"
sleep 30
done
echo "::error::Cannot install pygresql $VERSION from TestPyPI"
exit 1
- name: Check the installed package
env:
VERSION: ${{ needs.check-version.outputs.version }}
# outside the checkout, so that the installed package is imported
working-directory: ${{ runner.temp }}
run: |
python - << "EOF"
import os
import pg
import pgdb
version = os.environ["VERSION"]
print(pg.__file__, pg.version, pg.get_pqlib_version())
assert "site-packages" in pg.__file__
assert pg.version == pg.__version__ == version
assert pgdb.version == version
db = pg.DB()
print(db.query("select version()").singlescalar())
assert db.query("select 1 + 1").singlescalar() == 2
db.close()
con = pgdb.connect()
cur = con.cursor()
cur.execute("select %s || %s", ("pygres", "ql"))
assert cur.fetchone()[0] == "pygresql"
con.close()
EOF
publish-pypi:
name: Publish to PyPI
needs: verify-testpypi
runs-on: ubuntu-26.04
timeout-minutes: 10
# the deployment waits until a required reviewer approves it
environment:
name: pypi
url: https://pypi.org/p/PyGreSQL
permissions:
# for trusted publishing
id-token: write
steps:
- name: Download the release files
uses: actions/download-artifact@v8
with:
name: dist
path: dist
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1