Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Redis FDW test

on:
workflow_dispatch:
pull_request:
push:
branches:
- master
- main
jobs:
detect-pgversion:
runs-on: ubuntu-22.04
outputs:
pgversion: ${{ steps.detect-pgversion.outputs.targets }}
steps:
- uses: actions/checkout@v4

- name: detect-pgversion
id: detect-pgversion
run: |
targets=`bash GitHubActions/detect_targets.sh`
echo "targets=$targets" >> $GITHUB_OUTPUT

test:
needs: detect-pgversion
env:
POSTGIS_VERSION : "3.4.2"
HTTP_PROXY: ""
HTTPS_PROXY: ""
HIREDIS_FOR_TESTING_DIR: "/opt/hiredis_testing"
strategy:
fail-fast: false
matrix:
pg: ${{ fromJSON(needs.detect-pgversion.outputs.pgversion) }}
config: ["default", "postgis"]

name: Test on PostgreSQL ${{ matrix.pg }}, ${{ matrix.config }} mode
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4

- name: tar
run: tar zcvf redis_fdw.tar.gz ./*

- name: set_proxy
run: bash GitHubActions/env.sh

- name: download PostGIS, ${{ matrix.config }} mode
run: |
if [[ "${{ matrix.config }}" == "postgis" ]]; then
bash GitHubActions/download_postgis.sh ${{ env.POSTGIS_VERSION }}
fi

- name: install locales
run: bash GitHubActions/install_locales.sh

- name: build PostgreSQL ${{ matrix.pg }}
run: bash GitHubActions/build_postgres.sh ${{ matrix.pg }}

- name: install Redis, ${{ matrix.config }} mode
run: bash GitHubActions/install_redis.sh ${{ matrix.config }} ${{ env.HIREDIS_FOR_TESTING_DIR }}

- name: build PostGIS ${{ env.POSTGIS_VERSION }} for PostgreSQL ${{ matrix.pg }}, ${{ matrix.config }} mode
run: |
if [[ "${{ matrix.config }}" == "postgis" ]]; then
bash GitHubActions/build_postgis.sh ${{ matrix.pg }} ${{ env.POSTGIS_VERSION }}
fi

- name: build redis_fdw, ${{ matrix.config }} mode
run: |
bash GitHubActions/build_redis_fdw.sh ${{ matrix.pg }} ${{ matrix.config }} ${{ env.HIREDIS_FOR_TESTING_DIR }}

- name: execute redis_fdw test
run: bash GitHubActions/execute_test.sh ${{ matrix.pg }} ${{ matrix.config }} ${{ env.HIREDIS_FOR_TESTING_DIR }}

- name: download output files (regression.diffs)
if: failure()
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.pg }}-${{ matrix.config }}-test-results
path: |
workdir/postgresql-${{ matrix.pg }}/contrib/redis_fdw/test/regression.diffs
workdir/postgresql-${{ matrix.pg }}/contrib/redis_fdw/test/regression.out
workdir/postgresql-${{ matrix.pg }}/contrib/redis_fdw/test/results
retention-days: 7

13 changes: 13 additions & 0 deletions GitHubActions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# CI environment of redis_fdw.

Tests will be executed automatically when commited to main/master branch and when a pull request was opened/updated.
It is realized by using GitHub actions.

The CI process is defined in .github/workflows/CI.yml file.
Scripts in this directory (GitHubActions/*.sh) are referred by CI.yml.

The regression test will be executed for multi-versions of PostgreSQL.
Target versions are determined automatically based on directory names in "expected" directory.

If the regression test failed, test result files (result directory, regression.diff amd regression.out) are uploaded as artifacts.
7 days later, artifact files will be deleted.
41 changes: 41 additions & 0 deletions GitHubActions/build_postgis.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

################################################################################
#
# This script downloads PostGIS from the official web site into ./workdir
# then builds it.
#
# Usage: ./build_postgis.sh pg_version postgis_version
# pg_version is a PostgreSQL version to be installed like 16.0.
# postgis_version is a PostGIS version to be installed.
#
# Requirements
# - be able to connect to the PostGIS official web site by wget.
#
################################################################################

POSTGRESQL_VERSION=$1
POSTGIS_VERSION=$2

# Install necessary dependencies
sudo apt update
sudo apt install -y build-essential libxml2-dev libgeos-dev libproj-dev libgdal-dev libjson-c-dev libprotobuf-c-dev protobuf-c-compiler

cd ./workdir
# Download and compile PostGIS
cp -vr postgis "postgresql-${POSTGRESQL_VERSION}/contrib"
(
cd "postgresql-${POSTGRESQL_VERSION}/contrib/postgis"
echo " - PostGIS directory"
GEOS_CONFIG_PATH=$(which geos-config)
export LD_LIBRARY_PATH="/usr/local/lib/:$LD_LIBRARY_PATH"
./configure --with-pgconfig=/usr/local/pgsql/bin/pg_config --with-geosconfig=$GEOS_CONFIG_PATH
make
sudo make install
)

(
cd "postgresql-${POSTGRESQL_VERSION}/contrib/hstore"
make
sudo make install
)
42 changes: 42 additions & 0 deletions GitHubActions/build_postgres.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

################################################################################
#
# This script downloads PostgreSQL from the official web site into ./workdir
# then builds it.
#
# Usage: ./build_postgres.sh pg_version [configure_options]
# pg_version is a PostgreSQL version to be installed like 17.0.
# configure_options are a list of option for postgres server.
#
# Requirements
# - be able to connect to the PostgreSQL official web site by curl.
#
################################################################################

POSTGRESQL_VERSION=$1
CONFIGURE_OPTIONS=""

while (( "$#" )); do
CONFIGURE_OPTIONS="$CONFIGURE_OPTIONS $2"
shift
done

mkdir -p ./workdir
cd ./workdir
adr="https://ftp.postgresql.org/pub/source/v${POSTGRESQL_VERSION}/postgresql-${POSTGRESQL_VERSION}.tar.bz2";
echo "PG version URL:
$adr"
curl -O "$adr"
tar xjf postgresql-${POSTGRESQL_VERSION}.tar.bz2
cd postgresql-${POSTGRESQL_VERSION}

if [ -z "$CONFIGURE_OPTIONS" ]; then
./configure
else
./configure $CONFIGURE_OPTIONS
fi

make
sudo make install
sudo chown -R $USER /usr/local/pgsql
35 changes: 35 additions & 0 deletions GitHubActions/build_redis_fdw.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

################################################################################
#
# This script builds redis_fdw in PostgreSQL source tree.
#
# Usage: ./build_redis_fdw.sh pg_version mode hiredis_for_testing_dir
# pg_version is a PostgreSQL version like 17.0 to be built in.
# mode is flag for redis_fdw compiler.
# hiredis_for_testing_dir: path to install directory of hiredis version for testing
#
# Requirements
# - the source code of redis_fdw is available by git clone.
# - the source code of PostgreSQL is located in ~/workdir/postgresql-{pg_version}.
# - Hiredis development package is installed in a system.
################################################################################

VERSION="$1"
MODE="$2"
HIREDIS_FOR_TESTING_DIR="$3"

mkdir -p ./workdir/postgresql-${VERSION}/contrib/redis_fdw
tar zxf ./redis_fdw.tar.gz -C ./workdir/postgresql-${VERSION}/contrib/redis_fdw/
cd ./workdir/postgresql-${VERSION}/contrib/redis_fdw

# show locally compiled hiredis library
ls -la /usr/local/lib

if [ "$MODE" == "postgis" ]; then
make ENABLE_GIS=1 HIREDIS_FOR_TESTING_DIR="$3"
else
make HIREDIS_FOR_TESTING_DIR="$3"
fi

sudo make install
30 changes: 30 additions & 0 deletions GitHubActions/detect_targets.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

################################################################################
#
# This script detects target PostgreSQL versions for redis_fdw testing from
# directory names in ./sql directory. Detected versions will be outputed to
# the standard output as an array of string like ["16.3","17.0"].
#
# Usage: ./detect_targets.sh
#
# Requirements
# - there is a directory named "sql" in a curent directory.
#
################################################################################

dirs="./test/expected/*"
pattern="[0-9]+(\.|rc)[0-9]+"
targets="["
for pathname in $dirs; do
if [[ "$pathname" =~ $pattern ]]; then
target=`basename $pathname`
if [ "$targets" != "[" ]; then
targets+=","
fi
targets+="\"$target\""
fi
done
targets+="]"

echo "$targets"
28 changes: 28 additions & 0 deletions GitHubActions/download_postgis.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

################################################################################
#
# This script downloads PostGIS from the official web site into ./workdir
# then builds it.
#
# Usage: ./download_postgis.sh postgis_version
# postgis_version is a PostGIS version to be installed.
#
# Requirements
# - be able to connect to the PostGIS official web site by wget.
#
################################################################################

POSTGIS_VERSION=$1

mkdir -p ./workdir
cd ./workdir
pgisfile="postgis-${POSTGIS_VERSION}.tar.gz"
if [ ! -f "$pgisfile" ]; then
wget -nv "http://download.osgeo.org/postgis/source/$pgisfile"
tar -xzf "$pgisfile"
mv postgis-${POSTGIS_VERSION} postgis -v
echo "PostGIS source code directory " $(dirname $(readlink -f postgis))
else
echo "PostGIS downloaded"
fi
20 changes: 20 additions & 0 deletions GitHubActions/env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

################################################################################
#
# This script configures apt.conf to set a proxy if an environment variable
# HTTP_PROXY or HTTPS_PROXY is set.
#
# Usage: ./env.sh
#
# Requirements
# - having superuser privileges
#
################################################################################

if [ -z $HTTP_PROXY ] && [ "$HTTP_PROXY" != "" ]; then
echo 'Acquire::http::proxy "$HTTP_PROXY";' | sudo tee /etc/apt/apt.conf
fi
if [ -z $HTTPS_PROXY ] && [ "$HTTPS_PROXY" != "" ]; then
echo 'Acquire::https::proxy "$HTTPS_PROXY";' | sudo tee -a /etc/apt/apt.conf
fi
61 changes: 61 additions & 0 deletions GitHubActions/execute_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash

################################################################################
#
# This script executes a regression test pf redis_fdw by calling test.sh in
# redis_fdw. If all tests are passed, this script will exit successfully.
# Otherwise, it will exit with failure.

# Usage: ./execute_test.sh pg_version mode redis_for_testing_dir
# pg_version is a PostgreSQL version to be tested like 17.0.
# mode is flag for redis_fdw compiler.
# hiredis_for_testing_dir: path to install directory of hiredis version for testing
#
# Requiremets
# - the source code of PostgreSQL is located in ./workdir/postgresql-{pg_version}.
# - the source code of redis_fdw is loacted in ./workdir/postgresql-{pg_version}/contrib/redis_fdw.
# - PostgreSQL and redis_fdw were built.
# - this script assumes that tests are passed if this file (created by executing
# the test) contains " ALL {number} tests passed" at the last or the 3rd line
# from the end.
#
################################################################################

VERSION=$1
MODE="$2"
HIREDIS_FOR_TESTING_DIR="$3"

cd ./workdir/postgresql-${VERSION}/contrib/redis_fdw

if [ "$MODE" == "postgis" ]; then
export ENABLE_GIS=1

# Start postgres server
POSTGRES_HOME=/usr/local/pgsql
${POSTGRES_HOME}/bin/initdb ${POSTGRES_HOME}/databases
${POSTGRES_HOME}/bin/pg_ctl -D ${POSTGRES_HOME}/databases -l logfile start

# Change the testing method
sed -i 's/make check/make installcheck/' test.sh
fi

# Execute test script
chmod +x ./test.sh
./test.sh $MAKEFILE_OPT

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

pattern=" All [0-9]+ tests passed.+"

if [[ "$last_line" =~ $pattern ]]; then
echo "last_line"

elif [[ "$third_line_from_the_last" =~ $pattern ]]; then
echo "$third_line_from_the_last"
else
echo "Error : not All the tests passed"
echo "last line : '$last_line'"
echo "thierd_line_from_the_last : '$third_line_from_the_last'"
exit 1
fi
22 changes: 22 additions & 0 deletions GitHubActions/install_locales.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

################################################################################
#
# This script installs some locales and language packs used by redis_fdw
# tests in Ubuntu.
#
# Usage: ./install_locales.sh
#
# Requirements:
# - having superuser privileges
#
################################################################################

sudo apt-get update
sudo apt-get install locales language-pack-ja
sudo locale-gen ja_JP.EUC-JP
sudo apt-get install language-pack-ko-base language-pack-ko
sudo locale-gen ko_KR.EUC-KR
sudo apt-get install language-pack-bg-base language-pack-bg
sudo locale-gen bg_BG
sudo apt-get install libreadline8 libreadline-dev
Loading