diff --git a/.github/actions/pgx-init/action.yml b/.github/actions/pgx-init/action.yml index a5644af6..431606e5 100644 --- a/.github/actions/pgx-init/action.yml +++ b/.github/actions/pgx-init/action.yml @@ -4,6 +4,12 @@ inputs: working-directory: description: 'The directory in which there is a pgrx extension project' required: true + pg_version: + description: 'The version of postgres' + default: "15.4" + pgrx_pg_version: + description: 'Pgrx pg version alias' + default: "pg15" outputs: {} runs: using: "composite" @@ -35,12 +41,11 @@ runs: working-directory: ${{ inputs.working-directory }} run: | set -x - pg_version=$(stoml Cargo.toml features.default) # pgrx init can take a long time, and it re-compiles postgres even when there # is a cached version. So, we can just check for the directory and cat /home/runner/.pgrx/config.toml || true - if find /home/runner/.pgrx | grep $(awk -F "=" '/${pg_version}/ {print $2}' /home/runner/.pgrx/config.toml | tr -d '"'); then + if find /home/runner/.pgrx | grep $(awk -F "=" '/${{ inputs.pg_version}}/ {print $2}' /home/runner/.pgrx/config.toml | tr -d '"'); then echo "Already found pgrx is initialized. Skipping 'cargo pgrx init' command." else - cargo pgrx init --${pg_version} download || true + cargo pgrx init --${{inputs.pgrx_pg_version}} download || true fi diff --git a/.github/workflows/extension_ci.yml b/.github/workflows/extension_ci.yml index 85d32be2..35b29d70 100644 --- a/.github/workflows/extension_ci.yml +++ b/.github/workflows/extension_ci.yml @@ -51,6 +51,17 @@ jobs: test: name: Run tests runs-on: ubuntu-22.04 + strategy: + fail-fast: false + matrix: + pg: [ + {version: "12.16", pgrx_version: "pg12"}, + {version: "13.12", pgrx_version: "pg13"}, + {version: "14.9", pgrx_version: "pg14"}, + {version: "15.4", pgrx_version: "pg15"}, + #TODO: must update pgrx to support pg16 + # {version: "16.0", pgrx_version: "pg16", server_dev: "postgresql-server-dev-all"}, + ] steps: - uses: actions/checkout@v2 - name: Install Rust stable toolchain @@ -59,7 +70,7 @@ jobs: toolchain: stable - uses: Swatinem/rust-cache@v2 with: - prefix-key: "pgmq-extension-test" + prefix-key: "pgmq-extension-test-${{ matrix.pg.pgrx_version }}" workspaces: | pgmq # Additional directories to cache @@ -68,19 +79,23 @@ jobs: - uses: ./.github/actions/pgx-init with: working-directory: ./ + pgrx_pg_version: ${{ matrix.pg.pgrx_version }} + pg_version: ${{ matrix.pg.version }} - name: test run: | - sudo apt-get update && sudo apt-get install -y postgresql-server-dev-14 + sudo apt-get update + sudo apt-get install -y --allow-downgrades postgresql-client-common=238 + sudo apt-get install -y --allow-downgrades postgresql-common=238 postgresql-server-dev-14 + sudo apt-get install -y --allow-downgrades postgresql-server-dev-all git clone https://github.com/pgpartman/pg_partman.git && \ cd pg_partman && \ git checkout v4.7.4 && \ sudo make install && cd ../ - cp /usr/share/postgresql/14/extension/pg_partman* ~/.pgrx/15.4/pgrx-install/share/postgresql/extension/ - cp /usr/lib/postgresql/14/lib/pg_partman_bgw.so ~/.pgrx/15.4/pgrx-install/lib/postgresql/ + cp /usr/share/postgresql/14/extension/pg_partman* ~/.pgrx/${{ matrix.pg.version }}/pgrx-install/share/postgresql/extension/ + cp /usr/lib/postgresql/14/lib/pg_partman_bgw.so ~/.pgrx/${{ matrix.pg.version }}/pgrx-install/lib/postgresql/ rm -rf ./target/pgrx-test-data-* || true - pg_version=$(stoml Cargo.toml features.default) - cargo pgrx run ${pg_version} --pgcli || true - make test + cargo pgrx run ${{ matrix.pg.pgrx_version }} --pgcli || true + PGRX_POSTGRES=${{ matrix.pg.pgrx_version }} make test publish: # only publish release events diff --git a/Makefile b/Makefile index 4dad260c..7d3e087e 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,8 @@ +PGRX_POSTGRES ?= pg15 + test: - cargo pgrx test - cargo test -- --test-threads=1 --ignored + cargo pgrx test $(PGRX_POSTGRES) + cargo test --no-default-features --features ${PGRX_POSTGRES} -- --test-threads=1 --ignored format: cargo +nightly fmt --all diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 683f813f..406d5c7c 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -40,9 +40,10 @@ async fn connect(url: &str) -> Pool { async fn init_database() -> Pool { let username = whoami::username(); + let database_port = database_port(); let conn00 = connect(&format!( - "postgres://{username}:postgres@localhost:28815/pgmq" + "postgres://{username}:postgres@localhost:{database_port}/pgmq" )) .await; // ignore the error if the db already exists! @@ -669,7 +670,22 @@ async fn send_sample_message(queue_name: &String, conn: &Pool) -> i64 .get::(0) } -pub fn database_name() -> String { +fn database_name() -> String { let username = whoami::username(); - format!("postgres://{username}:postgres@localhost:28815/pgmq_test") + let database_port = database_port(); + format!("postgres://{username}:postgres@localhost:{database_port}/pgmq_test") +} + +fn database_port() -> usize { + if cfg!(feature = "pg15") { + 28815 + } else if cfg!(feature = "pg14") { + 28814 + } else if cfg!(feature = "pg13") { + 28813 + } else if cfg!(feature = "pg12") { + 28812 + } else { + 5432 + } }