diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 68c07485..7e3c5cd5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,17 +50,7 @@ jobs: # different DATABASE_URL values. Package the Linux test executables once # here so those jobs do not recompile SQLPage or its dependencies. - name: Package Linux Rust test binaries - run: | - set -euo pipefail - rm -rf target/sqlpage-test-binaries - mkdir -p target/sqlpage-test-binaries - cargo test --features odbc-static --no-run --message-format=json \ - | jq -r 'select(.profile.test == true and .executable != null) | .executable' \ - | while IFS= read -r test_binary; do - cp -- "$test_binary" target/sqlpage-test-binaries/ - done - test -n "$(find target/sqlpage-test-binaries -maxdepth 1 -type f -print -quit)" - tar -C target/sqlpage-test-binaries -czf target/sqlpage-linux-test-binaries.tar.gz . + run: scripts/package-test-binaries.sh - name: Build Linux binary run: cargo build --features odbc-static - name: Upload Linux Rust test binaries @@ -150,19 +140,7 @@ jobs: run: docker compose logs ${{ matrix.container }} - name: Run tests against ${{ matrix.database }} timeout-minutes: 5 - run: | - set -euo pipefail - shopt -s nullglob - test_binaries=(target/sqlpage-test-binaries/*) - if ((${#test_binaries[@]} == 0)); then - echo "No test binaries were found in target/sqlpage-test-binaries" >&2 - exit 1 - fi - for test_binary in "${test_binaries[@]}"; do - echo "::group::$(basename "$test_binary")" - "$test_binary" --quiet - echo "::endgroup::" - done + run: scripts/run-test-binaries.sh env: DATABASE_URL: ${{ matrix.db_url }} MALLOC_CHECK_: 3 diff --git a/scripts/README.md b/scripts/README.md index 59986f41..750695a6 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -1,20 +1,18 @@ -# Docker Build Scripts +# Scripts -This directory contains scripts used by the Dockerfile to build SQLPage with cross-compilation support. +## The Dockerfile runs these -## Scripts +- **`setup-cross-compilation.sh`** :: (1) Sets up the cross-compilation environment from the target and build architectures; (2) Installs system dependencies and cross-compilers; and (3) extracts libgcc for the runtime stage. +- **`build-dependencies.sh`** :: Builds only the dependencies for Docker layer caching. +- **`build-project.sh`**: Builds the SQLPage binary. +- **`build-frontend.mjs`**: Bundles the browser assets into `frontend/dist`. Also callable via `npm run build`. +- **`install-duckdb-odbc.sh`**: Installs the DuckDB ODBC driver into the `duckdb` image variant. +- **`setup-sqlpage-user.sh`**: Creates the unprivileged user the images run as. -- **`setup-cross-compilation.sh`**: Sets up the cross-compilation environment based on target and build architectures. Handles system dependencies, cross-compiler installation, and libgcc extraction for runtime. -- **`build-dependencies.sh`**: Builds only the project dependencies for Docker layer caching -- **`build-project.sh`**: Builds the final SQLPage binary +These scripts pass configuration between build stages through temporary files in `/tmp/`. -## Usage +## CI runs these -These scripts are automatically copied and executed by the Dockerfile during the build process. They handle: - -- Cross-compilation setup for different architectures (amd64, arm64, arm) -- System dependencies installation -- Cargo build configuration with appropriate linkers -- Library extraction for runtime - -The scripts use temporary files in `/tmp/` to pass configuration between stages and export environment variables for use in subsequent build steps. +- **`package-test-binaries.sh`**: Compiles the Rust test harnesses once and tars them, so the database matrix runs the same executables instead of recompiling SQLPage six times. +- **`run-test-binaries.sh`**: Runs SQLPage compiled executables against whatever `DATABASE_URL` names. +- **`test-examples-hurl.sh`**: Starts an example's containers and runs its `test.hurl` suite. Takes an example path to filter on. diff --git a/scripts/package-test-binaries.sh b/scripts/package-test-binaries.sh new file mode 100755 index 00000000..6ee76de5 --- /dev/null +++ b/scripts/package-test-binaries.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +set -euo pipefail + +cd "$(dirname "${BASH_SOURCE[0]}")/.." + +BINARY_DIR=target/sqlpage-test-binaries +ARCHIVE=target/sqlpage-linux-test-binaries.tar.gz + +rm -rf "$BINARY_DIR" +mkdir -p "$BINARY_DIR" + +cargo test --features odbc-static --no-run --message-format=json \ + | jq -r 'select(.profile.test == true and .executable != null) | .executable' \ + | while IFS= read -r test_binary; do + cp -- "$test_binary" "$BINARY_DIR/" + done + +test -n "$(find "$BINARY_DIR" -maxdepth 1 -type f -print -quit)" +tar -C "$BINARY_DIR" -czf "$ARCHIVE" . diff --git a/scripts/run-test-binaries.sh b/scripts/run-test-binaries.sh new file mode 100755 index 00000000..6a02b2a7 --- /dev/null +++ b/scripts/run-test-binaries.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +set -euo pipefail + +cd "$(dirname "${BASH_SOURCE[0]}")/.." + +shopt -s nullglob +test_binaries=(target/sqlpage-test-binaries/*) + +if ((${#test_binaries[@]} == 0)); then + echo "No test binaries were found in target/sqlpage-test-binaries" >&2 + exit 1 +fi + +for test_binary in "${test_binaries[@]}"; do + echo "::group::$(basename "$test_binary")" + "$test_binary" --quiet + echo "::endgroup::" +done