Skip to content

Commit

Permalink
Use pgxn-tools in the Lint and Test workflow
Browse files Browse the repository at this point in the history
v1.6.0 of the pgxn/pgxn-tools Docker image includes the Rust toolchain
(with clippy and rustfmt) and a new command `pgrx-build-test` that
builds and tests pgrx extensions. It will also run `make installcheck`
if it detects it.

So use that image to run all the tests, and remove the
`.ci/apt-install-postgres` script. Meanwhile, teach `.ci/test-cover` how
to handle `PGUSER` and `PGDATA`.
  • Loading branch information
theory committed Apr 23, 2024
1 parent d7cb0d6 commit 3d77e3b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 68 deletions.
27 changes: 0 additions & 27 deletions .ci/apt-install-postgres

This file was deleted.

10 changes: 9 additions & 1 deletion .ci/test-cover
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,16 @@ if [ "$(uname -o)" = "Darwin" ]; then
export RUSTFLAGS="-Clink-arg=-Wl,-undefined,dynamic_lookup $RUSTFLAGS"
fi

coverargs=()
if [ -n "${PGUSER}" ]; then
coverargs+=(--runas "$PGUSER")
fi
if [ -n "${PGDATA}" ]; then
coverargs+=(--pgdata "$PGDATA")
fi

export LLVM_PROFILE_FILE="${DESTDIR}/default_%m_%p.profraw"
cargo test --all --no-default-features --features "pg${PGVERSION} pg_test" -- --nocapture
cargo pgrx test "${coverargs[@]}" "pg${PGVERSION}"

grcov "${DESTDIR}" \
--ignore '**/clang-sys*/**' \
Expand Down
62 changes: 22 additions & 40 deletions .github/workflows/lint-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,64 +5,46 @@ on:
branches-ignore: [wip/**]

jobs:
test:
runs-on: ubuntu-latest
container: pgxn/pgxn-tools
strategy:
matrix:
pg: [11, 12, 13, 14, 15, 16]
name: 🐘 Postgres ${{ matrix.pg }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Start PostgreSQL ${{ matrix.pg }}
run: pg-start ${{ matrix.pg }}
- name: Setup Rust Cache
uses: Swatinem/rust-cache@v2
- name: Test on PostgreSQL ${{ matrix.pg }}
run: pgrx-build-test

lint:
name: πŸ”Ž Lint and Cover
name: βœ… Lint and Cover
runs-on: ubuntu-latest
container: pgxn/pgxn-tools
env: { PGVERSION: 16 }
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Rust Toolchain
uses: dtolnay/rust-toolchain@stable
with: { components: "rustfmt, clippy" }
- name: Start PostgreSQL ${{ env.PGVERSION }}
run: pg-start ${{ env.PGVERSION }}
- name: Setup Rust Cache
uses: Swatinem/rust-cache@v2
- name: Install Postgres
run: sudo ./.ci/apt-install-postgres ${{ env.PGVERSION }}
- name: Install pgrx
run: make install-pgrx
- name: Initialize pgrx
run: make pgrx-init
- name: Format and Lint
run: make lint
- name: Generate Coverage
run: make cover RUST_BACKTRACE=1 PGUSER=postgres
run: make cover RUST_BACKTRACE=1 PGUSER=postgres PGDATA=/var/lib/postgresql/pgrx
- name: Publish Coverage
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: tembo-io/pg-jsonschema-boon
files: target/cover/cobertura.xml
- name: Remove Data Diretory
run: rm -rf target/pgrx-test-data-${{ env.PGVERSION }}

test:
runs-on: ubuntu-latest
strategy:
matrix:
pg: [11, 12, 13, 14, 15, 16]
os: [[🐧, Ubuntu]] # [🍎, macOS], [πŸͺŸ, Windows]]
name: 🐘 Postgres ${{ matrix.pg }} on ${{ matrix.os[0] }} ${{ matrix.os[1] }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Rust Toolchain
uses: dtolnay/rust-toolchain@stable
- name: Install Postgres ${{ matrix.pg }}
run: sudo ./.ci/apt-install-postgres ${{ matrix.pg }}
- name: Setup Rust Cache
uses: Swatinem/rust-cache@v2
- name: Install pgrx
run: make install-pgrx
- name: Remove Data Diretory
run: rm -rf target/pgrx-test-data-${{ matrix.pg }}
- name: Initialize pgrx
run: make pgrx-init
- name: Run the tests
run: make test RUST_BACKTRACE=1 PGUSER=postgres
- name: Install
run: make install
- name: Run Install Check
run: make installcheck PGUSER=postgres PGPORT=5433
- name: Remove Data Diretory
run: rm -rf target/pgrx-test-data-${{ matrix.pg }}

0 comments on commit 3d77e3b

Please sign in to comment.