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 1 commit
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
Prev Previous commit
Next Next commit
Add support for missing action runners
Turns out that Windows Server 2019 does not support locale names
specified in the format defined by the POSIX standard. This patch
converts the POSIX format to the one supported by Windows 2019.

In addition to that, this patch adds all supported action runners to
the continue integration, so we can make sure that this action works
properly on every supported platform.

Reported-by: Irena Rindos
Fixes: #25
ikalnytskyi committed May 1, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 89e158678347488cdd62fe7e46d2391c6bcbfc71
20 changes: 16 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -14,18 +14,25 @@ jobs:
strategy:
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-latest
- macos-13
- ubuntu-22.04
- ubuntu-20.04
- windows-2022
- windows-2019
- macos-14
- macos-13
- macos-12
steps:
- uses: actions/checkout@v4

- name: Run setup-postgres
uses: ./
id: postgres

- name: Run setup-python
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Run tests
run: |
python3 -m pip install --upgrade pip pytest psycopg furl
@@ -57,6 +64,11 @@ jobs:
port: 34837
id: postgres

- name: Run setup-python
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Run tests
run: |
python3 -m pip install --upgrade pip pytest psycopg furl
16 changes: 14 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
@@ -64,6 +64,18 @@ runs:
export PGDATA="$RUNNER_TEMP/pgdata"
export PWFILE="$RUNNER_TEMP/pwfile"

DEFAULT_ENCODING="UTF-8"
DEFAULT_LOCALE="en_US.$DEFAULT_ENCODING"

# Unfortunately, Windows Server 2019 doesn't understand locale
# specified in the format defined by the POSIX standard, i.e.
# <language>_<country>.<encoding>. Therefore, we have to convert it
# into something it can swallow, i.e. <language>-<country>.
if [[ "$RUNNER_OS" == "Windows" && "$(wmic os get Caption)" == *"2019"* ]]; then
DEFAULT_LOCALE="${DEFAULT_LOCALE%%.*}"
DEFAULT_LOCALE="${DEFAULT_LOCALE//_/-}"
fi

# Unfortunately 'initdb' could only receive a password via file on disk
# or prompt to enter on. Prompting is not an option since we're running
# in non-interactive mode.
@@ -82,8 +94,8 @@ runs:
--username="${{ inputs.username }}" \
--pwfile="$PWFILE" \
--auth="scram-sha-256" \
--encoding="UTF-8" \
--locale="en_US.UTF-8" \
--encoding="$DEFAULT_ENCODING" \
--locale="$DEFAULT_LOCALE" \
--no-instructions

# Do not create unix sockets since they are created by default in the
41 changes: 32 additions & 9 deletions test_action.py
Original file line number Diff line number Diff line change
@@ -12,6 +12,24 @@
ConnectionFactory = t.Callable[[str], psycopg.Connection]


@pytest.fixture(scope="function")
def is_windows() -> bool:
"""Returns True if running on Windows."""

return os.name == "nt"


@pytest.fixture(scope="function")
def is_windows_server_2019(is_windows: bool) -> bool:
"""Returns True if running on Windows Server 2019."""

if not is_windows:
return False

windows_caption = subprocess.check_output(["wmic", "os", "get", "Caption"], text=True)
return "Windows Server 2019" in windows_caption


@pytest.fixture(scope="function")
def connection_uri() -> str:
"""Read and return connection URI from environment."""
@@ -57,35 +75,40 @@ def connection(
raise RuntimeError("f{request.param}: unknown value")


def test_connection_uri(connection_uri):
def test_connection_uri(connection_uri: str):
"""Test that CONNECTION_URI matches EXPECTED_CONNECTION_URI."""

assert connection_uri == os.getenv("EXPECTED_CONNECTION_URI")


def test_service_name(service_name):
def test_service_name(service_name: str):
"""Test that SERVICE_NAME matches EXPECTED_SERVICE_NAME."""

assert service_name == os.getenv("EXPECTED_SERVICE_NAME")


def test_server_encoding(connection: psycopg.Connection):
"""Test that PostgreSQL's encoding is 'UTF-8'."""
"""Test that PostgreSQL's encoding matches the one we passed to initdb."""

assert connection.execute("SHOW SERVER_ENCODING").fetchone()[0] == "UTF8"


def test_locale(connection: psycopg.Connection):
"""Test that PostgreSQL's locale is 'en_US.UTF-8'."""
def test_locale(connection: psycopg.Connection, is_windows_server_2019: bool):
"""Test that PostgreSQL's locale matches the one we paased to initdb."""

locale_exp = "en_US.UTF-8"

if is_windows_server_2019:
locale_exp = "en-US"

lc_collate = connection.execute("SHOW LC_COLLATE").fetchone()[0]
lc_ctype = connection.execute("SHOW LC_CTYPE").fetchone()[0]

assert locale.normalize(lc_collate) == "en_US.UTF-8"
assert locale.normalize(lc_ctype) == "en_US.UTF-8"
assert locale.normalize(lc_collate) == locale_exp
assert locale.normalize(lc_ctype) == locale_exp


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

pg_environ = {k: v for k, v in os.environ.items() if k.startswith("PG")}
@@ -96,7 +119,7 @@ def test_environment_variables():
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":
if is_windows:
pg_environ_exp = {
"PGBIN": "",
"PGDATA": "",