Skip to content

Commit

Permalink
Make CI work with multiple Pg versions, really necessary to
Browse files Browse the repository at this point in the history
test the various differences in backends for an extension like this.
  • Loading branch information
pramsey committed Feb 25, 2022
1 parent 6bb9f52 commit 08fdaf0
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 22 deletions.
42 changes: 34 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 4 additions & 6 deletions expected/http.out
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions http.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -642,18 +641,19 @@ 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);

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
Expand Down
4 changes: 2 additions & 2 deletions sql/http.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 08fdaf0

Please sign in to comment.