Skip to content

Commit 0db18ef

Browse files
MinhLA1410MinhLA
andauthored
Improve CI scripts (#103)
* improve CI scripts supporting tests with PostGIS on CI Actions --------- Co-authored-by: MinhLA <vagrant@localhost.localdomain>
1 parent f2475fb commit 0db18ef

File tree

7 files changed

+138
-25
lines changed

7 files changed

+138
-25
lines changed

.github/workflows/CI.yml

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,47 +26,60 @@ jobs:
2626
env:
2727
SQLITE_VERSION : "3420000"
2828
SQLITE_YEAR: "2023"
29+
POSTGIS_VERSION : "3.4.2"
2930
HTTP_PROXY: ""
3031
HTTPS_PROXY: ""
3132
strategy:
3233
fail-fast: false
3334
matrix:
3435
pg: ${{ fromJSON(needs.detect-pgversion.outputs.pgversion) }}
36+
config: ["default", "postgis"]
3537

36-
name: Test on PostgreSQL ${{ matrix.pg }}
38+
name: Test on PostgreSQL ${{ matrix.pg }}, ${{ matrix.config }} mode
3739
runs-on: ubuntu-22.04
3840
steps:
3941
- uses: actions/checkout@v4
4042

4143
- name: tar
4244
run: tar zcvf sqlite_fdw.tar.gz ./*
43-
45+
4446
- name: set_proxy
4547
run: bash GitHubActions/env.sh
4648

4749
- name: install locales
4850
run: bash GitHubActions/install_locales.sh
49-
50-
- name: build PostgreSQL ${{ matrix.pg }}
51+
52+
- name: build PostgreSQL ${{ matrix.pg }} with ${{ matrix.config }}
5153
run: bash GitHubActions/build_postgres.sh ${{ matrix.pg }}
5254

53-
- name: install SQLite
54-
run: bash GitHubActions/install_sqlite.sh ${{ env.SQLITE_VERSION }} ${{ env.SQLITE_YEAR }}
55-
56-
- name: build sqlite_fdw
57-
run: bash GitHubActions/build_sqlite_fdw.sh ${{ matrix.pg }}
58-
55+
- name: build PostGIS ${{ env.POSTGIS_VERSION }} for PostgreSQL ${{ matrix.pg }}, ${{ matrix.config }} mode
56+
run: |
57+
if [[ "${{ matrix.config }}" == "postgis" ]]; then
58+
bash GitHubActions/build_postgis.sh ${{ matrix.pg }} ${{ env.POSTGIS_VERSION }}
59+
fi
60+
61+
- name: install SQLite, ${{ matrix.config }} mode
62+
run: |
63+
if [[ "${{ matrix.config }}" == "default" ]]; then
64+
bash GitHubActions/install_sqlite.sh ${{ env.SQLITE_VERSION }} ${{ env.SQLITE_YEAR }}
65+
elif [[ "${{ matrix.config }}" == "postgis" ]]; then
66+
bash GitHubActions/install_sqlite.sh ${{ env.SQLITE_VERSION }} ${{ env.SQLITE_YEAR }} --enable-rtree
67+
fi
68+
69+
- name: build sqlite_fdw, ${{ matrix.config }} mode
70+
run: |
71+
bash GitHubActions/build_sqlite_fdw.sh ${{ matrix.pg }} ${{ matrix.config }}
72+
5973
- name: execute sqlite_fdw test
60-
run: bash GitHubActions/execute_test.sh ${{ matrix.pg }}
61-
74+
run: bash GitHubActions/execute_test.sh ${{ matrix.pg }} ${{ matrix.config }}
75+
6276
- name: download output files (regression.diffs)
6377
if: failure()
6478
uses: actions/upload-artifact@v4
6579
with:
66-
name: ${{ matrix.pg }}-test-results
80+
name: ${{ matrix.pg }}-${{ matrix.config }}-test-results
6781
path: |
6882
workdir/postgresql-${{ matrix.pg }}/contrib/sqlite_fdw/regression.diffs
6983
workdir/postgresql-${{ matrix.pg }}/contrib/sqlite_fdw/regression.out
7084
workdir/postgresql-${{ matrix.pg }}/contrib/sqlite_fdw/results
7185
retention-days: 7
72-

GitHubActions/build_postgis.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
################################################################################
4+
#
5+
# This script downloads PostgreSQL from the official web site into ./workdir
6+
# then builds it.
7+
#
8+
# Usage: ./build_postgres.sh pg_version postgis_version
9+
# pg_version is a PostgreSQL version to be installed like 16.0.
10+
# postgis_version is a PostGIS version to be installed.
11+
#
12+
# Requirements
13+
# - be able to connect to the PostgreSQL official web site by curl.
14+
#
15+
################################################################################
16+
17+
POSTGRESQL_VERSION=$1
18+
POSTGIS_VERSION=$2
19+
20+
cd ./workdir
21+
cd postgresql-${POSTGRESQL_VERSION}
22+
23+
# Install necessary dependencies
24+
sudo apt update
25+
sudo apt install -y build-essential libxml2-dev libgeos-dev libproj-dev libgdal-dev libjson-c-dev libprotobuf-c-dev protobuf-c-compiler
26+
27+
GEOS_CONFIG_PATH=$(which geos-config)
28+
29+
# Download and compile PostGIS
30+
cd contrib
31+
wget http://download.osgeo.org/postgis/source/postgis-${POSTGIS_VERSION}.tar.gz
32+
tar -xzf postgis-${POSTGIS_VERSION}.tar.gz
33+
mv postgis-${POSTGIS_VERSION} postgis -v
34+
cd postgis
35+
echo " - PostGIS directory"
36+
export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH
37+
./configure --with-pgconfig=/usr/local/pgsql/bin/pg_config --with-geosconfig=$GEOS_CONFIG_PATH
38+
make
39+
sudo make install

GitHubActions/build_postgres.sh

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,35 @@
55
# This script downloads PostgreSQL from the official web site into ./workdir
66
# then builds it.
77
#
8-
# Usage: ./build_postgres.sh pg_version
8+
# Usage: ./build_postgres.sh pg_version [configure_options]
99
# pg_version is a PostgreSQL version to be installed like 16.0.
10+
# configure_options are a list of option for postgres server.
1011
#
1112
# Requirements
1213
# - be able to connect to the PostgreSQL official web site by curl.
1314
#
1415
################################################################################
1516

1617
VERSION=$1
18+
CONFIGURE_OPTIONS=""
19+
20+
while (( "$#" )); do
21+
CONFIGURE_OPTIONS="$CONFIGURE_OPTIONS $2"
22+
shift
23+
done
24+
1725
mkdir -p ./workdir
1826
cd ./workdir
1927
curl -O https://ftp.postgresql.org/pub/source/v${VERSION}/postgresql-${VERSION}.tar.bz2
2028
tar xjf postgresql-${VERSION}.tar.bz2
2129
cd postgresql-${VERSION}
22-
./configure
30+
31+
if [ -z "$CONFIGURE_OPTIONS" ]; then
32+
./configure
33+
else
34+
./configure $CONFIGURE_OPTIONS
35+
fi
36+
2337
make
38+
sudo make install
39+
sudo chown -R $USER /usr/local/pgsql

GitHubActions/build_sqlite_fdw.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
#
55
# This script builds sqlite_fdw in PostgreSQL source tree.
66
#
7-
# Usage: ./build_sqlite_fdw.sh pg_version
7+
# Usage: ./build_sqlite_fdw.sh pg_version mode
88
# pg_version is a PostgreSQL version like 16.0 to be built in.
9+
# mode is flag for sqlite_fdw compiler.
910
#
1011
# Requirements
1112
# - the source code of sqlite_fdw is available by git clone.
@@ -14,8 +15,17 @@
1415
################################################################################
1516

1617
VERSION=$1
18+
MODE="$2"
19+
1720
mkdir -p ./workdir/postgresql-${VERSION}/contrib/sqlite_fdw
1821
tar zxvf ./sqlite_fdw.tar.gz -C ./workdir/postgresql-${VERSION}/contrib/sqlite_fdw/
1922
cd ./workdir/postgresql-${VERSION}/contrib/sqlite_fdw
2023
export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH
21-
make
24+
25+
if [ "$MODE" == "postgis" ]; then
26+
make ENABLE_GIS=1
27+
else
28+
make
29+
fi
30+
31+
sudo make install

GitHubActions/execute_test.sh

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
# sqlite_fdw. If all tests are passed, this script will exit successfully.
77
# Otherwise, it will exit with failure.
88

9-
# Usage: ./execute_test.sh pg_version
9+
# Usage: ./execute_test.sh pg_version mode
1010
# pg_version is a PostgreSQL version to be tested like 16.0.
11+
# mode is flag for sqlite_fdw compiler.
1112
#
1213
# Requiremets
1314
# - the source code of PostgreSQL is located in ./workdir/postgresql-{pg_version}.
@@ -20,9 +21,26 @@
2021
################################################################################
2122

2223
VERSION=$1
24+
MODE="$2"
25+
2326
cd ./workdir/postgresql-${VERSION}/contrib/sqlite_fdw
27+
28+
if [ "$MODE" == "postgis" ]; then
29+
MAKEFILE_OPT="ENABLE_GIS=1"
30+
echo "$MODE mode, makefile option = $MAKEFILE_OPT"
31+
32+
# Start postgres server
33+
POSTGRES_HOME=/usr/local/pgsql
34+
${POSTGRES_HOME}/bin/initdb ${POSTGRES_HOME}/databases
35+
${POSTGRES_HOME}/bin/pg_ctl -D ${POSTGRES_HOME}/databases -l logfile start
36+
37+
# Change the testing method
38+
sed -i 's/make check/make installcheck/' test.sh
39+
fi
40+
41+
# Execute test script
2442
chmod +x ./test.sh
25-
./test.sh
43+
./test.sh $MAKEFILE_OPT
2644

2745
last_line=$(tail -n 1 make_check.out)
2846
third_line_from_the_last=$(tail -n 3 make_check.out | head -n 1)

GitHubActions/install_sqlite.sh

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
# This sript downloads SQLite source code from the official web site into
66
# ./workdir then builds and installs it.
77
#
8-
# Usage: ./install_sqlite.sh version year
8+
# Usage: ./install_sqlite.sh version year [configure_options]
99
# version: SQLite version to be installed
1010
# year: A year of SQLite released. It is used for determining a download URL.
11+
# configure_options are a list of option for sqlite server.
1112
#
12-
# Ex) ./install_sqlite.sh 3420000 2023
13+
# Ex) ./install_sqlite.sh 3420000 2023 --enable-rtree
1314
#
1415
# Requirements
1516
# - be able to connect to the SQLite official web site by curl.
@@ -19,11 +20,25 @@
1920

2021
VERSION=$1
2122
YEAR=$2
23+
24+
CONFIGURE_OPTIONS=""
25+
26+
while (( "$#" )); do
27+
CONFIGURE_OPTIONS="$CONFIGURE_OPTIONS $3"
28+
shift
29+
done
30+
2231
mkdir -p ./workdir
2332
cd ./workdir
2433
curl -O https://www.sqlite.org/${YEAR}/sqlite-src-${VERSION}.zip
25-
unzip sqlite-src-${VERSION}.zip
34+
unzip sqlite-src-${VERSION}.zip > /dev/null
2635
cd sqlite-src-${VERSION}
27-
./configure --enable-fts5
36+
37+
if [ -z "$CONFIGURE_OPTIONS" ]; then
38+
./configure --enable-fts5
39+
else
40+
./configure --enable-fts5 $CONFIGURE_OPTIONS
41+
fi
42+
2843
make
2944
sudo make install

test.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/bin/bash
2+
13
testdir='/tmp/sqlite_fdw_test';
24
rm -rf "$testdir";
35
mkdir "$testdir";
@@ -10,6 +12,6 @@ sqlite3 "$testdir/selectfunc.db" < sql/init_data/init_selectfunc.sql;
1012

1113
sed -i 's/REGRESS =.*/REGRESS = extra\/sqlite_fdw_post extra\/bitstring extra\/bool extra\/float4 extra\/float8 extra\/int4 extra\/int8 extra\/numeric extra\/out_of_range extra\/timestamp extra\/uuid extra\/join extra\/limit extra\/aggregates extra\/prepare extra\/select_having extra\/select extra\/insert extra\/update extra\/encodings sqlite_fdw type aggregate selectfunc /' Makefile
1214

13-
make clean;
15+
make clean $1;
1416
make $1;
1517
make check $1 | tee make_check.out;

0 commit comments

Comments
 (0)