Repository navigation
250 lines (232 loc) · 8.49 KB
/
Copy pathtests.yml
File metadata and controls
250 lines (232 loc) · 8.49 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
name: Run PyGreSQL test matrix
# this has been shamelessly copied from Psycopg
on:
push:
pull_request:
permissions:
contents: read
jobs:
tests:
name: Unit tests run
# the older libpq of Ubuntu 24.04 (16) is the only one in CI without the
# features of libpq 17 and 18, so the "distro" jobs keep that release
runs-on: ${{ matrix.libpq == 'distro' && 'ubuntu-24.04' || 'ubuntu-26.04' }}
# the whole job usually takes less than 2 minutes
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
# libpq "pgdg" means the latest libpq from apt.postgresql.org,
# "distro" means the older libpq shipped with Ubuntu 24.04.
include:
# Diagonal through the supported Py/PG range
- { python: "3.10", postgres: "12", libpq: "pgdg" }
- { python: "3.11", postgres: "14", libpq: "pgdg" }
- { python: "3.12", postgres: "15", libpq: "pgdg" }
- { python: "3.13", postgres: "16", libpq: "pgdg" }
- { python: "3.14", postgres: "17", libpq: "pgdg" }
- { python: "3.15", postgres: "19", libpq: "pgdg" }
# Opposite extremes and remaining versions, older libpq
- { python: "3.10", postgres: "19", libpq: "distro" }
- { python: "3.12", postgres: "13", libpq: "distro" }
- { python: "3.13", postgres: "18", libpq: "distro" }
- { python: "3.15", postgres: "12", libpq: "distro" }
env:
PYGRESQL_DB: test
PYGRESQL_HOST: 127.0.0.1
PYGRESQL_USER: test
PYGRESQL_PASSWD: test
services:
postgresql:
image: postgres:${{ matrix.postgres }}
env:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
ports:
- 5432:5432
# Set health checks to wait until postgres has started.
# Limit the server log, which is printed when the job ends.
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
--log-opt max-size=1m
--log-opt max-file=1
steps:
- name: Check out repository
uses: actions/checkout@v7
- name: Install latest libpq from PGDG
if: matrix.libpq == 'pgdg'
run: |
sudo apt-get update
sudo apt-get install -y postgresql-common
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y
sudo apt-get install -y libpq-dev
- name: Install libpq from Ubuntu
if: matrix.libpq == 'distro'
# the runner image may already use PGDG, so pin the Ubuntu archive
run: |
sudo apt-get update
sudo apt-get install -y --allow-downgrades \
libpq5/noble-updates libpq-dev/noble-updates
- name: Show libpq version
run: pg_config --version
- name: Setup Python
uses: actions/setup-python@v7
with:
python-version: ${{ matrix.python }}
- name: Install tox
run: pip install tox
- name: Enable SSL on the database server
# with the self-signed certificate of the image (service containers
# cannot be started with options, so the setting is changed later)
run: |
docker exec ${{ job.services.postgresql.id }} psql -U test -c \
"alter system set ssl_cert_file = '/etc/ssl/certs/ssl-cert-snakeoil.pem'" \
-c "alter system set ssl_key_file = '/etc/ssl/private/ssl-cert-snakeoil.key'" \
-c "alter system set ssl = on" -c "select pg_reload_conf()"
- name: Run tests
env:
MATRIX_PYTHON: ${{ matrix.python }}
run: tox -e py${MATRIX_PYTHON/./}
timeout-minutes: 5
platforms:
name: Unit tests on other platforms
runs-on: ${{ matrix.os }}
# installing PostgreSQL takes longer than on Linux
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
# the newest server and libpq, with the oldest and the newest
# Python on Windows (the range of the Windows wheels)
include:
- { os: windows-2025, python: "3.10" }
- { os: windows-2025, python: "3.15" }
- { os: macos-15, python: "3.15" }
env:
PYGRESQL_DB: test
PYGRESQL_HOST: 127.0.0.1
PYGRESQL_USER: test
PYGRESQL_PASSWD: test
# connecting takes longer on Windows, where the server starts a new
# process for every connection, so the tests take about 90 seconds
PYGRESQL_TEST_TIMEOUT: 300
defaults:
run:
shell: bash
steps:
- name: Check out repository
uses: actions/checkout@v7
- name: Set up PostgreSQL
uses: ./.github/actions/setup-postgres
- name: Setup Python
uses: actions/setup-python@v7
with:
python-version: ${{ matrix.python }}
- name: Install tox
run: pip install tox
- name: Run tests
env:
MATRIX_PYTHON: ${{ matrix.python }}
run: tox -e py${MATRIX_PYTHON/./}
timeout-minutes: 10
- name: Show the server log
if: failure()
run: |
log="$PGDATA/server.log"
if [ -n "$PGDATA" ] && [ -f "$log" ]; then cat "$log"; fi
coverage:
name: Test coverage
runs-on: ubuntu-26.04
# the whole job usually takes less than 2 minutes
timeout-minutes: 15
# the newest server with UTF8 and the oldest server with SQL_ASCII
# together reach all code (see the coverage-thorough env in tox.ini)
env:
PYGRESQL_USER: test
PYGRESQL_PASSWD: test
PYGRESQL_NEWEST_HOST: 127.0.0.1
PYGRESQL_NEWEST_PORT: 5432
PYGRESQL_OLDEST_HOST: 127.0.0.1
PYGRESQL_OLDEST_PORT: 5433
services:
postgresql:
image: postgres:19
env:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
--log-opt max-size=1m
--log-opt max-file=1
oldest:
image: postgres:12
env:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
ports:
- 5433:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
--log-opt max-size=1m
--log-opt max-file=1
steps:
- name: Check out repository
uses: actions/checkout@v7
- name: Install latest libpq from PGDG
run: |
sudo apt-get update
sudo apt-get install -y postgresql-common
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y
sudo apt-get install -y libpq-dev
- name: Setup Python
uses: actions/setup-python@v7
with:
python-version: "3.15"
- name: Install tox
run: pip install tox
- name: Enable SSL on the database server
# with the self-signed certificate of the image (service containers
# cannot be started with options, so the setting is changed later)
run: |
docker exec ${{ job.services.postgresql.id }} psql -U test -c \
"alter system set ssl_cert_file = '/etc/ssl/certs/ssl-cert-snakeoil.pem'" \
-c "alter system set ssl_key_file = '/etc/ssl/private/ssl-cert-snakeoil.key'" \
-c "alter system set ssl = on" -c "select pg_reload_conf()"
- name: Create a database with SQL_ASCII on the oldest server
run: |
docker exec ${{ job.services.oldest.id }} \
createdb -U test -E SQL_ASCII -T template0 test_ascii
- name: Run tests with coverage measurement
# fails if not all statements of the Python and C code are covered
run: tox -e coverage-thorough
timeout-minutes: 5
- name: Write coverage summary
if: ${{ !cancelled() && hashFiles('htmlcov/c/coverage.json') != '' }}
run: |
{
echo "### Python code"
.tox/coverage-thorough/bin/coverage report --format=markdown \
--fail-under=0
echo
.tox/coverage-thorough/bin/gcovr \
--add-tracefile htmlcov/c/coverage.json \
--markdown-summary --markdown-title "C extension" \
--markdown-heading-level 3
} >> "$GITHUB_STEP_SUMMARY"
- name: Upload coverage reports
if: ${{ !cancelled() && hashFiles('htmlcov/c/coverage.json') != '' }}
uses: actions/upload-artifact@v7
with:
name: coverage-reports
path: htmlcov/