-
-
Notifications
You must be signed in to change notification settings - Fork 18
283 lines (244 loc) · 12.7 KB
/
test-pg_analytics.yml
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
# workflows/test-pg_analytics.yml
#
# Test pg_analytics
# Run unit and integration tests for the pg_analytics extension.
name: Test pg_analytics
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
branches:
- dev
- main
paths:
- ".github/workflows/test-pg_analytics.yml"
- "src/**"
- "tests/**"
- "Cargo.toml"
- "pg_analytics.control"
push:
branches: # Also run on `dev` and `main` to fill the GitHub Actions Rust cache in a way that PRs can see it
- dev
- main
paths:
- "**/*.rs"
- "**/*.toml"
workflow_dispatch:
concurrency:
group: test-pg_analytics-${{ github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
test-pg_analytics:
name: Test pg_analytics on PostgreSQL ${{ matrix.pg_version }} for ${{ matrix.arch }}
runs-on: ${{ matrix.runner }}
if: github.event.pull_request.draft == false
strategy:
matrix:
include:
- runner: ubicloud-standard-16
pg_version: 13
arch: amd64
- runner: ubicloud-standard-16
pg_version: 14
arch: amd64
- runner: ubicloud-standard-16
pg_version: 15
arch: amd64
- runner: ubicloud-standard-16
pg_version: 16
arch: amd64
- runner: ubicloud-standard-16
pg_version: 17
arch: amd64
env:
default_pg_version: 17
steps:
# For the Rust cache to get filled, we need to run the CI on the dev branch after every merge. This only
# needs to happen once, so we skip the workflow for all but one of the matrix jobs in that case.
- name: Check if Skipping
id: check_skip
run: |
if [[ "${{ github.event_name }}" == "push" && "${{ matrix.pg_version }}" != "${{ env.default_pg_version }}" ]]; then
echo "This is a push event to fill Rust cache. Skipping this job."
echo "skip_remaining_steps=true" >> $GITHUB_OUTPUT
fi
- name: Checkout Git Repository
if: steps.check_skip.outputs.skip_remaining_steps != 'true'
uses: actions/checkout@v4
- name: Install Rust
if: steps.check_skip.outputs.skip_remaining_steps != 'true'
uses: dtolnay/rust-toolchain@stable
# This checks that the version in Cargo.toml is incremented to the next release. We only run it
# on PRs to main, which are our release promotion PRs.
- name: Check version in Cargo.toml
if: steps.check_skip.outputs.skip_remaining_steps != 'true' && github.base_ref == 'main'
run: |
CARGO_VERSION=$(grep "^version" Cargo.toml | head -1 | awk -F '"' '{print $2}')
RELEASE_VERSION="${{ vars.VERSION_MAJOR }}.${{ vars.VERSION_MINOR }}.${{ vars.VERSION_PATCH }}"
if [ "$CARGO_VERSION" != "$RELEASE_VERSION" ]; then
echo "Version in Cargo.toml ($CARGO_VERSION) does not match upcoming release version ($RELEASE_VERSION), did you forget to increment it?"
exit 1
fi
echo "Version check passed!"
- name: Extract pgrx Version
id: pgrx
run: echo version=$(cargo tree --depth 1 -i pgrx -p pg_analytics | head -n 1 | cut -f2 -dv) >> $GITHUB_OUTPUT
# Caches from base branches are available to PRs, but not across unrelated branches, so we only
# save the cache on the 'dev' branch, but load it on all branches.
- name: Install Rust Cache
if: steps.check_skip.outputs.skip_remaining_steps != 'true'
uses: ubicloud/rust-cache@v2
with:
prefix-key: "v1-rust"
key: ${{ matrix.pg_version }}-${{ steps.pgrx.outputs.version }}
cache-targets: true
cache-all-crates: true
save-if: ${{ github.ref == 'refs/heads/dev' }}
- name: Install & Configure Supported PostgreSQL Version
if: steps.check_skip.outputs.skip_remaining_steps != 'true'
run: |
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/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
sudo apt-get update && sudo apt-get install -y postgresql-${{ matrix.pg_version }} postgresql-server-dev-${{ matrix.pg_version }}
sudo chown -R $(whoami) /usr/share/postgresql/${{ matrix.pg_version }}/ /usr/lib/postgresql/${{ matrix.pg_version }}/ /var/lib/postgresql/${{ matrix.pg_version }}/
echo "/usr/lib/postgresql/${{ matrix.pg_version }}/bin" >> $GITHUB_PATH
- name: Install llvm-tools-preview
if: steps.check_skip.outputs.skip_remaining_steps != 'true'
run: rustup component add llvm-tools-preview
- name: Install cargo-pgrx
if: steps.check_skip.outputs.skip_remaining_steps != 'true'
run: cargo install -j $(nproc) --locked cargo-pgrx --version ${{ steps.pgrx.outputs.version }} --debug
- name: Initialize cargo-pgrx environment
if: steps.check_skip.outputs.skip_remaining_steps != 'true'
run: cargo pgrx init "--pg${{ matrix.pg_version }}=/usr/lib/postgresql/${{ matrix.pg_version }}/bin/pg_config"
- name: Add pg_analytics to shared_preload_libraries
if: steps.check_skip.outputs.skip_remaining_steps != 'true'
working-directory: /home/runner/.pgrx/data-${{ matrix.pg_version }}/
run: sed -i "s/^#shared_preload_libraries = .*/shared_preload_libraries = 'pg_analytics'/" postgresql.conf
- name: Compile & install pg_analytics extension
if: steps.check_skip.outputs.skip_remaining_steps != 'true'
run: cargo pgrx install --pg-config="/usr/lib/postgresql/${{ matrix.pg_version }}/bin/pg_config"
- name: Start Postgres via cargo-pgrx
if: steps.check_skip.outputs.skip_remaining_steps != 'true'
run: RUST_BACKTRACE=1 cargo pgrx start pg${{ matrix.pg_version }}
# The SHA hash here must exactly match the Image::Tag that is referenced in the
# testcontainers modules Rust crate for localstack.
- name: Pull Localstack Image
run: docker pull localstack/localstack@sha256:73698e485240939490134aadd7e429ac87ff068cd5ad09f5de8ccb76727c13e1
- name: Run pg_analytics Cargo Test Suite
if: steps.check_skip.outputs.skip_remaining_steps != 'true'
env:
LLVM_PROFILE_FILE: target/coverage/pg_analytics-%p-%m.profraw
RUST_BACKTRACE: full
run: |
echo ""
echo "Enabling code coverage..."
echo -e "\n# Enable code coverage on Linux only, for CI builds\n[target.'cfg(target_os=\"linux\")']\nrustflags = [\"-Cinstrument-coverage\"]" >> .cargo/config.toml
mkdir -p target/coverage target/coverage-report
echo ""
echo "Running Rust tests..."
export DATABASE_URL=postgresql://localhost:288${{ matrix.pg_version }}/postgres
export RUST_BACKTRACE=1
cargo test --package tests --features "pg${{ matrix.pg_version }}" --no-default-features
- name: Print the Postgres Logs
if: steps.check_skip.outputs.skip_remaining_steps != 'true' && always()
run: cat ~/.pgrx/${{ matrix.pg_version}}.log
test-pg_analytics-pgrx-postgres:
name: Test pg_analytics on pgrx PostgreSQL ${{ matrix.pg_version }} for ${{ matrix.arch }}
runs-on: ${{ matrix.runner }}
if: github.event.pull_request.draft == false
strategy:
matrix:
include:
- runner: ubicloud-standard-8
pg_version: 17
arch: amd64
env:
default_pg_version: 17
steps:
# For the Rust cache to get filled, we need to run the CI on the dev branch after every merge. This only
# needs to happen once, so we skip the workflow for all but one of the matrix jobs in that case.
- name: Check if Skipping
id: check_skip
run: |
if [[ "${{ github.event_name }}" == "push" && "${{ matrix.pg_version }}" != "${{ env.default_pg_version }}" ]]; then
echo "This is a push event to fill Rust cache. Skipping this job."
echo "skip_remaining_steps=true" >> $GITHUB_OUTPUT
fi
- name: Checkout Git Repository
if: steps.check_skip.outputs.skip_remaining_steps != 'true'
uses: actions/checkout@v4
- name: Install Rust
if: steps.check_skip.outputs.skip_remaining_steps != 'true'
uses: dtolnay/rust-toolchain@stable
# This checks that the version in Cargo.toml is incremented to the next release. We only run it
# on PRs to main, which are our release promotion PRs.
- name: Check version in Cargo.toml
if: steps.check_skip.outputs.skip_remaining_steps != 'true' && github.base_ref == 'main'
run: |
CARGO_VERSION=$(grep "^version" Cargo.toml | head -1 | awk -F '"' '{print $2}')
RELEASE_VERSION="${{ vars.VERSION_MAJOR }}.${{ vars.VERSION_MINOR }}.${{ vars.VERSION_PATCH }}"
if [ "$CARGO_VERSION" != "$RELEASE_VERSION" ]; then
echo "Version in Cargo.toml ($CARGO_VERSION) does not match upcoming release version ($RELEASE_VERSION), did you forget to increment it?"
exit 1
fi
echo "Version check passed!"
- name: Extract pgrx Version
id: pgrx
run: echo version=$(cargo tree --depth 1 -i pgrx -p pg_analytics | head -n 1 | cut -f2 -dv) >> $GITHUB_OUTPUT
# Caches from base branches are available to PRs, but not across unrelated branches, so we only
# save the cache on the 'dev' branch, but load it on all branches.
- name: Install Rust Cache
if: steps.check_skip.outputs.skip_remaining_steps != 'true'
uses: ubicloud/rust-cache@v2
with:
prefix-key: "v1-rust"
key: ${{ matrix.pg_version }}-${{ steps.pgrx.outputs.version }}
cache-targets: true
cache-all-crates: true
save-if: ${{ github.ref == 'refs/heads/dev' }}
- name: Install llvm-tools-preview
if: steps.check_skip.outputs.skip_remaining_steps != 'true'
run: rustup component add llvm-tools-preview
- name: Install cargo-pgrx
if: steps.check_skip.outputs.skip_remaining_steps != 'true'
run: cargo install -j $(nproc) --locked cargo-pgrx --version ${{ steps.pgrx.outputs.version }} --debug
- name: Initialize cargo-pgrx environment
if: steps.check_skip.outputs.skip_remaining_steps != 'true'
run: cargo pgrx init "--pg${{ matrix.pg_version }}=download"
- name: Add pg_analytics to shared_preload_libraries
if: steps.check_skip.outputs.skip_remaining_steps != 'true'
working-directory: /home/runner/.pgrx/data-${{ matrix.pg_version }}/
run: sed -i "s/^#shared_preload_libraries = .*/shared_preload_libraries = 'pg_analytics'/" postgresql.conf
- name: Stop Postgres
if: steps.check_skip.outputs.skip_remaining_steps != 'true'
run: cargo pgrx stop all
- name: Compile & install pg_analytics extension
if: steps.check_skip.outputs.skip_remaining_steps != 'true'
run: cargo pgrx install --pg-config ~/.pgrx/${{ matrix.pg_version }}.*/pgrx-install/bin/pg_config --features=pg${{ matrix.pg_version }}
- name: Start Postgres and Create Database
if: steps.check_skip.outputs.skip_remaining_steps != 'true'
run: |
RUST_BACKTRACE=1 cargo pgrx start pg${{ matrix.pg_version }}
~/.pgrx/${{ matrix.pg_version }}.*/pgrx-install/bin/createdb -p 288${{ matrix.pg_version }} -h localhost pg_analytics
# The SHA hash here must exactly match the Image::Tag that is referenced in the
# testcontainers modules Rust crate for localstack.
- name: Pull Localstack Image
run: docker pull localstack/localstack@sha256:73698e485240939490134aadd7e429ac87ff068cd5ad09f5de8ccb76727c13e1
- name: Run pg_analytics Cargo Test Suite
if: steps.check_skip.outputs.skip_remaining_steps != 'true'
env:
LLVM_PROFILE_FILE: target/coverage/pg_analytics-%p-%m.profraw
RUST_BACKTRACE: full
run: |
echo ""
echo "Enabling code coverage..."
echo -e "\n# Enable code coverage on Linux only, for CI builds\n[target.'cfg(target_os=\"linux\")']\nrustflags = [\"-Cinstrument-coverage\"]" >> .cargo/config.toml
mkdir -p target/coverage target/coverage-report
echo ""
echo "Running Rust tests..."
export DATABASE_URL=postgresql://localhost:288${{ matrix.pg_version }}/postgres
export RUST_BACKTRACE=1
cargo test --package tests --features "pg${{ matrix.pg_version }}" --no-default-features
- name: Print the Postgres Logs
if: steps.check_skip.outputs.skip_remaining_steps != 'true' && always()
run: cat ~/.pgrx/${{ matrix.pg_version}}.log