-
Notifications
You must be signed in to change notification settings - Fork 80
325 lines (287 loc) · 12.4 KB
/
Copy pathpackage-release.yml
File metadata and controls
325 lines (287 loc) · 12.4 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
name: Package Release
on:
workflow_dispatch:
inputs:
tag:
description: 'v-tag to package, for example v0.2.2'
required: true
type: string
publish:
description: 'Upload assets to the GitHub release after packaging and validation'
required: true
default: false
type: boolean
push:
tags:
- 'v*'
pull_request:
paths:
- '.github/workflows/package-release.yml'
- 'Cargo.toml'
- 'Cargo.lock'
- 'Makefile'
- 'expected/**'
- 'scripts/package-deb.sh'
- 'scripts/validate-deb-package.sh'
- 'sql/**'
permissions:
contents: read
env:
CARGO_TERM_COLOR: always
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
CARGO_PGRX_VERSION: 0.16.1
PACKAGE_HTTP_FEATURE: http-allow-azure-domains
concurrency:
group: package-release-${{ inputs.tag || github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
validate-inputs:
name: Validate package inputs
runs-on: ubuntu-latest
steps:
- name: Require v-tag for manual packaging
if: github.event_name == 'workflow_dispatch'
run: |
case "${{ inputs.tag }}" in
v*) ;;
*)
echo "::error::tag input must be a v-tag, for example v0.2.2"
exit 1
;;
esac
build-packages:
name: Build PG${{ matrix.pg_version }} ${{ matrix.platform.type }} package
needs: validate-inputs
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
pg_version: [17, 18]
platform:
- type: amd64
docker_platform: linux/amd64
file_pattern: x86-64
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.event_name == 'workflow_dispatch' && format('refs/tags/{0}', inputs.tag) || github.ref }}
# Release tooling (scripts, packaging helpers) must come from the commit
# that defines this workflow, not from the target tag. For
# workflow_dispatch, this allows a PR branch to run its updated pipeline
# while the primary checkout above is pinned to the v-tag being packaged.
# github.sha tracks the workflow's own commit for workflow_dispatch and
# push:tags, keeping YAML and scripts in sync with the branch that ran it.
- name: Checkout release tooling
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.sha }}
path: _release_tooling
- name: Set version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "VERSION=${{ inputs.tag }}" >> "$GITHUB_ENV"
elif [ "${{ github.event_name }}" = "pull_request" ]; then
crate_version=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1)
echo "VERSION=${crate_version}~pr${{ github.event.pull_request.number }}+${GITHUB_SHA::7}" >> "$GITHUB_ENV"
else
echo "VERSION=${GITHUB_REF#refs/tags/}" >> "$GITHUB_ENV"
fi
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@37fe631027851001ddb9b187196cc803df7f5f0e # v4.3.0
- name: Build pgrx package in Docker
run: |
docker run --rm \
--platform "${{ matrix.platform.docker_platform }}" \
-e VERSION \
-v "$PWD:/work" \
-w /work \
--user root \
rust:bookworm \
bash -euxo pipefail -c '
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get install -y \
ca-certificates \
curl \
gnupg \
lsb-release \
pkg-config \
libssl-dev \
libclang-dev \
clang \
build-essential \
bison \
flex \
libreadline-dev \
zlib1g-dev \
libxml2-dev \
libxslt1-dev \
libicu-dev \
file
install -d -m 0755 /usr/share/keyrings
curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc \
| gpg --dearmor -o /usr/share/keyrings/postgresql-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/postgresql-keyring.gpg] http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" \
> /etc/apt/sources.list.d/pgdg.list
apt-get update
apt-get install -y \
postgresql-${{ matrix.pg_version }} \
postgresql-server-dev-${{ matrix.pg_version }}
export PG_CONFIG="/usr/lib/postgresql/${{ matrix.pg_version }}/bin/pg_config"
export PATH="/usr/lib/postgresql/${{ matrix.pg_version }}/bin:$PATH"
cargo install cargo-pgrx --version "${{ env.CARGO_PGRX_VERSION }}" --locked
cargo pgrx init --pg${{ matrix.pg_version }} "$PG_CONFIG"
make -f _release_tooling/Makefile package \
PG_CONFIG="$PG_CONFIG" \
EXTRA_FEATURES="${{ env.PACKAGE_HTTP_FEATURE }}"
STAGE_DIR="$PWD/target/source-install-stage-pg${{ matrix.pg_version }}"
make -f _release_tooling/Makefile install \
PG_CONFIG="$PG_CONFIG" \
PGRX_PACKAGE_DIR="$PWD/target/release/pg_durable-pg${{ matrix.pg_version }}" \
DESTDIR="$STAGE_DIR"
test -f "$STAGE_DIR/usr/lib/postgresql/${{ matrix.pg_version }}/lib/pg_durable.so"
test -f "$STAGE_DIR/usr/share/postgresql/${{ matrix.pg_version }}/extension/pg_durable.control"
compgen -G "$STAGE_DIR/usr/share/postgresql/${{ matrix.pg_version }}/extension/pg_durable--*.sql" >/dev/null
compgen -G "$STAGE_DIR/usr/share/postgresql/${{ matrix.pg_version }}/extension/pg_durable--*--*.sql" >/dev/null
_release_tooling/scripts/package-deb.sh \
"$VERSION" \
"$PWD/target/release/pg_durable-pg${{ matrix.pg_version }}" \
"${{ matrix.platform.type }}" \
"${{ matrix.pg_version }}"
'
- name: Verify Debian package
run: |
sudo chown -R "$USER:$USER" dist target || true
deb_file=$(ls dist/pg-durable-postgresql-${{ matrix.pg_version }}_*_${{ matrix.platform.type }}.deb)
echo "Checking $deb_file"
dpkg-deb --info "$deb_file"
dpkg-deb --contents "$deb_file" | grep "usr/lib/postgresql/${{ matrix.pg_version }}/lib/pg_durable.so"
dpkg-deb --contents "$deb_file" | grep "usr/share/postgresql/${{ matrix.pg_version }}/extension/pg_durable.control"
rm -rf check-package
mkdir check-package
dpkg-deb -x "$deb_file" check-package
file "check-package/usr/lib/postgresql/${{ matrix.pg_version }}/lib/pg_durable.so" | grep -E "${{ matrix.platform.file_pattern }}"
- name: Upload package artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: pg-durable-package-${{ github.run_id }}-pg${{ matrix.pg_version }}-${{ matrix.platform.type }}
path: |
dist/*.deb
retention-days: 30
validate-packages:
name: Validate PG${{ matrix.pg_version }} ${{ matrix.platform.type }} package
needs: build-packages
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
pg_version: [17, 18]
platform:
- type: amd64
docker_platform: linux/amd64
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.event_name == 'workflow_dispatch' && format('refs/tags/{0}', inputs.tag) || github.ref }}
# See build-packages: validation tooling must come from the workflow's
# own commit (github.sha), not the target tag, so a tag predating these
# scripts still validates correctly.
- name: Checkout release tooling
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.sha }}
path: _release_tooling
- name: Download package artifact
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: pg-durable-package-${{ github.run_id }}-pg${{ matrix.pg_version }}-${{ matrix.platform.type }}
path: dist
- name: Validate Debian package in PostgreSQL
run: |
docker run --rm \
--platform "${{ matrix.platform.docker_platform }}" \
-v "$PWD:/work" \
-w /work \
--user root \
debian:bookworm \
bash -euxo pipefail -c '_release_tooling/scripts/validate-deb-package.sh "${{ matrix.pg_version }}" "${{ matrix.platform.type }}"'
- name: Upload validation diagnostics on failure
if: failure()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: pg-durable-validation-diagnostics-${{ github.run_id }}-pg${{ matrix.pg_version }}-${{ matrix.platform.type }}
path: |
package-validation-logs/**
regression.out
regression.diffs
if-no-files-found: ignore
build-source:
name: Build source archives
needs: validate-inputs
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.event_name == 'workflow_dispatch' && format('refs/tags/{0}', inputs.tag) || github.ref }}
- name: Set version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "VERSION=${{ inputs.tag }}" >> "$GITHUB_ENV"
elif [ "${{ github.event_name }}" = "pull_request" ]; then
crate_version=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1)
echo "VERSION=${crate_version}~pr${{ github.event.pull_request.number }}+${GITHUB_SHA::7}" >> "$GITHUB_ENV"
else
echo "VERSION=${GITHUB_REF#refs/tags/}" >> "$GITHUB_ENV"
fi
- name: Create source archives
run: |
clean_version="${VERSION#v}"
mkdir -p dist
git archive --format=tar --prefix="pg_durable-${clean_version}/" HEAD -o "dist/pg_durable-${clean_version}.tar"
gzip -c "dist/pg_durable-${clean_version}.tar" > "dist/pg_durable-${clean_version}.tar.gz"
bzip2 -k "dist/pg_durable-${clean_version}.tar"
rm "dist/pg_durable-${clean_version}.tar"
- name: Upload source artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: pg-durable-source-${{ github.run_id }}
path: dist/pg_durable-*.tar.*
retention-days: 30
release:
name: Upload release assets
needs: [validate-packages, build-source]
runs-on: ubuntu-latest
if: github.event_name == 'push' || inputs.publish == true
permissions:
contents: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.event_name == 'workflow_dispatch' && format('refs/tags/{0}', inputs.tag) || github.ref }}
- name: Set version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "VERSION=${{ inputs.tag }}" >> "$GITHUB_ENV"
else
echo "VERSION=${GITHUB_REF#refs/tags/}" >> "$GITHUB_ENV"
fi
- name: Download artifacts
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
path: artifacts
- name: Upload assets
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if ! gh release view "$VERSION" >/dev/null 2>&1; then
gh release create "$VERSION" \
--title "Release $VERSION" \
--notes "Release $VERSION" \
--draft
fi
mkdir -p release-assets
find artifacts -type f \( -name '*.deb' -o -name '*.tar.gz' -o -name '*.tar.bz2' \) \
-exec cp -t release-assets {} +
( cd release-assets && sha256sum -- * > SHA256SUMS )
find release-assets -type f -print0 \
| xargs -0 -I {} gh release upload "$VERSION" "{}" --clobber