Skip to content
Merged
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
54 changes: 54 additions & 0 deletions .github/scripts/build-postgres.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash

set -e

ARGS=

SCRIPT_DIR="$(cd -- "$(dirname "$0")" >/dev/null 2>&1; pwd -P)"
PSP_DIR="$SCRIPT_DIR/../../../postgres"

case "$1" in
debug)
echo "Building with debug option"
ARGS+=" --enable-cassert --enable-injection-points"
;;

debugoptimized)
echo "Building with debugoptimized option"
export CFLAGS="-O2"
ARGS+=" --enable-cassert --enable-injection-points"
;;

coverage)
echo "Building with coverage option"
ARGS+=" --enable-cassert --enable-injection-points --enable-coverage"
;;

sanitize)
echo "Building with sanitize option"
export CFLAGS="-fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer -fno-inline-functions"
;;

*)
echo "Unknown build type: $1"
echo "Please use one of the following: debug, debugoptimized, sanitize"
exit 1
;;
esac

if [[ "$OSTYPE" == "linux-gnu"* ]]; then
ARGS+=" --with-liburing"
NCPU=$(nproc)
elif [[ "$OSTYPE" == "darwin"* ]]; then
NCPU=$(sysctl -n hw.ncpu)
fi

cd "$PSP_DIR"

./configure \
--enable-debug \
--enable-tap-tests \
$ARGS

sudo make install-world -j $NCPU
echo "/usr/local/pgsql/bin" >> $GITHUB_PATH
43 changes: 43 additions & 0 deletions .github/scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

set -e

SCRIPT_DIR="$(cd -- "$(dirname "$0")" >/dev/null 2>&1; pwd -P)"
PG_CFLAGS=-Werror

cd "$SCRIPT_DIR/../.."

case "$1" in
debug)
echo "Building with debug option"
;;

debugoptimized)
echo "Building with debugoptimized option"
PG_CFLAGS+=" -O2"
;;

sanitize)
echo "Building with sanitize option"
PG_CFLAGS+=" -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer -fno-inline-functions"
;;

coverage)
echo "Building with coverage option"
PG_CFLAGS+=" -g -fprofile-arcs -ftest-coverage"
;;

*)
echo "Unknown build type: $1"
echo "Please use one of the following: debug, debugoptimized, sanitize"
exit 1
;;
esac

if [[ "$OSTYPE" == "linux-gnu"* ]]; then
NCPU=$(nproc)
elif [[ "$OSTYPE" == "darwin"* ]]; then
NCPU=$(sysctl -n hw.ncpu)
fi

sudo env "PATH=$PATH" PG_CFLAGS="$PG_CFLAGS" make USE_PGXS=1 install -j $NCPU
17 changes: 17 additions & 0 deletions .github/scripts/dump-typedefs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

set -e

SCRIPT_DIR="$(cd -- "$(dirname "$0")" >/dev/null 2>&1; pwd -P)"
cd "$SCRIPT_DIR/../.."

if ! test -f pg_stat_monitor.so; then
echo "pg_stat_monitor.so doesn't exists, run build.sh first in debug mode"
exit 1
fi

../postgres/src/tools/find_typedef . >> typedefs.list

# Fetches typedefs list for PostgreSQL core and merges it with typedefs defined in this project.
# https://wiki.postgresql.org/wiki/Running_pgindent_on_non-core_code_or_development_code
(wget -q -O - "https://buildfarm.postgresql.org/cgi-bin/typedefs.pl?branch=REL_17_STABLE"; wget -q -O - "https://buildfarm.postgresql.org/cgi-bin/typedefs.pl?branch=REL_18_STABLE") | cat - typedefs.list | sort -u > typedefs-full.list
49 changes: 49 additions & 0 deletions .github/scripts/install-postgresql.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
set -e

if [ -z "$2" ]; then
echo "Error: The second argument (PostgreSQL version) must be provided."
exit 1
fi


case "$1" in
pgdg)
echo "Installing PostgreSQL from PostgreSQL Global Development Group (PGDG) Distribution"
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt \
$(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
sudo wget --quiet -O - \
https://www.postgresql.org/media/keys/ACCC4CF8.asc |
sudo apt-key add -
sudo apt update -y
sudo apt -y install postgresql-${2} postgresql-server-dev-${2}
;;

psp)
echo "Installing Percona Server for PostgreSQL"
sudo wget https://repo.percona.com/apt/percona-release_latest.generic_all.deb
sudo dpkg -i percona-release_latest.generic_all.deb
sudo percona-release setup ppg-${2}
sudo apt update -y
sudo apt install -y percona-postgresql-${2} \
percona-postgresql-contrib percona-postgresql-server-dev-all \
percona-pgpool2 libpgpool2 percona-postgresql-${2}-pgaudit \
percona-postgresql-${2}-pgaudit-dbgsym percona-postgresql-${2}-repack \
percona-postgresql-${2}-repack-dbgsym percona-pgaudit${2}-set-user \
percona-pgaudit${2}-set-user-dbgsym percona-postgresql-${2}-postgis-3 \
percona-postgresql-${2}-postgis-3-scripts \
percona-postgresql-postgis-scripts percona-postgresql-postgis \
percona-postgis
;;

pgdg-macos)
echo "Installing PostgreSQL from PostgreSQL Global Development Group (PGDG) Distribution on macOS"
brew install postgresql@${2}
brew link postgresql@${2}
;;

*)
echo "Unknown PostgreSQL distribution type: $1"
echo "Please use one of the following: pgdg, psp"
exit 1
;;
esac
18 changes: 18 additions & 0 deletions .github/scripts/macos-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

set -e

DEPS=(
# Setup
wget
# Build
gnu-sed

# Run pgperltidy
perltidy
)

brew update
brew install ${DEPS[@]}

cpan -T IPC::Run Text::Trim JSON
22 changes: 22 additions & 0 deletions .github/scripts/run-pgindent.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

set -e

SCRIPT_DIR="$(cd -- "$(dirname "$0")" >/dev/null 2>&1; pwd -P)"
INSTALL_DIR="$SCRIPT_DIR/../../pginst"
cd "$SCRIPT_DIR/../../"

if ! test -f typedefs-full.list; then
echo "typedefs-full.list doesn't exists, run dump-typedefs.sh first"
exit 1
fi

cd ../postgres/src/tools/pg_bsd_indent
sudo make install

cd "$SCRIPT_DIR/../.."

export PATH=$SCRIPT_DIR/../../../postgres/src/tools/pgindent/:$INSTALL_DIR/bin/:$PATH

# Check pg_stat_monitor with the fresh list extraxted from the object file
pgindent --typedefs=typedefs-full.list --excludes=<(echo "src/libkmip") "$@" .
10 changes: 10 additions & 0 deletions .github/scripts/run-pgperltidy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

set -e

SCRIPT_DIR="$(cd -- "$(dirname "$0")" >/dev/null 2>&1; pwd -P)"
cd "$SCRIPT_DIR/../../"

source ../postgres/src/tools/perlcheck/find_perl_files

find_perl_files . | xargs perltidy "$@" --profile=../postgres/src/tools/pgindent/perltidyrc
24 changes: 24 additions & 0 deletions .github/scripts/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

set -e

SCRIPT_DIR="$(cd -- "$(dirname "$0")" >/dev/null 2>&1; pwd -P)"
PG_BIN_DIR=$(pg_config --bindir)

cd "$SCRIPT_DIR/../../"

PG_VERSION=$(pg_config --version | sed -n 's/PostgreSQL \([0-9]*\).*/\1/p')

OPTS='-c shared_preload_libraries=pg_stat_monitor'

if [ "$1" = sanitize ]; then
OPTS+=' -c max_stack_depth=8MB'
fi

$PG_BIN_DIR/pg_ctl -D regression_install -l regression_install.log init

$PG_BIN_DIR/pg_ctl -D regression_install -l regression_install.log start -o "$OPTS"

make USE_PGXS=1 installcheck

$PG_BIN_DIR/pg_ctl -D regression_install stop
61 changes: 61 additions & 0 deletions .github/scripts/ubuntu-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash

set -e

DEPS=(
# Setup
wget

# Build
perl

# Test
libipc-run-perl
libtext-trim-perl
libjson-perl

# Run pgperltidy
perltidy
)

case "$1" in
dev)
DEPS+=(
# Build
bison
docbook-xml
docbook-xsl
flex
gettext
lcov
libicu-dev
libkrb5-dev
libldap2-dev
liblz4-dev
libpam0g-dev
libperl-dev
libreadline-dev
libselinux1-dev
libssl-dev
libsystemd-dev
liburing-dev
libxml2-dev
libxml2-utils
libxslt1-dev
libzstd-dev
lz4
mawk
perl
pkgconf
systemtap-sdt-dev
tcl-dev
uuid-dev
xsltproc
zlib1g-dev
zstd
)
;;
esac

sudo apt-get update
sudo apt-get install -y ${DEPS[@]}
82 changes: 82 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Reusable build and test
on:
workflow_call:
inputs:
pg_package:
type: string
required: true
pg_version:
type: string
required: true
os:
type: string
required: true
compiler:
type: string
required: true
build_type:
type: string
required: true

env:
PG_PACKAGE: ${{ inputs.pg_package }}
PG_VERSION: ${{ inputs.pg_version }}
OS: ${{ inputs.os }}
CC: ${{ inputs.compiler }}
BUILD_TYPE: ${{ inputs.build_type }}

jobs:
build:
name: Build
runs-on: ${{ inputs.os }}
timeout-minutes: 10
steps:
- name: Remove existing PostgreSQL
if: startsWith(inputs.os, 'ubuntu-')
run: sudo apt purge postgresql* libpq*

- name: Clone repository
uses: actions/checkout@v5
with:
submodules: recursive
ref: ${{ github.ref }}

- name: Install dependencies for Ubuntu
if: startsWith(inputs.os, 'ubuntu-')
run: .github/scripts/ubuntu-deps.sh

- name: Install dependencies for MacOS
if: startsWith(inputs.os, 'macos-')
run: .github/scripts/macos-deps.sh

- name: Install PostgreSQL
run: .github/scripts/install-postgresql.sh ${{ env.PG_PACKAGE }} ${{ env.PG_VERSION }}

- name: Build pg_stat_monitor
run: .github/scripts/build.sh ${{ env.BUILD_TYPE }}

- name: Set permissions
if: startsWith(inputs.os, 'ubuntu-')
run: sudo chown -R runner:runner /var/run/postgresql

- name: Stop existing PostgreSQL instances
if: startsWith(inputs.os, 'ubuntu-')
run: sudo service postgresql stop

- name: Run tests
run: .github/scripts/test.sh ${{ env.BUILD_TYPE }}

- name: Report on test fail
uses: actions/upload-artifact@v4
if: ${{ failure() }}
with:
name: log-test-${{ env.PG_PACKAGE }}-${{ env.PG_VERSION }}-${{ env.OS }}-${{ env.CC }}-${{ env.BUILD_TYPE }}
path: |
regression_install
regression_install.log
regression.diffs
regression.out
results
t/results
tmp_check
retention-days: 3
Loading
Loading