Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2: Merge upstream changes, doc updates #3

Closed
wants to merge 24 commits into from
Closed
Changes from 2 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
acc2f7f
Use `$GITHUB_OUTPUT` instead of `::set-output`
nyurik Oct 29, 2022
3973215
Merge pull request #9 from ikalnytskyi/remove-set-output
ikalnytskyi Dec 28, 2022
f9abc1d
BREAKING CHANGE: create superuser
ikalnytskyi Jan 2, 2023
ae2fb38
Merge pull request #11 from ikalnytskyi/superuser
ikalnytskyi Jan 3, 2023
f02428f
BREAKING CHANGE: enforce password authentication
ikalnytskyi Jan 3, 2023
3574bd5
Merge pull request #12 from ikalnytskyi/enforce-auth
ikalnytskyi Jan 3, 2023
75b3f77
BREAKING CHANGE: don't set connection env vars
ikalnytskyi Jan 3, 2023
f19cd58
Merge pull request #13 from ikalnytskyi/pgservice
ikalnytskyi Jan 4, 2023
814fad8
Use '@v4' tag in usage examples
ikalnytskyi Jan 4, 2023
6f93681
CI: Bump actions/checkout to v4
ikalnytskyi Dec 29, 2023
510dee7
Merge pull request #21 from ikalnytskyi/chore/ci-checkout-v4
ikalnytskyi Dec 29, 2023
6fd93bd
Add macOS 13 support
ikalnytskyi Jan 5, 2024
7685acb
Merge pull request #22 from ikalnytskyi/feat/macos-13
ikalnytskyi Jan 6, 2024
11ff483
Unset PG* env vars except PGSERVICEFILE
ikalnytskyi Jan 6, 2024
e8f195e
Merge pull request #23 from ikalnytskyi/bug/unset-pg-env
ikalnytskyi Jan 9, 2024
74e3964
Bump version to v5
ikalnytskyi Jan 9, 2024
88de67f
Fix macOS 13 support
ikalnytskyi Mar 16, 2024
49d71fa
Merge pull request #28 from ikalnytskyi/bug/macos-13-install-postgres
ikalnytskyi Mar 16, 2024
85a5c36
Add macOS 14 support
ikalnytskyi Mar 19, 2024
ca880f6
Merge pull request #29 from ikalnytskyi/feat/macos-14
ikalnytskyi Mar 19, 2024
89e1586
Add support for missing action runners
ikalnytskyi Mar 19, 2024
e629f5d
Merge pull request #30 from ikalnytskyi/feat/missing-os-runners
ikalnytskyi May 1, 2024
687404e
Version 6
ikalnytskyi May 1, 2024
6db06e9
v2: Merge upstream changes, doc updates
nyurik May 24, 2024
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
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -14,6 +14,19 @@ key features:

## Usage

> [!IMPORTANT]
>
> In order to connect to a PostgreSQL server, use either connection parameters
> from the table below ([link](#connection-parameters)), or retrieve a
> connection URI from the `connection-uri` output ([link](#advanced)).

> [!TIP]
>
> `libpq`-using applications may choose to set the `PGSERVICE=postgres`
> environment variable instead ([link](#create-a-new-user-w-database-via-cli)),
> where `postgres` is the service name extracted from the `service-name`
> output.

#### Connection parameters

| Key | Value |
@@ -73,11 +86,10 @@ steps:
createuser myuser
createdb --owner myuser mydatabase
psql -c "ALTER USER myuser WITH PASSWORD 'mypassword'"

env:
# This activates connection parameters for the superuser created by
# the action in the step above. It's mandatory to set this before using
# createuser/psql/etc tools.
# createuser/psql and other libpq-using applications.
#
# The service name is the same as the username (i.e. 'postgres') but
# it's recommended to use action's output to get the name in order to
7 changes: 7 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -38,6 +38,13 @@ runs:
elif [ "$RUNNER_OS" == "Windows" ]; then
echo "$PGBIN" >> $GITHUB_PATH
echo "PQ_LIB_DIR=$PGROOT\lib" >> $GITHUB_ENV

# The Windows runner has some PostgreSQL environment variables set
# that may confuse users since they may be irrelevant to the
# PostgreSQL server we're using.
for name in "PGROOT" "PGDATA" "PGBIN" "PGUSER" "PGPASSWORD"; do
echo "$name=" >> $GITHUB_ENV
done
elif [ "$RUNNER_OS" == "macOS" ]; then
case "$(sw_vers -productVersion)" in
13.*)
38 changes: 38 additions & 0 deletions test_action.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import locale
import os
import pathlib
import subprocess
import typing as t

@@ -84,6 +85,30 @@ def test_locale(connection: psycopg.Connection):
assert locale.normalize(lc_ctype) == "en_US.UTF-8"


def test_environment_variables():
"""Test that only expected 'PG*' variables are set."""

pg_environ = {k: v for k, v in os.environ.items() if k.startswith("PG")}

# In case of Windows, there might be a mix of forward and backward slashes
# as separators. So let's compare paths semantically instead.
pg_servicefile = pathlib.Path(pg_environ.pop("PGSERVICEFILE", ""))
pg_servicefile_exp = pathlib.Path(os.environ["RUNNER_TEMP"], "pgdata", "pg_service.conf")
assert pg_servicefile.resolve() == pg_servicefile_exp.resolve()

if os.name == "nt":
pg_environ_exp = {
"PGBIN": "",
"PGDATA": "",
"PGPASSWORD": "",
"PGROOT": "",
"PGUSER": "",
}
else:
pg_environ_exp = {}
assert pg_environ == pg_environ_exp


def test_user_permissions(connection: psycopg.Connection):
"""Test that a user has super/createdb permissions."""

@@ -201,6 +226,19 @@ def test_client_applications(
subprocess.check_call(["dropuser", username])


def test_libpq_applications(service_name: str, monkeypatch: pytest.MonkeyPatch):
"""Test that libpq-using applications can be used."""

# Request connection parameters from the connection service file prepared
# by our action.
monkeypatch.setenv("PGSERVICE", service_name)

with psycopg.connect() as connection:
assert connection \
.execute("SELECT usename FROM pg_user WHERE usename = CURRENT_USER") \
.fetchone()


def test_auth_wrong_username(connection_factory: ConnectionFactory, connection_uri: str):
"""Test that wrong username is rejected!"""