Skip to content

Enhance explain

Enhance explain #268

# 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:
- dev # Run CI on dev. This is important to fill the GitHub Actions cache in a way that pull requests can see it
workflow_dispatch:
inputs:
test_upgrade_version:
description: "Upcoming pg_analytics version to test upgrading against"
required: false
default: ""
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: depot-ubuntu-latest-16
pg_version: 14
arch: amd64
- runner: depot-ubuntu-latest-16
pg_version: 15
arch: amd64
- runner: depot-ubuntu-latest-16
pg_version: 16
arch: amd64
- runner: depot-ubuntu-latest-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
# 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: Swatinem/rust-cache@v2
with:
prefix-key: "v1"
shared-key: ${{ runner.os }}-rust-cache-pg_analytics-${{ HashFiles('Cargo.lock') }}
cache-targets: true
cache-on-failure: 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: Extract pgrx version
if: steps.check_skip.outputs.skip_remaining_steps != 'true'
run: echo "PGRX_VERSION=$(cargo tree --depth 1 -i pgrx -p pg_analytics | head -n 1 | cut -f2 -dv)" >> $GITHUB_ENV
- name: Install pgrx & llvm-tools-preview
if: steps.check_skip.outputs.skip_remaining_steps != 'true'
run: |
cargo install -j $(nproc) --locked cargo-pgrx --version ${{ env.PGRX_VERSION }}
rustup component add llvm-tools-preview
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
# 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
# The integration tests also test upgrading the extension when passed the '-u' flag (only on promotion PRs)
- 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: |
# Variables (we disable telemetry to avoid skewing the user metrics with CI runs)
PARADEDB_TELEMETRY=false
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 "Building pg_analytics..."
cargo pgrx install --pg-config="/usr/lib/postgresql/${{ matrix.pg_version }}/bin/pg_config" --release
echo ""
echo "Starting Postgres..."
cargo pgrx start pg${{ matrix.pg_version }}
echo ""
echo "Running Rust tests..."
export DATABASE_URL=postgresql://localhost:288${{ matrix.pg_version }}/postgres
cargo pgrx test "pg${{ matrix.pg_version }}"