Skip to content

Commit 062ab3a

Browse files
ikalnytskyimalorrkiyanchuk
committed
Set 'postgres-version'
Co-Authored-By: Roman Podoliaka <[email protected]> Co-Authored-By: Ruslan Kiyanchuk <[email protected]>
1 parent 814fad8 commit 062ab3a

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ jobs:
3333
SERVICE_NAME: ${{ steps.postgres.outputs.service-name }}
3434
EXPECTED_CONNECTION_URI: postgresql://postgres:postgres@localhost:5432/postgres
3535
EXPECTED_SERVICE_NAME: postgres
36+
EXPECTED_SERVER_VERSION: "15"
3637
shell: bash
3738

3839
parametrized:
@@ -53,6 +54,7 @@ jobs:
5354
password: GrandMaster
5455
database: jedi_order
5556
port: 34837
57+
postgres-version: "13"
5658
id: postgres
5759

5860
- name: Run tests
@@ -64,4 +66,5 @@ jobs:
6466
SERVICE_NAME: ${{ steps.postgres.outputs.service-name }}
6567
EXPECTED_CONNECTION_URI: postgresql://yoda:GrandMaster@localhost:34837/jedi_order
6668
EXPECTED_SERVICE_NAME: yoda
69+
EXPECTED_SERVER_VERSION: "13"
6770
shell: bash

action.yml

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ inputs:
2121
description: The server port to listen on.
2222
default: "5432"
2323
required: false
24+
postgres-version:
25+
description: The PostgreSQL (major) version to install.
26+
default: "15"
27+
required: false
2428
outputs:
2529
connection-uri:
2630
description: The connection URI to connect to PostgreSQL.
@@ -31,13 +35,25 @@ outputs:
3135
runs:
3236
using: composite
3337
steps:
34-
- name: Prerequisites
38+
- name: Install PostgreSQL
3539
run: |
3640
if [ "$RUNNER_OS" == "Linux" ]; then
37-
echo "$(pg_config --bindir)" >> $GITHUB_PATH
41+
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
42+
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
43+
sudo apt-get update
44+
sudo apt-get -y install postgresql-${{ inputs.postgres-version }}
45+
46+
echo "$(/usr/lib/postgresql/${{ inputs.postgres-version }}/bin/pg_config --bindir)" >> $GITHUB_PATH
47+
3848
elif [ "$RUNNER_OS" == "Windows" ]; then
39-
echo "$PGBIN" >> $GITHUB_PATH
40-
echo "PQ_LIB_DIR=$PGROOT\lib" >> $GITHUB_ENV
49+
choco install postgresql${{ inputs.postgres-version }}
50+
51+
echo "$('C:/Program Files/PostgreSQL/${{ inputs.postgres-version }}/bin/pg_config.exe' --bindir)" >> $GITHUB_PATH
52+
echo "PQ_LIB_DIR=$('C:/Program Files/PostgreSQL/${{ inputs.postgres-version }}/bin/pg_config.exe' --libdir)" >> $GITHUB_ENV
53+
54+
elif [ "$RUNNER_OS" == "macOS" ]; then
55+
brew install postgresql@${{ inputs.postgres-version }}
56+
brew link --overwrite postgresql@${{ inputs.postgres-version }}
4157
fi
4258
shell: bash
4359

@@ -65,8 +81,7 @@ runs:
6581
--pwfile="$PWFILE" \
6682
--auth="scram-sha-256" \
6783
--encoding="UTF-8" \
68-
--locale="en_US.UTF-8" \
69-
--no-instructions
84+
--locale="en_US.UTF-8"
7085
7186
# Do not create unix sockets since they are created by default in the
7287
# directory we have no permissions to (owned by system postgres user).

test_action.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ def test_locale(connection: psycopg.Connection):
8484
assert locale.normalize(lc_ctype) == "en_US.UTF-8"
8585

8686

87+
def test_server_version(connection: psycopg.Connection):
88+
"""Test that PostgreSQL's version is expected."""
89+
90+
server_version = connection.execute("SHOW SERVER_VERSION").fetchone()[0]
91+
assert server_version.split(".")[0] == os.getenv("EXPECTED_SERVER_VERSION")
92+
93+
8794
def test_user_permissions(connection: psycopg.Connection):
8895
"""Test that a user has super/createdb permissions."""
8996

0 commit comments

Comments
 (0)