Repository navigation
448 lines (393 loc) · 16.5 KB
/
Copy pathci.yml
File metadata and controls
448 lines (393 loc) · 16.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
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
name: CI
on:
push:
branches: [main]
pull_request:
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
# Cancel superseded runs on the same ref.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
# Rust build does not depend on PG major, so build instrumented tests once
# and let each matrix job run them from a nextest archive
build:
name: build tests (instrumented)
runs-on: ubuntu-latest
timeout-minutes: 45
# Coverage reads __llvm_cov sections, not DWARF. Line tables keep
# backtraces readable while shrinking archive
env:
CARGO_PROFILE_DEV_DEBUG: line-tables-only
outputs:
toolchain: ${{ steps.toolchain.outputs.version }}
steps:
- name: Checkout walshadow
uses: actions/checkout@v7
with:
path: walshadow
submodules: recursive
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: llvm-tools-preview
# Test jobs install this exact version, profraw format follows LLVM
- name: Record toolchain
id: toolchain
run: echo "version=$(rustc --version | cut -d' ' -f2)" >> "$GITHUB_OUTPUT"
- name: Install cargo-llvm-cov + cargo-nextest
uses: taiki-e/install-action@v2
with:
tool: cargo-llvm-cov,cargo-nextest
- name: Cargo cache
uses: Swatinem/rust-cache@v2
with:
workspaces: walshadow
key: cov
- name: Install C deps (lz4 + zstd for clickhouse-c-rs)
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
build-essential liblz4-dev libzstd-dev
# Archived binaries keep compile time paths, so tests read
# CARGO_BIN_EXE_* at runtime. Source must sit at same path in test jobs
- name: Build + archive tests
working-directory: walshadow
run: |
cargo llvm-cov nextest-archive --workspace --all-targets --locked \
--archive-file "$RUNNER_TEMP/tests.tar.zst"
- name: Upload test archive
uses: actions/upload-artifact@v7
with:
name: nextest-archive
path: ${{ runner.temp }}/tests.tar.zst
# Already zstd
compression-level: 0
if-no-files-found: error
retention-days: 1
test:
name: e2e (pg${{ matrix.pg-major }})
needs: build
runs-on: ubuntu-latest
timeout-minutes: 60
# Supported versions live in docs/limitations.md
# Matrix pins the on-PATH PG binaries to one
# specific major; tests + fixture-capture scripts pick up whichever
# `initdb` / `pg_ctl` / `postgres` lands first.
# Merge coverage because PostgreSQL versions take different code paths.
strategy:
fail-fast: false
matrix:
pg-major: [16, 17, 18, 19]
steps:
# Coverage files can fill the runner disk.
- name: Free disk space
uses: jlumbroso/free-disk-space@v1.3.1
with:
large-packages: false
swap-storage: false
- name: Checkout walshadow
uses: actions/checkout@v7
with:
path: walshadow
submodules: recursive
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ needs.build.outputs.toolchain }}
# cargo-llvm-cov uses tools from this component.
components: llvm-tools-preview
# nextest runs one process per test and schedules across test
# binaries; `cargo test` runs binaries one at a time.
- name: Install cargo-llvm-cov + cargo-nextest
uses: taiki-e/install-action@v2
with:
tool: cargo-llvm-cov,cargo-nextest
- name: Install C deps (lz4 + zstd for clickhouse-c-rs)
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
build-essential liblz4-dev libzstd-dev curl gnupg lsb-release \
gcovr
# The runner's preinstalled postgresql-common ships only one major
# at a time; pull the requested major straight from PGDG so the
# matrix can pin any of 16 / 17 / 18 / 19 independently of the runner
# image's choice. PGDG keeps released majors in `main` and a
# pre-release major in its own numbered component, so name both.
# `systemctl stop postgresql` parks any auto-started instance so
# tests own the unix-socket dirs cleanly.
- name: Install PostgreSQL ${{ matrix.pg-major }} (PGDG)
run: |
sudo systemctl stop postgresql 2>/dev/null || true
curl -fsSL --retry 5 --retry-all-errors https://www.postgresql.org/media/keys/ACCC4CF8.asc \
| sudo gpg --dearmor -o /usr/share/keyrings/postgres-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/postgres-archive-keyring.gpg] https://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main ${{ matrix.pg-major }}" \
| sudo tee /etc/apt/sources.list.d/pgdg.list
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
postgresql-${{ matrix.pg-major }} \
postgresql-client-${{ matrix.pg-major }} \
postgresql-server-dev-${{ matrix.pg-major }} \
postgresql-${{ matrix.pg-major }}-pgvector
sudo systemctl stop postgresql 2>/dev/null || true
PG_BIN=/usr/lib/postgresql/${{ matrix.pg-major }}/bin
"$PG_BIN/postgres" -V
"$PG_BIN/initdb" --version
echo "$PG_BIN" >> "$GITHUB_PATH"
# Official deb repo gives us both the `clickhouse` multitool (for
# `clickhouse local` tests) and `clickhouse-server` (for the
# readme_quickstart that connects to localhost:9000).
- name: Install ClickHouse (server + client)
run: |
sudo apt-get install -y apt-transport-https ca-certificates
curl -fsSL --retry 5 --retry-all-errors https://packages.clickhouse.com/rpm/lts/repodata/repomd.xml.key \
| sudo gpg --dearmor -o /usr/share/keyrings/clickhouse-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/clickhouse-keyring.gpg] https://packages.clickhouse.com/deb stable main" \
| sudo tee /etc/apt/sources.list.d/clickhouse.list
sudo apt-get update
DEBIAN_FRONTEND=noninteractive sudo -E apt-get install -y \
-o Dpkg::Options::="--force-confdef" \
-o Dpkg::Options::="--force-confold" \
clickhouse-server clickhouse-client clickhouse-common-static
clickhouse --version
- name: Start ClickHouse server
run: |
sudo service clickhouse-server start
# Wait for native protocol on :9000 (readme_quickstart probes it).
for i in $(seq 1 60); do
if clickhouse-client --query "SELECT 1" >/dev/null 2>&1; then
echo "clickhouse-server up after ${i}s"
exit 0
fi
sleep 1
done
echo "clickhouse-server failed to come up" >&2
sudo tail -n 200 /var/log/clickhouse-server/clickhouse-server.err.log || true
exit 1
# classify / filter / xlog_switch / vacuum_full_pg_depend tests
# fail when no fixture bytes are present. Regenerate
# them against the matrix PG major so each job's
# filter_round_trip + classify_fixture + wal_stream_chunk_boundary
# actually runs against that major's WAL layout.
- name: Regenerate WAL fixtures (PG ${{ matrix.pg-major }})
working-directory: walshadow
env:
WALSHADOW_USE_LOCAL: "1"
run: |
fixtures/wal/classify/capture.sh
fixtures/wal/filter/capture.sh
fixtures/wal/xlog_switch/capture.sh
fixtures/wal/vacuum_full_pg_depend/capture.sh
# Build walshadow.so before the e2e suite: the bridge tests point
# dynamic_library_path at the build tree, so `make` alone is what they
# need. `make install` additionally proves the target docker relies on.
# Load pgext/test in source clusters for primitives SQL cannot express,
# such as VACUUM's lock lifetime. Keep it uninstalled.
# Build it separately: test-deps would replace coverage objects
- name: Build + install walshadow PG module (e2e oracle path)
working-directory: walshadow/pgext
run: |
PG_CONFIG=/usr/lib/postgresql/${{ matrix.pg-major }}/bin/pg_config
make PG_CONFIG=$PG_CONFIG coverage-build
sudo make PG_CONFIG=$PG_CONFIG COVERAGE=1 CC=gcc install
make -C test PG_CONFIG=$PG_CONFIG
- name: Download test archive
uses: actions/download-artifact@v8
with:
name: nextest-archive
path: ${{ runner.temp }}
# Each e2e test stages a source + shadow PG cluster on disk; the
# runner's root fs is small, so point TMPDIR at the larger /mnt volume.
- name: Set TMPDIR to /mnt
run: |
sudo mkdir -p /mnt/tmp && sudo chmod 1777 /mnt/tmp
echo "TMPDIR=/mnt/tmp" >> "$GITHUB_ENV"
# All e2e tests run: shadow_lifecycle, shadow_catalog, catalog_seed,
# wal_stream_e2e (need initdb), classify_fixture + filter_round_trip
# + wal_stream_chunk_boundary (use the freshly regenerated fixtures),
# clickhouse-c-rs clickhouse_local + readme_quickstarts (need
# clickhouse binary + server on :9000).
#
# Concurrency comes from `.config/nextest.toml`: unit tests run
# `num-cpus` wide, cluster drills are capped by the `clusters`
# test group. No `--no-capture`, it would force one thread.
# Run tests once, then generate reports from saved coverage data.
- name: Test (workspace, instrumented)
working-directory: walshadow
env:
# Opts tests with `fx::dump_artifacts` into copying their tempdir
# here on failure. Empty on success; uploaded as a job artifact
# by the next step when present.
WALSHADOW_ARTIFACT_DIR: ${{ github.workspace }}/test-artifacts
# Missing tool or fixture fails the test instead of skipping it
WALSHADOW_REQUIRE_TOOLS: "1"
run: |
initdb --version | grep -Eq '\) ${{ matrix.pg-major }}([.a-z]|$)' \
|| { echo "::error::initdb on PATH is not PostgreSQL ${{ matrix.pg-major }}"; exit 1; }
mkdir -p target/llvm-cov-target
cargo llvm-cov nextest --archive-file "$RUNNER_TEMP/tests.tar.zst" \
--no-report --no-fail-fast
- name: PG module coverage
if: ${{ !cancelled() }}
working-directory: walshadow/pgext
run: make coverage-html COVERAGE_MIN_LINE=100
- name: Upload PG module coverage
if: ${{ !cancelled() }}
uses: actions/upload-artifact@v7
with:
name: coverage-pgext-pg${{ matrix.pg-major }}
path: walshadow/pgext/coverage
if-no-files-found: error
retention-days: 30
- name: Upload test artifacts on failure
if: failure()
uses: actions/upload-artifact@v7
with:
name: test-artifacts-pg${{ matrix.pg-major }}
path: ${{ github.workspace }}/test-artifacts
if-no-files-found: ignore
retention-days: 7
# cargo-llvm-cov skips build/*/*/out dirs lacking a sibling fingerprint
# dir as build script output, and nextest archives omit fingerprints,
# dropping every test binary under cargo's v2 build-dir layout
# https://github.com/taiki-e/cargo-llvm-cov/issues/520
- name: Mark extracted test binaries as v2 layout
if: ${{ !cancelled() }}
working-directory: walshadow/target/llvm-cov-target/target/debug/build
run: find . -mindepth 3 -maxdepth 3 -type d -name out -execdir mkdir -p fingerprint \;
# Preserve coverage from failed test runs. Build failures may have none.
- name: Coverage summary (job log)
if: ${{ !cancelled() }}
continue-on-error: true
working-directory: walshadow
run: cargo llvm-cov report --nextest-archive-file "$RUNNER_TEMP/tests.tar.zst" --summary-only
- name: Coverage lcov.info
if: ${{ !cancelled() }}
continue-on-error: true
working-directory: walshadow
run: |
cargo llvm-cov report --nextest-archive-file "$RUNNER_TEMP/tests.tar.zst" \
--lcov --output-path lcov.info
- name: Upload lcov
if: ${{ !cancelled() }}
uses: actions/upload-artifact@v7
with:
name: coverage-pg${{ matrix.pg-major }}
path: walshadow/lcov.info
if-no-files-found: ignore
retention-days: 30
- name: ClickHouse server logs on failure
if: failure()
run: sudo tail -n 500 /var/log/clickhouse-server/clickhouse-server.err.log || true
# Combine coverage from every PostgreSQL version.
coverage-merge:
name: line coverage (merged 16/17/18/19)
needs: test
if: always()
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout walshadow
uses: actions/checkout@v7
with:
path: walshadow
# Build failures may not produce coverage data.
- name: Fetch per-major lcov
continue-on-error: true
uses: actions/download-artifact@v8
with:
pattern: coverage-pg[0-9]*
path: lcov
# Version branches only count as covered when every major reports
- name: Merge coverage
working-directory: walshadow
run: |
set -euo pipefail
inputs=()
for m in 16 17 18 19; do
f="$GITHUB_WORKSPACE/lcov/coverage-pg$m/lcov.info"
[ -s "$f" ] || { echo "::error::missing coverage for pg$m"; exit 1; }
inputs+=("$f")
done
printf 'merging %s\n' "${inputs[@]}"
awk -f ci/lcov_merge.awk "${inputs[@]}" >merged.lcov
- name: Require 100% line coverage
working-directory: walshadow
run: |
awk -F'[:,]' '
/^DA:/ { f++; if ($3 > 0) h++ }
END {
if (!f) { print "::error::no line coverage data"; exit 1 }
printf "merged line coverage: %d/%d = %.2f%%, %d missed\n", h, f, 100 * h / f, f - h
if (h != f) { print "::error::100% line coverage required"; exit 1 }
}
' merged.lcov
- name: Install genhtml
run: sudo apt-get update && sudo apt-get install -y lcov
# Ignore llvm-cov mappings that genhtml cannot render.
- name: Coverage HTML (merged)
working-directory: walshadow
run: |
genhtml merged.lcov --output-directory html \
--prefix "$GITHUB_WORKSPACE/walshadow" --title 'walshadow merged coverage' \
--legend --quiet --ignore-errors inconsistent,unmapped
- name: Upload merged coverage
uses: actions/upload-artifact@v7
with:
name: coverage-merged
path: |
walshadow/merged.lcov
walshadow/html
if-no-files-found: error
retention-days: 30
lint:
name: lint
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout walshadow
uses: actions/checkout@v7
with:
path: walshadow
submodules: recursive
- name: shellcheck
working-directory: walshadow
run: git ls-files '*.sh' | xargs shellcheck -x
- name: module cycles
working-directory: walshadow
run: find src -name '*.rs' | awk -f ci/module_cycles.awk
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt
- name: Cargo cache
uses: Swatinem/rust-cache@v2
with:
workspaces: walshadow
key: lint
- name: Install C deps
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
build-essential liblz4-dev libzstd-dev
- name: cargo fmt
working-directory: walshadow
run: cargo fmt --all -- --check
- name: cargo clippy
working-directory: walshadow
run: cargo clippy --workspace --all-targets -- -D warnings
- name: cargo doc
working-directory: walshadow
env:
RUSTDOCFLAGS: -D warnings
run: cargo doc --no-deps --lib --bins
- name: Install cargo-deny
uses: taiki-e/install-action@v2
with:
tool: cargo-deny
# Advisories, licenses, bans, sources over the Linux graph (deny.toml)
- name: cargo deny
working-directory: walshadow
run: cargo deny --locked check