Run Python tests against all supported PostgreSQL versions.

This commit is contained in:
Dave Page 2023-03-30 15:54:06 +01:00
parent 374941bfab
commit 222de66a83

View File

@ -9,7 +9,7 @@ on:
workflow_dispatch:
env:
POSTGRESQL_VERSION: 15
POSTGRESQL_VERSIONS: 15 14 13 12 11
jobs:
build:
@ -22,37 +22,56 @@ jobs:
run: |
sudo sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
- name: Install platform dependencies
run: |
PACKAGES=
for VERSION in ${POSTGRESQL_VERSIONS};
do
PACKAGES="${PACKAGES} postgresql-${VERSION} postgresql-${VERSION}-pldebugger"
done
sudo apt update
sudo apt install -y build-essential python3-dev python3-pip libpq-dev libffi-dev libssl-dev libkrb5-dev zlib1g-dev postgresql-${POSTGRESQL_VERSION} postgresql-${POSTGRESQL_VERSION}-pldebugger pgagent
sudo apt install -y build-essential python3-dev python3-pip libpq-dev libffi-dev libssl-dev libkrb5-dev zlib1g-dev ${PACKAGES} pgagent
- name: Create the tablespace directory
run: |
sudo mkdir -p /var/lib/postgresql/tablespaces/${POSTGRESQL_VERSION}
sudo chown postgres:postgres /var/lib/postgresql/tablespaces/${POSTGRESQL_VERSION}
for VERSION in ${POSTGRESQL_VERSIONS};
do
sudo mkdir -p /var/lib/postgresql/tablespaces/${VERSION}
sudo chown postgres:postgres /var/lib/postgresql/tablespaces/${VERSION}
done
- name: Start PostgreSQL
run: |
# Note: we use a custom port for PostgreSQL as the runner may already have a version of PostgreSQL installed
sudo su -c "echo local all all trust > /etc/postgresql/${POSTGRESQL_VERSION}/main/pg_hba.conf"
sudo sed -i "s/port = 543[0-9]/port = 59${POSTGRESQL_VERSION}/g" /etc/postgresql/${POSTGRESQL_VERSION}/main/postgresql.conf
sudo sed -i "s/#shared_preload_libraries = ''/shared_preload_libraries = '\$libdir\/plugin_debugger'/g" /etc/postgresql/${POSTGRESQL_VERSION}/main/postgresql.conf
sudo su - postgres -c "/usr/lib/postgresql/${POSTGRESQL_VERSION}/bin/postgres -D /var/lib/postgresql/${POSTGRESQL_VERSION}/main -c config_file=/etc/postgresql/${POSTGRESQL_VERSION}/main/postgresql.conf &"
for VERSION in ${POSTGRESQL_VERSIONS};
do
sudo su -c "echo local all all trust > /etc/postgresql/${VERSION}/main/pg_hba.conf"
sudo sed -i "s/port = 543[0-9]/port = 59${VERSION}/g" /etc/postgresql/${VERSION}/main/postgresql.conf
sudo sed -i "s/#shared_preload_libraries = ''/shared_preload_libraries = '\$libdir\/plugin_debugger'/g" /etc/postgresql/${VERSION}/main/postgresql.conf
sudo su - postgres -c "/usr/lib/postgresql/${VERSION}/bin/postgres -D /var/lib/postgresql/${VERSION}/main -c config_file=/etc/postgresql/${VERSION}/main/postgresql.conf &"
until sudo runuser -l postgres -c "pg_isready -p 59${POSTGRESQL_VERSION}" 2>/dev/null; do
>&2 echo "Postgres is unavailable - sleeping for 2 seconds"
sleep 2
until sudo runuser -l postgres -c "pg_isready -p 59${VERSION}" 2>/dev/null; do
>&2 echo "Postgres is unavailable - sleeping for 2 seconds"
sleep 2
done
psql -U postgres -p 59${VERSION} -c 'CREATE EXTENSION pgagent;'
psql -U postgres -p 59${VERSION} -c 'CREATE EXTENSION pldbgapi;'
done
psql -U postgres -p 59${POSTGRESQL_VERSION} -c 'CREATE EXTENSION pgagent;'
psql -U postgres -p 59${POSTGRESQL_VERSION} -c 'CREATE EXTENSION pldbgapi;'
- name: Install Python dependencies
run: |
sudo pip install --upgrade pip
sudo pip install -r web/regression/requirements.txt
sudo pip install "pyOpenSSL>=23.*"
- name: Create the test configuration
run: |
cat <<EOF > web/config_local.py
from config import *
# Debug mode
DEBUG = True
@ -74,6 +93,7 @@ jobs:
TEST_SQLITE_PATH = "$(pwd)/var/pgadmin4.db"
AZURE_CREDENTIAL_CACHE_DIR = "$(pwd)/var/azurecredentialcache"
EOF
cat <<EOF > web/regression/test_config.json
{
"pgAdmin4_login_credentials": {
@ -93,22 +113,41 @@ jobs:
},
"server_group": 1,
"server_credentials": [
EOF
function add_server_def() {
SEP=","
if [ "$1" = "$2" ]; then
SEP=""
fi
cat <<EOF >> web/regression/test_config.json
{
"name": "PostgreSQL ${POSTGRESQL_VERSION}",
"comment": "PostgreSQL ${POSTGRESQL_VERSION} Server",
"name": "PostgreSQL $1",
"comment": "PostgreSQL $1 Server",
"db_username": "postgres",
"host": "/var/run/postgresql",
"db_password": "postgres",
"db_port": 59${POSTGRESQL_VERSION},
"db_port": 59$1,
"maintenance_db": "postgres",
"sslmode": "prefer",
"tablespace_path": "/var/lib/postgresql/tablespaces/${POSTGRESQL_VERSION}",
"tablespace_path": "/var/lib/postgresql/tablespaces/$1",
"enabled": true,
"default_binary_paths": {
"pg": "/usr/lib/postgresql/${POSTGRESQL_VERSION}/bin",
"pg": "/usr/lib/postgresql/$1/bin",
"ppas": ""
}
}
}${SEP}
EOF
}
LAST_VERSION=$(echo ${POSTGRESQL_VERSIONS} | awk '{print $NF}')
for VERSION in ${POSTGRESQL_VERSIONS};
do
add_server_def ${VERSION} ${LAST_VERSION}
done
cat <<EOF >> web/regression/test_config.json
],
"server_update_data": [
{
@ -117,6 +156,7 @@ jobs:
]
}
EOF
- name: Run the tests
run: make check-python