diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..f3fc85e --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +.DS_Store +.idea/ +/debug +/target +*.iml +**/*.rs.bk +Cargo.lock +*.pdb diff --git a/.github/docker/Dockerfile.debian b/.github/docker/Dockerfile.debian new file mode 100644 index 0000000..f893a81 --- /dev/null +++ b/.github/docker/Dockerfile.debian @@ -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" diff --git a/.github/docker/run-docker.sh b/.github/docker/run-docker.sh new file mode 100644 index 0000000..c397bd3 --- /dev/null +++ b/.github/docker/run-docker.sh @@ -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" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index cea5c57..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,30 +0,0 @@ -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: - matrix: - os: [ubuntu-latest] - pg: ["12", "13", "14", "15", "16"] - 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 - - name: Init pgrx - run: cargo pgrx init --pg${{ matrix.pg }} download - - name: Run tests - run: cargo test --package plprql --lib plprql::tests --features pg${{ matrix.pg }} --no-default-features diff --git a/.github/workflows/package.yml b/.github/workflows/package.yml new file mode 100644 index 0000000..5c91186 --- /dev/null +++ b/.github/workflows/package.yml @@ -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 }}" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..04be254 --- /dev/null +++ b/.github/workflows/test.yml @@ -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');"