Skip to content

Commit

Permalink
CI refactoring, test install from source (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaspermarstal authored Jan 21, 2024
1 parent 7fa55c2 commit 76e6e34
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 30 deletions.
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
.idea/
/debug
/target
*.iml
**/*.rs.bk
Cargo.lock
*.pdb
21 changes: 21 additions & 0 deletions .github/docker/Dockerfile.debian
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM debian:bullseye

ARG PG_MAJOR_VER

RUN apt-get update
RUN apt-get install -y wget gnupg
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ bullseye-pgdg main" >> /etc/apt/sources.list.d/pgdg.list
RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
RUN apt-get update
RUN apt-get install -y build-essential postgresql-server-dev-${PG_MAJOR_VER} postgresql-${PG_MAJOR_VER}

RUN apt-get install -y curl pkg-config
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"

RUN cargo install --locked cargo-pgrx --version 0.11.2
RUN cargo pgrx init --pg${PG_MAJOR_VER} /usr/bin/pg_config

COPY ./ /plprql
WORKDIR /plprql
RUN cargo pgrx install --release -c "/usr/bin/pg_config"
34 changes: 34 additions & 0 deletions .github/docker/run-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#! /usr/bin/env bash

# Environment variables:
# PG_MAJOR_VER: The major version of Postgres in which to build/run. E.g. 14, 12, 15
# DOCKERFILE_ID: The Dockerfile identifier to be built, included in this repo,
# e.g. debian:bullseye or amazon:2
# CARGO_LOCKED_OPTION: Set to '--locked' to use "cargo --locked", or set to
# blank '' to use "cargo" without "--locked"

# Examples of running this script in CI (currently Github Actions):
# ./.github/docker/run-docker.sh 14 debian_bullseye
# ./.github/docker/run-docker.sh 12 fedora

set -x

PG_MAJOR_VER=$1
DOCKERFILE_ID=$2

echo "Building docker container for Postgres version $PG_MAJOR_VER on $DOCKERFILE_ID"
echo "Cargo lock flag set to: '$CARGO_LOCKED_OPTION'"

docker build \
--build-arg PG_MAJOR_VER="$PG_MAJOR_VER" \
-t plprql \
-f ".github/docker/Dockerfile.$DOCKERFILE_ID" \
.

echo "Packaging PL/PRQL for Postgres version $PG_MAJOR_VER on $DOCKERFILE_ID"

docker run plprql \
cargo test \
--no-default-features \
--features "pg$PG_MAJOR_VER" \
"$CARGO_LOCKED_OPTION"
30 changes: 0 additions & 30 deletions .github/workflows/ci.yml

This file was deleted.

33 changes: 33 additions & 0 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: PL/PRQL

on:
# schedule:
# - cron: '0 7 * * MON-FRI'
workflow_dispatch:
# push:
# branches:
# - main
# pull_request:
# branches:
# - main

env:
RUST_BACKTRACE: 1
CARGO_INCREMENTAL: "false"

jobs:
distro_tests:
name: Package
runs-on: ubuntu-latest
strategy:
fail-fast: false # We want all of them to run, even if one fails
matrix:
pg: [ "12" ] # ["12", "13", "14", "15", "16"]
container: [ "debian" ]
steps:
- uses: actions/checkout@v3
- name: Package PL/PRQL for PostgreSQL ${{ matrix.pg }} (${{ matrix.container }})
shell: bash
run: |
docker build --build-arg PG_MAJOR_VER="${{ matrix.pg }}" -t plprql -f ".github/docker/Dockerfile.${{ matrix.container }}" .
docker run plprql cargo test --no-default-features --features "pg${{ matrix.pg }}"
60 changes: 60 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: PL/PRQL

on:
push:
branches:
- main
pull_request:
branches:
- main

env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
CARGO_INCREMENTAL: "false"

jobs:
Test:
strategy:
fail-fast: false # We want all of them to run, even if one fails
matrix:
os: [ ubuntu-latest ]
pg: [ "pg12", "pg13", "pg14", "pg15", "pg16" ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Install cargo-pgrx
run: |
cargo install --locked --version=0.11.2 cargo-pgrx --debug --force
cargo pgrx init --${{ matrix.pg }} download
- name: Run tests
run: cargo test --package plprql --lib plprql::tests --features ${{ matrix.pg }} --no-default-features
Install:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install PostgreSQL headers
run: sudo apt-get install postgresql-server-dev-14
- name: Install cargo-pgrx
run: |
cargo install --locked --version=0.11.2 cargo-pgrx --debug --force
cargo pgrx init --pg14 $(which pg_config)
- name: Install PL/PRQL
run: |
# Touching these files is a workaround for std::canonicalize not working if file does not exist (v0.11.2 cargo-pgrx/src/command/sudo_install.rs#L72)
# This has been fixed on develop and can be removed when next version of pgrx is released
sudo touch /usr/share/postgresql/14/extension/plprql--0.0.1.sql
sudo touch /usr/share/postgresql/14/extension/plprql.control
sudo touch /usr/lib/postgresql/14/lib/plprql.so
cargo pgrx install --no-default-features --release --sudo
- name: Start PostgreSQL
run: |
sudo systemctl start postgresql.service
pg_isready
# superuser (-s), can create databases (-d) and roles (-r), no password prompt (-w) named runner
sudo -u postgres createuser -s -d -r -w runner
- name: Verify install
run: |
createdb -U runner runner
psql -U runner -c "create extension plprql;"
psql -U runner -c "select prql_to_sql('from table');"

0 comments on commit 76e6e34

Please sign in to comment.