Skip to content

Commit

Permalink
CI environment using GitHub Actions (pgspider#98)
Browse files Browse the repository at this point in the history
Co-authored-by: tachikiH <137734056+tachikiH@users.noreply.github.com>
  • Loading branch information
t-kataym and tachikiH authored Apr 8, 2024
1 parent a272452 commit 1953298
Show file tree
Hide file tree
Showing 9 changed files with 256 additions and 0 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -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 }}
10 changes: 10 additions & 0 deletions GitHubActions/README.md
Original file line number Diff line number Diff line change
@@ -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.
23 changes: 23 additions & 0 deletions GitHubActions/build_postgres.sh
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions GitHubActions/build_sqlite_fdw.sh
Original file line number Diff line number Diff line change
@@ -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
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 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"
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
42 changes: 42 additions & 0 deletions GitHubActions/execute_test.sh
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions GitHubActions/install_locales.sh
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions GitHubActions/install_sqlite.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1953298

Please sign in to comment.