Skip to content

Commit 67c4ecc

Browse files
authored
ci: build native wheels once and shard the unit and integration tests (#1475)
* ci: split static checks and unit tests into a prebuilt-wheel static job and three test shards The extension and CLI build once into wheels that the static job and each shard install. check-test-shards, now part of check-ci, proves the shards run every unit and integration test exactly once, using the shard coverage check the DuckDB E2E shards already had. On a Release Please version-bump head, Lockfile consistency waits for the lockfile refresh commit, whose run checks the lockfiles. The depth step documents that re-running an older Verify suite never repaints the required check. * ci: keep test wheels for shard reruns and describe what backs the release lockfile wait * ci: find compiler sources from the repository when tests run on installed wheels
1 parent b4b19c8 commit 67c4ecc

5 files changed

Lines changed: 360 additions & 127 deletions

File tree

‎.github/workflows/verify.yml‎

Lines changed: 135 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,9 @@ jobs:
339339
# every group before it merges, so a passing fast core reports as Verify and each pull
340340
# request runs the heavy suites once, in the queue. Unsetting the variable restores the old
341341
# behaviour.
342+
# GitHub takes the required Verify from the newest Verify check suite on the head. Re-running
343+
# an older suite never repaints it: to recover a head whose newest suite reported another
344+
# name, start a new suite (push, or remove and re-add full-verify), not a rerun.
342345
# The label and draft state come from the pull request as it is now, not the event payload:
343346
# `gh pr create --label` can deliver `labeled` before `opened`, and the later run cancels the
344347
# earlier one, so the surviving run must still see the label.
@@ -372,26 +375,56 @@ jobs:
372375
if: ${{ !((github.event.action == 'labeled' || github.event.action == 'unlabeled') && github.event.label.name != 'full-verify') }}
373376
runs-on: ubuntu-24.04
374377
steps:
378+
# Release Please pushes its version bump before release-please.yml refreshes Cargo.lock and
379+
# uv.lock in a commit of its own, so a bump head always disagrees with its lockfiles. That
380+
# head waits for the refresh commit, whose run checks the lockfiles. The refresh step itself
381+
# runs cargo metadata --locked and uv sync --locked before it commits, and the merge queue
382+
# always checks the lockfiles.
383+
- name: Wait for the release lockfile refresh
384+
id: release
385+
if: >-
386+
github.event_name == 'pull_request'
387+
&& github.event.pull_request.head.repo.full_name == github.repository
388+
&& startsWith(github.event.pull_request.head.ref, 'release-please--branches--')
389+
env:
390+
GH_TOKEN: ${{ github.token }}
391+
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
392+
run: |
393+
subject="$(gh api "repos/${GITHUB_REPOSITORY}/commits/${HEAD_SHA}" \
394+
--jq '.commit.message | split("\n")[0]')"
395+
if [[ "${subject}" != "chore: refresh release lockfiles" ]]; then
396+
echo "pending=true" >> "${GITHUB_OUTPUT}"
397+
echo "Version bump ${HEAD_SHA}: the lockfile refresh commit's run checks the lockfiles" \
398+
| tee -a "${GITHUB_STEP_SUMMARY}"
399+
fi
375400
- uses: actions/checkout@v4
401+
if: steps.release.outputs.pending != 'true'
376402
- uses: ./.github/actions/setup-uv
403+
if: steps.release.outputs.pending != 'true'
377404
with:
378405
version: "0.12.3"
379406
- uses: dtolnay/rust-toolchain@master
407+
if: steps.release.outputs.pending != 'true'
380408
with:
381409
toolchain: stable
382410
- name: Install Python
411+
if: steps.release.outputs.pending != 'true'
383412
run: uv python install 3.12
384413
- name: Verify lockfile
414+
if: steps.release.outputs.pending != 'true'
385415
run: uv lock --check --python 3.12
386416
- name: Verify native workspace lockfile
417+
if: steps.release.outputs.pending != 'true'
387418
run: cargo metadata --locked --format-version 1 > /dev/null
388419

389-
checks:
390-
name: Static checks and unit + integration tests
420+
# The extension and CLI build once here; the static job and every test shard install these
421+
# wheels instead of compiling them again.
422+
native_build:
423+
name: Build the extension and CLI wheels
391424
needs: [changes, lockfile]
392425
if: needs.changes.outputs.checks == 'true'
393426
runs-on: ubuntu-24.04
394-
timeout-minutes: 45
427+
timeout-minutes: 30
395428
steps:
396429
- uses: actions/checkout@v4
397430
- uses: ./.github/actions/setup-uv
@@ -413,8 +446,58 @@ jobs:
413446
save-if: false
414447
- name: Install Python
415448
run: uv python install 3.12
416-
- name: Install dependencies
417-
run: uv sync --locked --all-groups --all-extras
449+
- name: Install the build tools without building the packages
450+
run: uv sync --locked --all-groups --all-extras --no-install-package sqlbuild --no-install-package sqlbuild-cli
451+
- name: Build the extension and CLI wheels
452+
run: |
453+
uv run --no-sync maturin build --release --compatibility linux --out dist
454+
uv run --no-sync maturin build --manifest-path crates/sqlbuild-cli/Cargo.toml --release --compatibility linux --out dist
455+
- uses: actions/upload-artifact@v4
456+
with:
457+
name: verify-native-wheels
458+
path: dist/*.whl
459+
if-no-files-found: error
460+
compression-level: 0
461+
# Long enough for "Re-run failed jobs" on a shard, which reuses this run's wheels.
462+
retention-days: 3
463+
overwrite: true
464+
465+
checks:
466+
name: Static checks
467+
needs: [changes, lockfile, native_build]
468+
if: needs.changes.outputs.checks == 'true'
469+
runs-on: ubuntu-24.04
470+
timeout-minutes: 30
471+
env:
472+
# A syncing `uv run` would replace the installed wheels with a fresh editable build.
473+
UV_NO_SYNC: "1"
474+
steps:
475+
- uses: actions/checkout@v4
476+
- uses: ./.github/actions/setup-uv
477+
with:
478+
version: "0.12.3"
479+
enable-cache: true
480+
cache-dependency-glob: |
481+
uv.lock
482+
Cargo.lock
483+
# Clippy in check-ci builds its own check artifacts from the same cache as the native checks.
484+
- uses: dtolnay/rust-toolchain@master
485+
with:
486+
toolchain: stable
487+
- uses: Swatinem/rust-cache@v2
488+
with:
489+
shared-key: verify-checks
490+
save-if: false
491+
- name: Install Python
492+
run: uv python install 3.12
493+
- name: Install dependencies without building the packages
494+
run: uv sync --locked --all-groups --all-extras --no-install-package sqlbuild --no-install-package sqlbuild-cli
495+
- uses: actions/download-artifact@v4
496+
with:
497+
name: verify-native-wheels
498+
path: dist
499+
- name: Install the prebuilt extension and CLI
500+
run: uv pip install --no-deps dist/*.whl
418501
- uses: actions/setup-node@v4
419502
with:
420503
node-version: "22"
@@ -428,14 +511,55 @@ jobs:
428511
run: make check-ci
429512
env:
430513
DUPES_BASE: ${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha || 'origin/main' }}
514+
515+
tests:
516+
# check-test-shards, part of the static checks, proves that the TEST_SHARD_*_PATHS lists in
517+
# the Makefile run every test once; each of those lists needs an entry here.
518+
name: Unit + integration tests (${{ matrix.name }})
519+
needs: [changes, lockfile, native_build]
520+
if: needs.changes.outputs.checks == 'true'
521+
runs-on: ubuntu-24.04
522+
timeout-minutes: 30
523+
strategy:
524+
fail-fast: false
525+
matrix:
526+
include:
527+
- name: core
528+
target: test-shard-core
529+
workers: "4"
530+
- name: publication
531+
target: test-shard-publication
532+
workers: "2"
533+
- name: warehouse history
534+
target: test-shard-history
535+
workers: "4"
536+
env:
537+
UV_NO_SYNC: "1"
538+
PYTEST_XDIST_AUTO_NUM_WORKERS: ${{ matrix.workers }}
539+
steps:
540+
- uses: actions/checkout@v4
541+
- uses: ./.github/actions/setup-uv
542+
with:
543+
version: "0.12.3"
544+
enable-cache: true
545+
- name: Install Python
546+
run: uv python install 3.12
547+
- name: Install dependencies without building the packages
548+
run: uv sync --locked --all-groups --all-extras --no-install-package sqlbuild --no-install-package sqlbuild-cli
549+
- uses: actions/download-artifact@v4
550+
with:
551+
name: verify-native-wheels
552+
path: dist
553+
- name: Install the prebuilt extension and CLI
554+
run: uv pip install --no-deps dist/*.whl
431555
- name: Prepare Docker worker tests
432556
run: |
433557
docker info > /dev/null
434558
docker pull alpine:3.23
435559
- name: Run unit and integration tests
436560
env:
437561
SQLBUILD_REQUIRE_DOCKER_TESTS: "1"
438-
run: make test
562+
run: make ${{ matrix.target }}
439563

440564
native_checks:
441565
name: Native workspace checks
@@ -1330,7 +1454,9 @@ jobs:
13301454
[
13311455
changes,
13321456
lockfile,
1457+
native_build,
13331458
checks,
1459+
tests,
13341460
native_checks,
13351461
e2e_shards,
13361462
compiler_differential,
@@ -1358,7 +1484,9 @@ jobs:
13581484
CHANGES_RESULT: ${{ needs.changes.result }}
13591485
CHECKS_SELECTED: ${{ needs.changes.outputs.checks }}
13601486
LOCKFILE_RESULT: ${{ needs.lockfile.result }}
1487+
NATIVE_BUILD_RESULT: ${{ needs.native_build.result }}
13611488
CHECKS_RESULT: ${{ needs.checks.result }}
1489+
TESTS_RESULT: ${{ needs.tests.result }}
13621490
NATIVE_CHECKS_RESULT: ${{ needs.native_checks.result }}
13631491
E2E_SHARDS_RESULT: ${{ needs.e2e_shards.result }}
13641492
COMPILER_DIFFERENTIAL_RESULT: ${{ needs.compiler_differential.result }}
@@ -1399,7 +1527,7 @@ jobs:
13991527
echo "Required classification or lockfile checks did not pass" >&2
14001528
exit 1
14011529
fi
1402-
for result in "${CHECKS_RESULT}" "${NATIVE_CHECKS_RESULT}"; do
1530+
for result in "${NATIVE_BUILD_RESULT}" "${CHECKS_RESULT}" "${TESTS_RESULT}" "${NATIVE_CHECKS_RESULT}"; do
14031531
if [[ "${result}" != "success" ]] && \
14041532
! [[ "${CHECKS_SELECTED}" == "false" && "${result}" == "skipped" ]]; then
14051533
echo "Required static or native checks did not pass: ${result}" >&2

‎Makefile‎

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
SHELL := /bin/bash
22

33
.PHONY: verify verify-quick verify-pg coverage cli-preview rust-check check-native-layering check-dupes-new check-native-stub check-build-features check-python-boundary check-release-gate check-docs-skill check-control-client \
4-
check-e2e-shards test-e2e-duckdb test-e2e-duckdb-build-core \
4+
check-e2e-shards check-test-shards test-shard-core test-shard-publication test-shard-history \
5+
test-e2e-duckdb test-e2e-duckdb-build-core \
56
test-e2e-duckdb-build-incremental \
67
test-e2e-duckdb-cli-data test-e2e-duckdb-cli test-e2e-duckdb-inspection \
78
test-e2e-duckdb-integrations test-e2e-performance \
@@ -69,14 +70,46 @@ rust-lint:
6970
cargo clippy --workspace --all-targets --all-features -- -D warnings
7071

7172

72-
test:
73+
UNIT_INTEGRATION_MARKERS := not real_warehouse and not dbt
74+
PUBLICATION_TESTS := tests/integration/src/sqlbuild/compiler/compiled_project/publication
75+
76+
# CI runs the unit and integration tests in these shards; check-test-shards proves that together
77+
# they run every test once. Each shard lists the pytest path arguments it runs.
78+
TEST_SHARD_CORE_PATHS := tests/unit tests/integration --ignore=$(PUBLICATION_TESTS)
79+
TEST_SHARD_HISTORY_PATHS := $(PUBLICATION_TESTS)/test_warehouse_metadata.py
80+
TEST_SHARD_PUBLICATION_PATHS := $(PUBLICATION_TESTS) --ignore=$(TEST_SHARD_HISTORY_PATHS)
81+
82+
# $(1) target, $(2) pytest path arguments, $(3) xdist distribution.
83+
define run_unit_integration
7384
@mkdir -p /tmp/opencode
74-
@log="/tmp/opencode/test-$$(date +%Y%m%d-%H%M%S).log"; \
85+
@log="/tmp/opencode/$(1)-$$(date +%Y%m%d-%H%M%S).log"; \
7586
echo "Logging to $$log"; \
76-
env PYTHONUNBUFFERED=1 SQLBUILD_CONCURRENCY=$(SQLBUILD_CONCURRENCY) uv run pytest tests/unit tests/integration -m "not real_warehouse and not dbt" -vv --color=yes -n auto --dist loadfile --max-worker-restart=0 2>&1 | tee "$$log"; \
87+
env PYTHONUNBUFFERED=1 SQLBUILD_CONCURRENCY=$(SQLBUILD_CONCURRENCY) uv run pytest $(2) -m "$(UNIT_INTEGRATION_MARKERS)" -vv --color=yes -n auto --dist $(3) --max-worker-restart=0 2>&1 | tee "$$log"; \
7788
status=$${PIPESTATUS[0]}; \
7889
echo "TEST_EXIT=$$status (log: $$log)" | tee -a "$$log"; \
7990
exit $$status
91+
endef
92+
93+
test:
94+
$(call run_unit_integration,$@,tests/unit tests/integration,loadfile)
95+
96+
test-shard-core:
97+
$(call run_unit_integration,$@,$(TEST_SHARD_CORE_PATHS),loadfile)
98+
99+
test-shard-publication:
100+
$(call run_unit_integration,$@,$(TEST_SHARD_PUBLICATION_PATHS),loadfile)
101+
102+
# Its location-backed cases wait on reconcile loops, and no test there shares module state, so
103+
# they spread test by test instead of running as one file on one worker.
104+
test-shard-history:
105+
$(call run_unit_integration,$@,$(TEST_SHARD_HISTORY_PATHS),load)
106+
107+
check-test-shards:
108+
bash scripts/check_test_shards.sh --root tests/unit --root tests/integration \
109+
--markers "$(UNIT_INTEGRATION_MARKERS)" \
110+
--shard core $(TEST_SHARD_CORE_PATHS) \
111+
--shard publication $(TEST_SHARD_PUBLICATION_PATHS) \
112+
--shard history $(TEST_SHARD_HISTORY_PATHS)
80113

81114

82115
test-all:
@@ -291,7 +324,7 @@ test-e2e-duckdb-integrations:
291324
$(call run_e2e_duckdb,$@,$(E2E_DUCKDB_INTEGRATIONS_PATHS))
292325

293326
check-e2e-shards:
294-
bash scripts/check_e2e_shards.sh \
327+
bash scripts/check_test_shards.sh --root tests/e2e --markers "$(E2E_DUCKDB_MARKERS)" \
295328
--shard build-core $(E2E_DUCKDB_BUILD_CORE_PATHS) \
296329
--shard build-incremental $(E2E_DUCKDB_BUILD_INCREMENTAL_PATHS) \
297330
--shard cli-data $(E2E_DUCKDB_CLI_DATA_PATHS) \
@@ -707,7 +740,7 @@ verify-quick:
707740
exit $$status
708741

709742

710-
check-ci: check-dupes-new check-e2e-shards check-native-layering check-native-stub check-build-features check-python-boundary check-release-gate check-docs-skill check-control-client rust-lint
743+
check-ci: check-dupes-new check-e2e-shards check-test-shards check-native-layering check-native-stub check-build-features check-python-boundary check-release-gate check-docs-skill check-control-client rust-lint
711744
uv run ruff format --check .
712745
uv run ruff check .
713746
uv run ty check src tests

0 commit comments

Comments
 (0)