diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 00000000..57178b39 --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,60 @@ +name: SQLite 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: + SQLITE_VERSION : "3420000" + SQLITE_YEAR: "2023" + HTTP_PROXY: "" + HTTPS_PROXY: "" + strategy: + fail-fast: false + matrix: + pg: ${{ fromJSON(needs.detect-pgversion.outputs.pgversion) }} + + name: Test on PostgreSQL ${{ matrix.pg }} + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + + - name: tar + run: tar zcvf sqlite_fdw.tar.gz ./* + + - name: set_proxy + run: bash GitHubActions/env.sh + + - name: install locales + run: bash GitHubActions/install_locales.sh + + - name: build PostgreSQL ${{ matrix.pg }} + run: bash GitHubActions/build_postgres.sh ${{ matrix.pg }} + + - name: install SQLite + run: bash GitHubActions/install_sqlite.sh ${{ env.SQLITE_VERSION }} ${{ env.SQLITE_YEAR }} + + - name: build sqlite_fdw + run: bash GitHubActions/build_sqlite_fdw.sh ${{ matrix.pg }} + + - name: execute sqlite_fdw test + run: bash GitHubActions/execute_test.sh ${{ matrix.pg }} diff --git a/GitHubActions/README.md b/GitHubActions/README.md new file mode 100644 index 00000000..a4a884d9 --- /dev/null +++ b/GitHubActions/README.md @@ -0,0 +1,10 @@ +# CI environment of sqlite_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 "sql" directory. diff --git a/GitHubActions/build_postgres.sh b/GitHubActions/build_postgres.sh new file mode 100644 index 00000000..bb2fbd22 --- /dev/null +++ b/GitHubActions/build_postgres.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +################################################################################ +# +# This script downloads PostgreSQL from the official web site into ./workdir +# then builds it. +# +# Usage: ./build_postgres.sh pg_version +# pg_version is a PostgreSQL version to be installed like 16.0. +# +# Requirements +# - be able to connect to the PostgreSQL official web site by curl. +# +################################################################################ + +VERSION=$1 +mkdir -p ./workdir +cd ./workdir +curl -O https://ftp.postgresql.org/pub/source/v${VERSION}/postgresql-${VERSION}.tar.bz2 +tar xjf postgresql-${VERSION}.tar.bz2 +cd postgresql-${VERSION} +./configure +make diff --git a/GitHubActions/build_sqlite_fdw.sh b/GitHubActions/build_sqlite_fdw.sh new file mode 100644 index 00000000..f60012e4 --- /dev/null +++ b/GitHubActions/build_sqlite_fdw.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +################################################################################ +# +# This script builds sqlite_fdw in PostgreSQL source tree. +# +# Usage: ./build_sqlite_fdw.sh pg_version +# pg_version is a PostgreSQL version like 16.0 to be built in. +# +# Requirements +# - the source code of sqlite_fdw is available by git clone. +# - the source code of PostgreSQL is located in ~/workdir/postgresql-{pg_version}. +# - SQLite development package is installed in a system. +################################################################################ + +VERSION=$1 +mkdir -p ./workdir/postgresql-${VERSION}/contrib/sqlite_fdw +tar zxvf ./sqlite_fdw.tar.gz -C ./workdir/postgresql-${VERSION}/contrib/sqlite_fdw/ +cd ./workdir/postgresql-${VERSION}/contrib/sqlite_fdw +export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH +make diff --git a/GitHubActions/detect_targets.sh b/GitHubActions/detect_targets.sh new file mode 100644 index 00000000..5ba069e9 --- /dev/null +++ b/GitHubActions/detect_targets.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +################################################################################ +# +# This script detects target PostgreSQL versions for sqlite_fdw testing from +# directory names in ./sql directory. Detected versions will be outputed to +# the standard output as an array of string like ["15.4","16.0"]. +# +# Usage: ./detect_targets.sh +# +# Requirements +# - there is a directory named "sql" in a curent directory. +# +################################################################################ + +dirs="./sql/*" +pattern="[0-9]+\.[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" diff --git a/GitHubActions/env.sh b/GitHubActions/env.sh new file mode 100644 index 00000000..f6073765 --- /dev/null +++ b/GitHubActions/env.sh @@ -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 diff --git a/GitHubActions/execute_test.sh b/GitHubActions/execute_test.sh new file mode 100644 index 00000000..e67f3360 --- /dev/null +++ b/GitHubActions/execute_test.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +################################################################################ +# +# This script executes a regression test pf sqlite_fdw by calling test.sh in +# sqlite_fdw. If all tests are passed, this script will exit successfully. +# Otherwise, it will exit with failure. + +# Usage: ./execute_test.sh pg_version +# pg_version is a PostgreSQL version to be tested like 16.0. +# +# Requiremets +# - the source code of PostgreSQL is located in ./workdir/postgresql-{pg_version}. +# - the source code of sqlite_fdw is loacted in ./workdir/postgresql-{pg_version}/contrib/sqlite_fdw. +# - PostgreSQL and sqlite_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 +cd ./workdir/postgresql-${VERSION}/contrib/sqlite_fdw +chmod +x ./test.sh +./test.sh + +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 diff --git a/GitHubActions/install_locales.sh b/GitHubActions/install_locales.sh new file mode 100644 index 00000000..a120cfe3 --- /dev/null +++ b/GitHubActions/install_locales.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +################################################################################ +# +# This script installs some locales and language packs used by sqlite_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 diff --git a/GitHubActions/install_sqlite.sh b/GitHubActions/install_sqlite.sh new file mode 100644 index 00000000..0b6fcb84 --- /dev/null +++ b/GitHubActions/install_sqlite.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +################################################################################ +# +# This sript downloads SQLite source code from the official web site into +# ./workdir then builds and installs it. +# +# Usage: ./install_sqlite.sh version year +# version: SQLite version to be installed +# year: A year of SQLite released. It is used for determining a download URL. +# +# Ex) ./install_sqlite.sh 3420000 2023 +# +# Requirements +# - be able to connect to the SQLite official web site by curl. +# - having superuser privileges +# +################################################################################ + +VERSION=$1 +YEAR=$2 +mkdir -p ./workdir +cd ./workdir +curl -O https://www.sqlite.org/${YEAR}/sqlite-src-${VERSION}.zip +unzip sqlite-src-${VERSION}.zip +cd sqlite-src-${VERSION} +./configure --enable-fts5 +make +sudo make install