From 08fdaf0057081009371fad2a9ad2e1a1056d028e Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Fri, 25 Feb 2022 12:40:05 -0800 Subject: [PATCH] Make CI work with multiple Pg versions, really necessary to test the various differences in backends for an extension like this. --- .github/workflows/ci.yml | 42 ++++++++++++++++++++++++++++++++-------- Makefile | 2 +- expected/http.out | 10 ++++------ http.c | 10 +++++----- sql/http.sql | 4 ++-- 5 files changed, 46 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a37ea8e..9724ace 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,25 +11,51 @@ jobs: runs-on: ubuntu-20.04 env: - PG_VERSION: 14 + PGVER: 10 OS_NAME: focal-pgdg + OS_PGVER: 14 + + + name: "CI" + strategy: + matrix: + ci: + - { PGVER: 9.5 } + - { PGVER: 9.6 } + - { PGVER: 10 } + - { PGVER: 11 } + - { PGVER: 12 } + - { PGVER: 13 } + - { PGVER: 14 } steps: - name: 'Check Out' uses: actions/checkout@v2 - - name: 'Install' + - name: 'Uninstall PostgreSQL' + run: | + sudo apt-get -y -f --ignore-missing --purge remove postgresql postgresql-common postgresql-$OS_PGVER + sudo apt-get -y autoremove + sudo rm -rf /var/lib/postgresql + + - name: 'Install PostgreSQL' run: | + export PGVER=${{ matrix.ci.PGVER }} + export PGDATA=/var/lib/postgresql/$PGVER/main + export PGETC=/etc/postgresql/$PGVER/main + export PGBIN=/usr/lib/postgresql/$PGVER/bin curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - - sudo add-apt-repository "deb http://apt.postgresql.org/pub/repos/apt/ $OS_NAME main $PG_VERSION" - sudo apt-get -y install libcurl4-gnutls-dev postgresql-server-dev-$PG_VERSION - sudo cp ./ci/pg_hba.conf /etc/postgresql/$PG_VERSION/main/pg_hba.conf - sudo systemctl start postgresql.service + sudo add-apt-repository "deb http://apt.postgresql.org/pub/repos/apt/ $OS_NAME main $PGVER" + sudo apt-get -y install libcurl4-gnutls-dev postgresql-server-dev-$PGVER postgresql-client-$PGVER postgresql-$PGVER + sudo su postgres -c "$PGBIN/pg_ctl --pgdata $PGDATA stop" + # sudo $PGBIN/pg_ctlcluster $PGVER main stop + sudo cp ./ci/pg_hba.conf $PGETC/pg_hba.conf + sudo su postgres -c "$PGBIN/pg_ctl --pgdata $PGDATA start -o '-c config_file=$PGETC/postgresql.conf'" - name: 'Build & Test' run: | - export PATH=/usr/lib/postgresql/$PG_VERSION/bin/:$PATH - make + export PATH=/usr/lib/postgresql/$PGVER/bin/:$PATH + make DEBUG=1 all sudo make install PGUSER=postgres make installcheck || (cat regression.diffs && /bin/false) diff --git a/Makefile b/Makefile index acab268..8a01897 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ LIBS += $(shell $(CURL_CONFIG) --libs) SHLIB_LINK := $(LIBS) ifdef DEBUG -COPT += -O0 +COPT += -O0 -Werror endif PGXS := $(shell $(PG_CONFIG) --pgxs) diff --git a/expected/http.out b/expected/http.out index d1dc1c2..40c1590 100644 --- a/expected/http.out +++ b/expected/http.out @@ -180,22 +180,20 @@ BEGIN SELECT status FROM http_get('https://httpbin.org/status/555'); EXCEPTION WHEN OTHERS THEN - RAISE EXCEPTION 'Failed to connect'; + RAISE WARNING 'Failed to connect'; END; $$; -ERROR: Failed to connect -CONTEXT: PL/pgSQL function inline_code_block line 6 at RAISE +WARNING: Failed to connect -- Still an error DO $$ BEGIN SELECT status FROM http_get('https://httpbin.org/status/555'); EXCEPTION WHEN OTHERS THEN - RAISE EXCEPTION 'Failed to connect'; + RAISE WARNING 'Failed to connect'; END; $$; -ERROR: Failed to connect -CONTEXT: PL/pgSQL function inline_code_block line 6 at RAISE +WARNING: Failed to connect -- Reset options SELECT http_reset_curlopt(); http_reset_curlopt diff --git a/http.c b/http.c index 5bec3fe..c3eeb41 100644 --- a/http.c +++ b/http.c @@ -80,7 +80,7 @@ # define table_close(rel, lock) heap_close((rel), (lock)) #endif -#ifndef PG_GETARG_JSONB_P +#if PG_VERSION_NUM < 110000 #define PG_GETARG_JSONB_P(x) DatumGetJsonb(PG_GETARG_DATUM(x)) #endif @@ -597,16 +597,15 @@ static Oid get_extension_schema(Oid ext_oid) { Oid result; - Relation rel; SysScanDesc scandesc; HeapTuple tuple; ScanKeyData entry[1]; - rel = table_open(ExtensionRelationId, AccessShareLock); #if PG_VERSION_NUM >= 120000 Oid pg_extension_oid = Anum_pg_extension_oid; #else Oid pg_extension_oid = ObjectIdAttributeNumber; #endif + Relation rel = table_open(ExtensionRelationId, AccessShareLock); ScanKeyInit(&entry[0], pg_extension_oid, @@ -642,6 +641,7 @@ typname_get_tupledesc(const char *extname, const char *typname) { Oid extoid = get_extension_oid(extname, true); Oid extschemaoid; + Oid typoid; if ( ! OidIsValid(extoid) ) elog(ERROR, "could not lookup '%s' extension oid", extname); @@ -649,11 +649,11 @@ typname_get_tupledesc(const char *extname, const char *typname) extschemaoid = get_extension_schema(extoid); #if PG_VERSION_NUM >= 120000 - Oid typoid = GetSysCacheOid2(TYPENAMENSP, Anum_pg_type_oid, + typoid = GetSysCacheOid2(TYPENAMENSP, Anum_pg_type_oid, PointerGetDatum(typname), ObjectIdGetDatum(extschemaoid)); #else - Oid typoid = GetSysCacheOid2(TYPENAMENSP, + typoid = GetSysCacheOid2(TYPENAMENSP, PointerGetDatum(typname), ObjectIdGetDatum(extschemaoid)); #endif diff --git a/sql/http.sql b/sql/http.sql index 1f8bfd8..a126280 100644 --- a/sql/http.sql +++ b/sql/http.sql @@ -112,7 +112,7 @@ BEGIN SELECT status FROM http_get('https://httpbin.org/status/555'); EXCEPTION WHEN OTHERS THEN - RAISE EXCEPTION 'Failed to connect'; + RAISE WARNING 'Failed to connect'; END; $$; -- Still an error @@ -121,7 +121,7 @@ BEGIN SELECT status FROM http_get('https://httpbin.org/status/555'); EXCEPTION WHEN OTHERS THEN - RAISE EXCEPTION 'Failed to connect'; + RAISE WARNING 'Failed to connect'; END; $$; -- Reset options