-
Notifications
You must be signed in to change notification settings - Fork 874
399 lines (338 loc) · 19.5 KB
/
build.yml
File metadata and controls
399 lines (338 loc) · 19.5 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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
name: Build
on:
push:
branches:
- main
- 'hotfix/**'
tags:
- '*'
pull_request:
# Cancel previous PR branch commits (head_ref is only defined on PRs)
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
env:
dotnet_sdk_version: '8.0.100'
postgis_version: 3
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
# Windows comes with PG pre-installed, and defines the PGPASSWORD environment variable. Remove it as it interferes
# with some of our tests
PGPASSWORD: ""
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-22.04, windows-2022]
pg_major: [16, 15, 14, 13, 12]
config: [Release]
test_tfm: [net8.0]
include:
- os: ubuntu-22.04
pg_major: 16
config: Debug
test_tfm: net8.0
- os: macos-12
pg_major: 14
config: Release
test_tfm: net8.0
# - os: ubuntu-22.04
# pg_major: 17
# config: Release
# test_tfm: net8.0
# pg_prerelease: 'PG Prerelease'
outputs:
is_release: ${{ steps.analyze_tag.outputs.is_release }}
is_prerelease: ${{ steps.analyze_tag.outputs.is_prerelease }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: NuGet Cache
uses: actions/cache@v3
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/Directory.Build.targets') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v3.2.0
with:
dotnet-version: |
${{ env.dotnet_sdk_version }}
- name: Build
run: dotnet build -c ${{ matrix.config }}
shell: bash
- name: Start PostgreSQL ${{ matrix.pg_major }} (Linux)
if: startsWith(matrix.os, 'ubuntu')
run: |
# First uninstall any PostgreSQL installed on the image
dpkg-query -W --showformat='${Package}\n' 'postgresql-*' | xargs sudo dpkg -P postgresql
# Import the repository signing key
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ jammy-pgdg main ${{ matrix.pg_major }}" >> /etc/apt/sources.list.d/pgdg.list'
sudo apt-get update -qq
sudo apt-get install -qq postgresql-${{ matrix.pg_major }}
export PGDATA=/etc/postgresql/${{ matrix.pg_major }}/main
sudo cp $GITHUB_WORKSPACE/.build/{server.crt,server.key} $PGDATA
sudo chmod 600 $PGDATA/{server.crt,server.key}
sudo chown postgres $PGDATA/{server.crt,server.key}
# Create npgsql_tests user with md5 password 'npgsql_tests'
sudo -u postgres psql -c "CREATE USER npgsql_tests SUPERUSER PASSWORD 'md5adf74603a5772843f53e812f03dacb02'"
sudo -u postgres psql -c "CREATE USER npgsql_tests_ssl SUPERUSER PASSWORD 'npgsql_tests_ssl'"
sudo -u postgres psql -c "CREATE USER npgsql_tests_nossl SUPERUSER PASSWORD 'npgsql_tests_nossl'"
# To disable PostGIS for prereleases (because it usually isn't available until late), surround with the following:
if [ -z "${{ matrix.pg_prerelease }}" ]; then
sudo apt-get install -qq postgresql-${{ matrix.pg_major }}-postgis-${{ env.postgis_version }}
fi
if [ ${{ matrix.pg_major }} -ge 14 ]; then
sudo sed -i "s|unix_socket_directories = '/var/run/postgresql'|unix_socket_directories = '/var/run/postgresql, @/npgsql_unix'|" $PGDATA/postgresql.conf
fi
sudo sed -i 's/max_connections = 100/max_connections = 500/' $PGDATA/postgresql.conf
sudo sed -i 's/#ssl = off/ssl = on/' $PGDATA/postgresql.conf
sudo sed -i "s|ssl_cert_file =|ssl_cert_file = '$PGDATA/server.crt' #|" $PGDATA/postgresql.conf
sudo sed -i "s|ssl_key_file =|ssl_key_file = '$PGDATA/server.key' #|" $PGDATA/postgresql.conf
sudo sed -i 's/#password_encryption = md5/password_encryption = scram-sha-256/' $PGDATA/postgresql.conf
sudo sed -i 's/#wal_level =/wal_level = logical #/' $PGDATA/postgresql.conf
sudo sed -i 's/#max_wal_senders =/max_wal_senders = 50 #/' $PGDATA/postgresql.conf
sudo sed -i 's/#logical_decoding_work_mem =/logical_decoding_work_mem = 64kB #/' $PGDATA/postgresql.conf
sudo sed -i 's/#wal_sender_timeout =/wal_sender_timeout = 3s #/' $PGDATA/postgresql.conf
sudo sed -i "s/#synchronous_standby_names =/synchronous_standby_names = 'npgsql_test_sync_standby' #/" $PGDATA/postgresql.conf
sudo sed -i "s/#synchronous_commit =/synchronous_commit = local #/" $PGDATA/postgresql.conf
sudo sed -i "s/#max_prepared_transactions = 0/max_prepared_transactions = 100/" $PGDATA/postgresql.conf
# Disable trust authentication, requiring MD5 passwords - some tests must fail if a password isn't provided.
sudo sh -c "echo 'local all all trust' > $PGDATA/pg_hba.conf"
sudo sh -c "echo 'host all npgsql_tests_scram all scram-sha-256' >> $PGDATA/pg_hba.conf"
sudo sh -c "echo 'hostssl all npgsql_tests_ssl all md5' >> $PGDATA/pg_hba.conf"
sudo sh -c "echo 'hostnossl all npgsql_tests_ssl all reject' >> $PGDATA/pg_hba.conf"
sudo sh -c "echo 'hostnossl all npgsql_tests_nossl all md5' >> $PGDATA/pg_hba.conf"
sudo sh -c "echo 'hostssl all npgsql_tests_nossl all reject' >> $PGDATA/pg_hba.conf"
sudo sh -c "echo 'host all all all md5' >> $PGDATA/pg_hba.conf"
sudo sh -c "echo 'host replication all all md5' >> $PGDATA/pg_hba.conf"
sudo pg_ctlcluster ${{ matrix.pg_major }} main restart
# user 'npgsql_tests_scram' must be created with password encrypted as scram-sha-256 (which only applies after restart)
sudo -u postgres psql -c "CREATE USER npgsql_tests_scram SUPERUSER PASSWORD 'npgsql_tests_scram'"
# Uncomment the following to SSH into the agent running the build (https://github.com/mxschmitt/action-tmate)
#- uses: actions/checkout@v4
#- name: Setup tmate session
# uses: mxschmitt/action-tmate@v3
- name: Start PostgreSQL ${{ matrix.pg_major }} (Windows)
if: startsWith(matrix.os, 'windows')
shell: bash
run: |
# Find EnterpriseDB version number
EDB_VERSION=$(pwsh -c "
\$global:progressPreference='silentlyContinue';
Invoke-WebRequest -URI https://www.postgresql.org/applications-v2.xml |
Select-Object -ExpandProperty Content |
Select-Xml -XPath '/applications/application[id=\"postgresql_${{ matrix.pg_major }}\" and platform=\"windows-x64\"]/version/text()' |
Select-Object -First 1 -ExpandProperty Node |
Select-Object -ExpandProperty Value")
# Install PostgreSQL
echo "Installing PostgreSQL (version: ${EDB_VERSION})"
curl -o pgsql.zip -L https://get.enterprisedb.com/postgresql/postgresql-${EDB_VERSION}-windows-x64-binaries.zip
unzip pgsql.zip -x 'pgsql/include/**' 'pgsql/doc/**' 'pgsql/pgAdmin 4/**' 'pgsql/StackBuilder/**'
# Match Npgsql CI Docker image and stash one level up
cp $GITHUB_WORKSPACE/.build/{server.crt,server.key} pgsql
# Find OSGEO version number
OSGEO_VERSION=$(\
curl -Ls https://download.osgeo.org/postgis/windows/pg${{ matrix.pg_major }} |
sed -n 's/.*>postgis-bundle-pg${{ matrix.pg_major }}-\(${{ env.postgis_version }}.[0-9]*.[0-9]*\)x64.zip<.*/\1/p' |
tail -n 1)
if [ -z "$OSGEO_VERSION" ]; then
OSGEO_VERSION=$(\
curl -Ls https://download.osgeo.org/postgis/windows/pg${{ matrix.pg_major }}/archive |
sed -n 's/.*>postgis-bundle-pg${{ matrix.pg_major }}-\(${{ env.postgis_version }}.[0-9]*.[0-9]*\)x64.zip<.*/\1/p' |
tail -n 1)
POSTGIS_PATH="archive/"
else
POSTGIS_PATH=""
fi
# Install PostGIS
echo "Installing PostGIS (version: ${OSGEO_VERSION})"
POSTGIS_FILE="postgis-bundle-pg${{ matrix.pg_major }}-${OSGEO_VERSION}x64"
curl -o postgis.zip -L https://download.osgeo.org/postgis/windows/pg${{ matrix.pg_major }}/${POSTGIS_PATH}${POSTGIS_FILE}.zip
unzip postgis.zip -d postgis
cp -a postgis/$POSTGIS_FILE/. pgsql/
# Start PostgreSQL
pgsql/bin/initdb -D pgsql/PGDATA -E UTF8 -U postgres
SOCKET_DIR=$(echo "$LOCALAPPDATA\Temp" | sed 's|\\|/|g')
sed -i "s|max_connections = 100|max_connections = 500|" pgsql/PGDATA/postgresql.conf
sed -i "s|#unix_socket_directories = ''|unix_socket_directories = '$SOCKET_DIR'|" pgsql/PGDATA/postgresql.conf
sed -i "s|#wal_level =|wal_level = logical #|" pgsql/PGDATA/postgresql.conf
sed -i "s|#max_wal_senders =|max_wal_senders = 50 #|" pgsql/PGDATA/postgresql.conf
sed -i "s|#logical_decoding_work_mem =|logical_decoding_work_mem = 64kB #|" pgsql/PGDATA/postgresql.conf
sed -i "s|#wal_sender_timeout =|wal_sender_timeout = 3s #|" pgsql/PGDATA/postgresql.conf
sed -i "s|#synchronous_standby_names =|synchronous_standby_names = 'npgsql_test_sync_standby' #|" pgsql/PGDATA/postgresql.conf
sed -i "s|#synchronous_commit =|synchronous_commit = local #|" pgsql/PGDATA/postgresql.conf
sed -i "s|#max_prepared_transactions = 0|max_prepared_transactions = 100|" pgsql/PGDATA/postgresql.conf
pgsql/bin/pg_ctl -D pgsql/PGDATA -l logfile -o '-c ssl=true -c ssl_cert_file=../server.crt -c ssl_key_file=../server.key' start
# Create npgsql_tests user with md5 password 'npgsql_tests'
pgsql/bin/psql -U postgres -c "CREATE ROLE npgsql_tests SUPERUSER LOGIN PASSWORD 'md5adf74603a5772843f53e812f03dacb02'"
pgsql/bin/psql -U postgres -c "CREATE ROLE npgsql_tests_ssl SUPERUSER LOGIN PASSWORD 'npgsql_tests_ssl'"
pgsql/bin/psql -U postgres -c "CREATE ROLE npgsql_tests_nossl SUPERUSER LOGIN PASSWORD 'npgsql_tests_nossl'"
# user 'npgsql_tests_scram' must be created with password encrypted as scram-sha-256 (which only applies after restart)
if [ ${{ matrix.pg_major }} -ge 14 ]; then
sed -i "s|password_encryption = md5|password_encryption = scram-sha-256|" pgsql/PGDATA/postgresql.conf
else
sed -i "s|#password_encryption = md5|password_encryption = scram-sha-256|" pgsql/PGDATA/postgresql.conf
fi
pgsql/bin/pg_ctl -D pgsql/PGDATA -l logfile -o '-c ssl=true -c ssl_cert_file=../server.crt -c ssl_key_file=../server.key' restart
pgsql/bin/psql -U postgres -c "CREATE ROLE npgsql_tests_scram SUPERUSER LOGIN PASSWORD 'npgsql_tests_scram'"
# Disable trust authentication except for unix domain sockets, requiring MD5
# passwords - some tests must fail if a password isn't provided.
if [ ${{ matrix.pg_major }} -ge 13 ]; then
echo "local all all trust" > pgsql/PGDATA/pg_hba.conf
echo "host all npgsql_tests_scram all scram-sha-256" >> pgsql/PGDATA/pg_hba.conf
else
echo "host all npgsql_tests_scram all scram-sha-256" > pgsql/PGDATA/pg_hba.conf
fi
echo "hostssl all npgsql_tests_ssl all md5" >> pgsql/PGDATA/pg_hba.conf
echo "hostnossl all npgsql_tests_ssl all reject" >> pgsql/PGDATA/pg_hba.conf
echo "hostnossl all npgsql_tests_nossl all md5" >> pgsql/PGDATA/pg_hba.conf
echo "hostssl all npgsql_tests_nossl all reject" >> pgsql/PGDATA/pg_hba.conf
echo "host all all all md5" >> pgsql/PGDATA/pg_hba.conf
echo "host replication all all md5" >> pgsql/PGDATA/pg_hba.conf
- name: Start PostgreSQL ${{ matrix.pg_major }} (MacOS)
if: startsWith(matrix.os, 'macos')
run: |
PGDATA=/usr/local/var/postgresql@${{ matrix.pg_major }}
sudo sed -i '' 's/#ssl = off/ssl = on/' $PGDATA/postgresql.conf
cp $GITHUB_WORKSPACE/.build/{server.crt,server.key} $PGDATA
chmod 600 $PGDATA/{server.crt,server.key}
postgreService=$(brew services list | grep -oe "postgresql\S*")
brew services start $postgreService
echo "Check PostgreSQL service is running"
i=5
COMMAND='pg_isready'
while [ $i -gt 0 ]; do
echo "Check PostgreSQL service status"
eval $COMMAND && break
((i--))
if [ $i == 0 ]; then
echo "PostgreSQL service not ready, all attempts exhausted"
exit 1
fi
echo "PostgreSQL service not ready, wait 5 more sec, attempts left: $i"
sleep 5
done
# Create npgsql_tests user with md5 password 'npgsql_tests'
psql -c "CREATE USER npgsql_tests SUPERUSER PASSWORD 'md5adf74603a5772843f53e812f03dacb02'" postgres
psql -c "CREATE USER npgsql_tests_ssl SUPERUSER PASSWORD 'npgsql_tests_ssl'" postgres
psql -c "CREATE USER npgsql_tests_nossl SUPERUSER PASSWORD 'npgsql_tests_nossl'" postgres
sudo sed -i '' 's/max_connections = 100/max_connections = 500/' $PGDATA/postgresql.conf
sudo sed -i '' 's/#password_encryption = md5/password_encryption = scram-sha-256/' $PGDATA/postgresql.conf
sudo sed -i '' 's/#wal_level =/wal_level = logical #/' $PGDATA/postgresql.conf
sudo sed -i '' 's/#max_wal_senders =/max_wal_senders = 50 #/' $PGDATA/postgresql.conf
sudo sed -i '' 's/#logical_decoding_work_mem =/logical_decoding_work_mem = 64kB #/' $PGDATA/postgresql.conf
sudo sed -i '' 's/#wal_sender_timeout =/wal_sender_timeout = 3s #/' $PGDATA/postgresql.conf
sudo sed -i '' "s/#synchronous_standby_names =/synchronous_standby_names = 'npgsql_test_sync_standby' #/" $PGDATA/postgresql.conf
sudo sed -i '' "s/#synchronous_commit =/synchronous_commit = local #/" $PGDATA/postgresql.conf
sudo sed -i '' "s/#max_prepared_transactions = 0/max_prepared_transactions = 100/" $PGDATA/postgresql.conf
# Disable trust authentication, requiring MD5 passwords - some tests must fail if a password isn't provided.
sudo sh -c "echo 'local all all trust' > $PGDATA/pg_hba.conf"
sudo sh -c "echo 'hostssl all npgsql_tests_ssl all md5' >> $PGDATA/pg_hba.conf"
sudo sh -c "echo 'hostnossl all npgsql_tests_ssl all reject' >> $PGDATA/pg_hba.conf"
sudo sh -c "echo 'hostnossl all npgsql_tests_nossl all md5' >> $PGDATA/pg_hba.conf"
sudo sh -c "echo 'hostssl all npgsql_tests_nossl all reject' >> $PGDATA/pg_hba.conf"
sudo sh -c "echo 'host all npgsql_tests_scram all scram-sha-256' >> $PGDATA/pg_hba.conf"
sudo sh -c "echo 'host all all all md5' >> $PGDATA/pg_hba.conf"
sudo sh -c "echo 'host replication all all md5' >> $PGDATA/pg_hba.conf"
brew services restart $postgreService
echo "Check PostgreSQL service is running"
i=5
COMMAND='pg_isready'
while [ $i -gt 0 ]; do
echo "Check PostgreSQL service status"
eval $COMMAND && break
((i--))
if [ $i == 0 ]; then
echo "PostgreSQL service not ready, all attempts exhausted"
exit 1
fi
echo "PostgreSQL service not ready, wait 5 more sec, attempts left: $i"
sleep 5
done
psql -c "CREATE USER npgsql_tests_scram SUPERUSER PASSWORD 'npgsql_tests_scram'" postgres
# TODO: Once test/Npgsql.Specification.Tests work, switch to just testing on the solution
- name: Test
run: |
dotnet test -c ${{ matrix.config }} -f ${{ matrix.test_tfm }} test/Npgsql.Tests --logger "GitHubActions;report-warnings=false"
dotnet test -c ${{ matrix.config }} -f ${{ matrix.test_tfm }} test/Npgsql.DependencyInjection.Tests --logger "GitHubActions;report-warnings=false"
shell: bash
- name: Test Plugins
if: "!startsWith(matrix.os, 'macos')"
run: |
if [ -z "${{ matrix.pg_prerelease }}" ]; then
dotnet test -c ${{ matrix.config }} -f ${{ matrix.test_tfm }} test/Npgsql.PluginTests --logger "GitHubActions;report-warnings=false"
fi
shell: bash
- id: analyze_tag
name: Analyze tag
shell: bash
run: |
if [[ ${{ github.ref }} =~ ^refs/tags/v[0-9]+\.[0-9]+\.[0-9]+ ]]; then
echo "Release tag detected"
echo "::set-output name=is_release::true"
if [[ ${{ github.ref }} =~ ^refs/tags/v[0-9]+\.[0-9]+\.[0-9]+.*- ]]; then
echo "Prerelease tag detected"
echo "::set-output name=is_prerelease::true"
fi
fi
publish-ci:
needs: build
runs-on: ubuntu-22.04
if: github.event_name == 'push' && github.repository == 'npgsql/npgsql'
environment: myget
steps:
- name: Checkout
uses: actions/checkout@v4
- name: NuGet Cache
uses: actions/cache@v3
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/Directory.Build.targets') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v3.2.0
with:
dotnet-version: ${{ env.dotnet_sdk_version }}
- name: Pack
run: dotnet pack Npgsql.sln --configuration Release --property:PackageOutputPath="$PWD/nupkgs" --version-suffix "ci.$(date -u +%Y%m%dT%H%M%S)+sha.${GITHUB_SHA:0:9}" -p:ContinuousIntegrationBuild=true
- name: Upload artifacts (nupkg)
uses: actions/upload-artifact@v3
with:
name: Npgsql.CI
path: nupkgs
- name: Publish packages to MyGet (vnext)
if: startsWith(github.ref, 'refs/heads/') && startsWith(github.ref, 'refs/heads/hotfix/') == false
run: dotnet nuget push "*.nupkg" --api-key ${{ secrets.MYGET_FEED_TOKEN }} --source https://www.myget.org/F/npgsql-vnext/api/v3/index.json
working-directory: nupkgs
- name: Publish packages to MyGet (patch)
if: startsWith(github.ref, 'refs/heads/hotfix/')
run: dotnet nuget push "*.nupkg" --api-key ${{ secrets.MYGET_FEED_TOKEN }} --source https://www.myget.org/F/npgsql/api/v3/index.json
working-directory: nupkgs
release:
needs: build
runs-on: ubuntu-22.04
if: github.event_name == 'push' && startsWith(github.repository, 'npgsql/') && needs.build.outputs.is_release == 'true'
environment: nuget.org
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v3.2.0
with:
dotnet-version: ${{ env.dotnet_sdk_version }}
- name: Pack
run: dotnet pack Npgsql.sln --configuration Release --property:PackageOutputPath="$PWD/nupkgs" -p:ContinuousIntegrationBuild=true
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: Npgsql.Release
path: nupkgs
# TODO: Create a release
- name: Publish to nuget.org
run: dotnet nuget push "*.nupkg" --api-key ${{ secrets.NUGET_ORG_API_KEY }} --source https://api.nuget.org/v3/index.json
working-directory: nupkgs