Skip to content

Commit 410689b

Browse files
committed
Separate tests for Postgres 11 and 12.
1 parent fc30a21 commit 410689b

File tree

7 files changed

+62
-26
lines changed

7 files changed

+62
-26
lines changed

.github/workflows/tests.yml renamed to .github/workflows/tests-pg11.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Tests
1+
name: Tests on PG11
22

33
on: [push]
44

@@ -11,4 +11,4 @@ jobs:
1111
steps:
1212
- uses: actions/checkout@v2
1313
- name: Build and run tests in Docker
14-
run: env USE_DOCKER=1 ./build-and-test.sh
14+
run: env USE_DOCKER=1 POSTGRES_VERSION=11 ./build-and-test.sh

.github/workflows/tests-pg12.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Tests on PG12
2+
3+
on: [push]
4+
5+
jobs:
6+
7+
build:
8+
9+
runs-on: ubuntu-18.04
10+
11+
steps:
12+
- uses: actions/checkout@v2
13+
- name: Build and run tests in Docker
14+
run: env USE_DOCKER=1 POSTGRES_VERSION=12 ./build-and-test.sh

Dockerfile.test

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
11
FROM ubuntu:18.04
22

3-
ARG POSTGRES_VERSION=11
4-
53
RUN apt-get update \
64
&& apt-get install -y curl gnupg2 \
75
&& echo "deb http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main" > /etc/apt/sources.list.d/pgdg.list \
86
&& curl -sL https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
97
&& apt-get update \
108
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
11-
build-essential \
12-
postgresql-${POSTGRES_VERSION} \
13-
postgresql-server-dev-${POSTGRES_VERSION} \
14-
ruby \
15-
sudo \
9+
build-essential \
10+
ruby \
11+
sudo \
1612
&& apt-get clean \
1713
&& rm -Rf /var/lib/apt/lists/*
1814

19-
RUN sudo /etc/init.d/postgresql restart \
20-
&& sudo -u postgres createuser -s root
15+
# Compiling the protobuf library is quite slow, so do this before installing the correct Postgres version
16+
COPY build-protobuf-library.sh /app/
17+
RUN /app/build-protobuf-library.sh
18+
19+
ARG POSTGRES_VERSION=11
2120

22-
COPY Makefile /app/
23-
RUN make -C app protoc
21+
RUN apt-get update \
22+
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
23+
postgresql-${POSTGRES_VERSION} \
24+
postgresql-server-dev-${POSTGRES_VERSION} \
25+
&& apt-get clean \
26+
&& rm -Rf /var/lib/apt/lists/* \
27+
&& /etc/init.d/postgresql restart \
28+
&& sudo -u postgres createuser -s root
2429

25-
COPY *.hpp *.cpp *.rb *.sh *.sql *.control *.md /app/
2630
COPY /test_protos /app/test_protos
31+
COPY Makefile *.hpp *.cpp *.rb *.sh *.sql *.control *.md /app/

Makefile

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
PROTOBUF_VERSION=3.11.2
3-
PROTOBUF_ROOT=third_party/protobuf-$(PROTOBUF_VERSION)
2+
3+
PROTOBUF_ROOT=third_party/protobuf
44
PROTOC=$(PROTOBUF_ROOT)/src/protoc
55

66
MODULE_big = postgres_protobuf
@@ -33,18 +33,15 @@ clean: pb_clean
3333

3434
protoc: $(PROTOC)
3535

36-
# Hack to get protobuf headers before building any of our stuff
36+
# Hack to get protobuf headers and libraries before building any of our stuff
3737
$(OBJS) $(BC_FILES): $(PROTOC)
3838

3939
# Instead of proper dependency tracking, it's easier to make all compilation units depend on all headers.
4040
# Good enough for a small project.
4141
$(OBJS) $(BC_FILES): $(wildcard *.hpp)
4242

4343
$(PROTOC):
44-
rm -Rf third_party/protobuf-*
45-
mkdir -p third_party/
46-
cd third_party && curl -L "https://github.com/protocolbuffers/protobuf/releases/download/v$(PROTOBUF_VERSION)/protobuf-cpp-$(PROTOBUF_VERSION).tar.gz" | tar xzf -
47-
cd third_party/protobuf-$(PROTOBUF_VERSION) && ./configure --with-pic --enable-static && make -j16
44+
./build-protobuf-library.sh
4845

4946
sql/postgres_protobuf.sql: generate_test_cases.rb $(DESC_SET_FILES)
5047
env PROTOC=$(PROTOC) ./generate_test_cases.rb sql

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ which means that field renames will break backwards- and forwards-compatibility.
3232

3333
## Installation
3434

35+
Requires Postgres 11 or newer.
36+
3537
Prerequisites for installing from source:
3638

3739
- Postgres server headers (if you use the Postgres APT repo, install `postgresql-server-dev-$VERSION`)

build-and-test.sh

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@ set -euxo pipefail
33

44
cd "$(dirname "${0}")"
55

6-
if [ -n "${USE_DOCKER:-}" ]; then
7-
docker build -f Dockerfile.test -t postgres-protobuf-test .
8-
docker run postgres-protobuf-test env __IN_DOCKER=1 /app/build-and-test.sh
6+
POSTGRES_VERSION=${POSTGRES_VERSION:-11}
7+
8+
if [[ -n "${USE_DOCKER:-}" ]]; then
9+
unset USE_DOCKER
10+
docker build -f Dockerfile.test --build-arg=POSTGRES_VERSION="${POSTGRES_VERSION}" -t postgres-protobuf-test:"${POSTGRES_VERSION}" .
11+
docker run postgres-protobuf-test:"${POSTGRES_VERSION}" env __IN_DOCKER=1 /app/build-and-test.sh
912
exit $?
1013
fi
1114

12-
if [ -n "${__IN_DOCKER:-}" ]; then
15+
if [[ -n "${__IN_DOCKER:-}" ]]; then
1316
sudo /etc/init.d/postgresql restart
1417
fi
1518

16-
if [ -z "${NO_CLEAN:-}" ]; then
19+
if [[ -z "${NO_CLEAN:-}" ]]; then
1720
make clean
1821
fi
1922

build-protobuf-library.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
set -euxo pipefail
3+
4+
PROTOBUF_VERSION=3.11.2
5+
6+
cd "$(dirname "${0}")"
7+
8+
rm -Rf third_party/protobuf-*
9+
mkdir -p third_party/
10+
cd third_party
11+
curl -L "https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOBUF_VERSION}/protobuf-cpp-${PROTOBUF_VERSION}.tar.gz" | tar xzf -
12+
mv protobuf-"${PROTOBUF_VERSION}" protobuf
13+
cd protobuf
14+
./configure --with-pic --enable-static
15+
make -j16

0 commit comments

Comments
 (0)