-
Notifications
You must be signed in to change notification settings - Fork 465
494 lines (419 loc) · 17.6 KB
/
ruvector-postgres-ci.yml
File metadata and controls
494 lines (419 loc) · 17.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
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
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
# RuVector-Postgres CI/CD Pipeline
# Build, test, and package the PostgreSQL vector extension
#
# Features:
# - Matrix testing across PostgreSQL 16, 17 (LTS versions)
# - Docker-based integration tests
# - Performance regression detection
# - Automated packaging for releases
name: RuVector-Postgres CI/CD
on:
push:
branches: [main, develop, "feat/**", "claude/**", "fix/**"]
paths:
- 'crates/ruvector-postgres/**'
- '.github/workflows/ruvector-postgres-ci.yml'
pull_request:
branches: [main, develop]
paths:
- 'crates/ruvector-postgres/**'
- '.github/workflows/ruvector-postgres-ci.yml'
workflow_dispatch:
inputs:
run_benchmarks:
description: 'Run performance benchmarks'
required: false
default: 'false'
type: boolean
pg_version:
description: 'PostgreSQL version to test (empty for matrix)'
required: false
default: ''
type: string
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
PGRX_VERSION: '0.12.9'
RUST_VERSION: 'stable'
# Concurrency control - cancel in-progress runs for same PR
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
# ============================================================================
# Code Quality Checks
# ============================================================================
lint:
name: Lint & Format
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: ${{ env.RUST_VERSION }}
components: rustfmt, clippy
- name: Install PostgreSQL 17 dev headers
run: |
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install -y postgresql-17 postgresql-server-dev-17
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-cargo-lint-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-lint-
- name: Install cargo-pgrx
run: cargo install cargo-pgrx --version ${{ env.PGRX_VERSION }} --locked
- name: Initialize pgrx
run: cargo pgrx init --pg17=/usr/lib/postgresql/17/bin/pg_config
working-directory: crates/ruvector-postgres
- name: Check formatting
run: cargo fmt -- --check
working-directory: crates/ruvector-postgres
- name: Run Clippy
run: |
cargo clippy --features pg17 -- -D warnings \
-A clippy::too_many_arguments \
-A clippy::should_implement_trait \
-A clippy::collapsible_str_replace \
-A clippy::useless_format \
-A clippy::needless_range_loop \
-A clippy::comparison_chain \
-A clippy::not_unsafe_ptr_arg_deref \
-A clippy::derivable_impls \
-A clippy::redundant_closure \
-A clippy::manual_div_ceil \
-A clippy::unnecessary_cast \
-A clippy::unwrap_or_default
working-directory: crates/ruvector-postgres
# ============================================================================
# Matrix Build & Test
# ============================================================================
test:
name: Test PG${{ matrix.pg_version }} (${{ matrix.os }})
runs-on: ${{ matrix.os }}
needs: lint
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
pg_version: [17]
include:
# macOS tests for pg17
- os: macos-latest
pg_version: 17
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: ${{ env.RUST_VERSION }}
- name: Install PostgreSQL (Ubuntu)
if: runner.os == 'Linux'
run: |
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install -y postgresql-${{ matrix.pg_version }} postgresql-server-dev-${{ matrix.pg_version }}
echo "/usr/lib/postgresql/${{ matrix.pg_version }}/bin" >> $GITHUB_PATH
- name: Install PostgreSQL (macOS)
if: runner.os == 'macOS'
run: |
brew install postgresql@${{ matrix.pg_version }}
echo "/opt/homebrew/opt/postgresql@${{ matrix.pg_version }}/bin" >> $GITHUB_PATH
- name: Cache cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-test-pg${{ matrix.pg_version }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-test-pg${{ matrix.pg_version }}-
${{ runner.os }}-cargo-test-
- name: Install cargo-pgrx
run: cargo install cargo-pgrx --version ${{ env.PGRX_VERSION }} --locked
- name: Initialize pgrx (Ubuntu)
if: runner.os == 'Linux'
run: cargo pgrx init --pg${{ matrix.pg_version }}=/usr/lib/postgresql/${{ matrix.pg_version }}/bin/pg_config
working-directory: crates/ruvector-postgres
- name: Initialize pgrx (macOS)
if: runner.os == 'macOS'
run: cargo pgrx init --pg${{ matrix.pg_version }}=/opt/homebrew/opt/postgresql@${{ matrix.pg_version }}/bin/pg_config
working-directory: crates/ruvector-postgres
- name: Build extension
run: cargo build --no-default-features --features pg${{ matrix.pg_version }} --release
working-directory: crates/ruvector-postgres
# Note: cargo test --lib is skipped because #[pg_test] tests require PostgreSQL runtime
# and cause linker errors (undefined symbols) when compiled outside pgrx test harness.
# All tests are run via cargo pgrx test instead.
- name: Run pgrx tests
run: cargo pgrx test pg${{ matrix.pg_version }} --no-default-features
working-directory: crates/ruvector-postgres
# ============================================================================
# All Features Test
# ============================================================================
test-all-features:
name: Test All Features (PG17)
runs-on: ubuntu-latest
needs: lint
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: ${{ env.RUST_VERSION }}
- name: Install PostgreSQL 17
run: |
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install -y postgresql-17 postgresql-server-dev-17
- name: Cache cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-allfeatures-${{ hashFiles('**/Cargo.lock') }}
- name: Install cargo-pgrx
run: cargo install cargo-pgrx --version ${{ env.PGRX_VERSION }} --locked
- name: Initialize pgrx
run: cargo pgrx init --pg17=/usr/lib/postgresql/17/bin/pg_config
working-directory: crates/ruvector-postgres
- name: Build with all features
run: cargo build --features pg17,index-all,quant-all,graph-complete --release
working-directory: crates/ruvector-postgres
- name: Test with all features
run: cargo pgrx test pg17 --features index-all,quant-all,graph-complete
working-directory: crates/ruvector-postgres
# ============================================================================
# Docker Integration Tests
# ============================================================================
docker-integration:
name: Docker Integration (PG${{ matrix.pg_version }})
runs-on: ubuntu-latest
needs: test
strategy:
fail-fast: false
matrix:
pg_version: [17]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Docker image
uses: docker/build-push-action@v5
with:
context: .
file: crates/ruvector-postgres/docker/Dockerfile
build-args: |
PG_VERSION=${{ matrix.pg_version }}
push: false
load: true
tags: ruvector-postgres:pg${{ matrix.pg_version }}-test
cache-from: type=gha,scope=pg${{ matrix.pg_version }}
cache-to: type=gha,mode=max,scope=pg${{ matrix.pg_version }}
- name: Start PostgreSQL container
run: |
docker run -d \
--name ruvector-test \
-p 5432:5432 \
-e POSTGRES_USER=ruvector \
-e POSTGRES_PASSWORD=ruvector \
-e POSTGRES_DB=ruvector_test \
ruvector-postgres:pg${{ matrix.pg_version }}-test
# Wait for PostgreSQL to be ready
for i in {1..30}; do
if docker exec ruvector-test pg_isready -U ruvector -d ruvector_test; then
echo "PostgreSQL is ready"
break
fi
echo "Waiting for PostgreSQL..."
sleep 2
done
- name: Verify extension installation
run: |
docker exec ruvector-test psql -U ruvector -d ruvector_test -c "CREATE EXTENSION IF NOT EXISTS ruvector;"
docker exec ruvector-test psql -U ruvector -d ruvector_test -c "SELECT ruvector_version();"
docker exec ruvector-test psql -U ruvector -d ruvector_test -c "SELECT ruvector_simd_info();"
- name: Run integration tests
run: |
docker exec ruvector-test psql -U ruvector -d ruvector_test << 'EOF'
-- Test vector operations
SELECT '[1,2,3]'::real[] AS test_vector;
SELECT l2_distance_arr(ARRAY[1.0,2.0,3.0]::real[], ARRAY[4.0,5.0,6.0]::real[]) AS l2_dist;
SELECT cosine_distance_arr(ARRAY[1.0,0.0,0.0]::real[], ARRAY[0.0,1.0,0.0]::real[]) AS cosine_dist;
SELECT inner_product_arr(ARRAY[1.0,2.0,3.0]::real[], ARRAY[1.0,2.0,3.0]::real[]) AS inner_prod;
-- Test table creation and queries
CREATE TABLE test_vectors (id SERIAL PRIMARY KEY, embedding real[]);
INSERT INTO test_vectors (embedding) VALUES
(ARRAY[1.0,2.0,3.0]::real[]),
(ARRAY[4.0,5.0,6.0]::real[]),
(ARRAY[7.0,8.0,9.0]::real[]);
SELECT id, l2_distance_arr(embedding, ARRAY[1.0,2.0,3.0]::real[]) AS distance
FROM test_vectors
ORDER BY distance
LIMIT 3;
DROP TABLE test_vectors;
SELECT 'Integration tests passed!' AS result;
EOF
- name: Collect container logs
if: always()
run: docker logs ruvector-test
- name: Cleanup
if: always()
run: docker rm -f ruvector-test || true
# ============================================================================
# Performance Benchmarks
# ============================================================================
benchmark:
name: Performance Benchmarks
runs-on: ubuntu-latest
needs: test
if: github.event_name == 'pull_request' || github.event.inputs.run_benchmarks == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: ${{ env.RUST_VERSION }}
- name: Install PostgreSQL 17
run: |
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install -y postgresql-17 postgresql-server-dev-17
- name: Cache cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-bench-${{ hashFiles('**/Cargo.lock') }}
- name: Install cargo-pgrx
run: cargo install cargo-pgrx --version ${{ env.PGRX_VERSION }} --locked
- name: Initialize pgrx
run: cargo pgrx init --pg17=/usr/lib/postgresql/17/bin/pg_config
working-directory: crates/ruvector-postgres
- name: Run benchmarks
run: |
cargo bench --features pg17 -- --output-format bencher | tee benchmark-results.txt
working-directory: crates/ruvector-postgres
- name: Store benchmark results
uses: benchmark-action/github-action-benchmark@v1
with:
name: RuVector-Postgres Benchmarks
tool: 'cargo'
output-file-path: crates/ruvector-postgres/benchmark-results.txt
github-token: ${{ secrets.GITHUB_TOKEN }}
auto-push: false
alert-threshold: '150%'
comment-on-alert: true
fail-on-alert: false
- name: Upload benchmark artifacts
uses: actions/upload-artifact@v4
with:
name: benchmark-results
path: crates/ruvector-postgres/benchmark-results.txt
retention-days: 30
# ============================================================================
# Security Audit
# ============================================================================
security:
name: Security Audit
runs-on: ubuntu-latest
needs: lint
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Run cargo audit
run: |
cargo install cargo-audit
cargo audit --ignore RUSTSEC-2020-0071 || true
working-directory: crates/ruvector-postgres
# ============================================================================
# Package Extension
# ============================================================================
package:
name: Package PG${{ matrix.pg_version }}
runs-on: ubuntu-latest
needs: [test, docker-integration]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
strategy:
matrix:
pg_version: [17]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: ${{ env.RUST_VERSION }}
- name: Install PostgreSQL
run: |
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install -y postgresql-${{ matrix.pg_version }} postgresql-server-dev-${{ matrix.pg_version }}
- name: Cache cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-package-pg${{ matrix.pg_version }}-${{ hashFiles('**/Cargo.lock') }}
- name: Install cargo-pgrx
run: cargo install cargo-pgrx --version ${{ env.PGRX_VERSION }} --locked
- name: Initialize pgrx
run: cargo pgrx init --pg${{ matrix.pg_version }}=/usr/lib/postgresql/${{ matrix.pg_version }}/bin/pg_config
working-directory: crates/ruvector-postgres
- name: Package extension
run: cargo pgrx package --no-default-features --features pg${{ matrix.pg_version }},graph-complete
working-directory: crates/ruvector-postgres
- name: Upload package artifacts
uses: actions/upload-artifact@v4
with:
name: ruvector-postgres-pg${{ matrix.pg_version }}
path: crates/ruvector-postgres/target/release/ruvector-pg${{ matrix.pg_version }}/
retention-days: 30
# ============================================================================
# Summary Job
# ============================================================================
summary:
name: CI Summary
runs-on: ubuntu-latest
needs: [lint, test, test-all-features, docker-integration, security]
if: always()
steps:
- name: Check job statuses
run: |
echo "## CI Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Job | Status |" >> $GITHUB_STEP_SUMMARY
echo "|-----|--------|" >> $GITHUB_STEP_SUMMARY
echo "| Lint | ${{ needs.lint.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Test Matrix | ${{ needs.test.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| All Features | ${{ needs.test-all-features.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Docker Integration | ${{ needs.docker-integration.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Security Audit | ${{ needs.security.result }} |" >> $GITHUB_STEP_SUMMARY
- name: Fail if any job failed
if: contains(needs.*.result, 'failure')
run: exit 1