Skip to content

Commit 89e1586

Browse files
committed
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
1 parent ca880f6 commit 89e1586

File tree

3 files changed

+62
-15
lines changed

3 files changed

+62
-15
lines changed

.github/workflows/ci.yml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,25 @@ jobs:
1414
strategy:
1515
matrix:
1616
os:
17-
- ubuntu-latest
18-
- windows-latest
19-
- macos-latest
20-
- macos-13
17+
- ubuntu-22.04
18+
- ubuntu-20.04
19+
- windows-2022
20+
- windows-2019
2121
- macos-14
22+
- macos-13
23+
- macos-12
2224
steps:
2325
- uses: actions/checkout@v4
2426

2527
- name: Run setup-postgres
2628
uses: ./
2729
id: postgres
2830

31+
- name: Run setup-python
32+
uses: actions/setup-python@v5
33+
with:
34+
python-version: "3.10"
35+
2936
- name: Run tests
3037
run: |
3138
python3 -m pip install --upgrade pip pytest psycopg furl
@@ -57,6 +64,11 @@ jobs:
5764
port: 34837
5865
id: postgres
5966

67+
- name: Run setup-python
68+
uses: actions/setup-python@v5
69+
with:
70+
python-version: "3.10"
71+
6072
- name: Run tests
6173
run: |
6274
python3 -m pip install --upgrade pip pytest psycopg furl

action.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@ runs:
6464
export PGDATA="$RUNNER_TEMP/pgdata"
6565
export PWFILE="$RUNNER_TEMP/pwfile"
6666
67+
DEFAULT_ENCODING="UTF-8"
68+
DEFAULT_LOCALE="en_US.$DEFAULT_ENCODING"
69+
70+
# Unfortunately, Windows Server 2019 doesn't understand locale
71+
# specified in the format defined by the POSIX standard, i.e.
72+
# <language>_<country>.<encoding>. Therefore, we have to convert it
73+
# into something it can swallow, i.e. <language>-<country>.
74+
if [[ "$RUNNER_OS" == "Windows" && "$(wmic os get Caption)" == *"2019"* ]]; then
75+
DEFAULT_LOCALE="${DEFAULT_LOCALE%%.*}"
76+
DEFAULT_LOCALE="${DEFAULT_LOCALE//_/-}"
77+
fi
78+
6779
# Unfortunately 'initdb' could only receive a password via file on disk
6880
# or prompt to enter on. Prompting is not an option since we're running
6981
# in non-interactive mode.
@@ -82,8 +94,8 @@ runs:
8294
--username="${{ inputs.username }}" \
8395
--pwfile="$PWFILE" \
8496
--auth="scram-sha-256" \
85-
--encoding="UTF-8" \
86-
--locale="en_US.UTF-8" \
97+
--encoding="$DEFAULT_ENCODING" \
98+
--locale="$DEFAULT_LOCALE" \
8799
--no-instructions
88100
89101
# Do not create unix sockets since they are created by default in the

test_action.py

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,24 @@
1212
ConnectionFactory = t.Callable[[str], psycopg.Connection]
1313

1414

15+
@pytest.fixture(scope="function")
16+
def is_windows() -> bool:
17+
"""Returns True if running on Windows."""
18+
19+
return os.name == "nt"
20+
21+
22+
@pytest.fixture(scope="function")
23+
def is_windows_server_2019(is_windows: bool) -> bool:
24+
"""Returns True if running on Windows Server 2019."""
25+
26+
if not is_windows:
27+
return False
28+
29+
windows_caption = subprocess.check_output(["wmic", "os", "get", "Caption"], text=True)
30+
return "Windows Server 2019" in windows_caption
31+
32+
1533
@pytest.fixture(scope="function")
1634
def connection_uri() -> str:
1735
"""Read and return connection URI from environment."""
@@ -57,35 +75,40 @@ def connection(
5775
raise RuntimeError("f{request.param}: unknown value")
5876

5977

60-
def test_connection_uri(connection_uri):
78+
def test_connection_uri(connection_uri: str):
6179
"""Test that CONNECTION_URI matches EXPECTED_CONNECTION_URI."""
6280

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

6583

66-
def test_service_name(service_name):
84+
def test_service_name(service_name: str):
6785
"""Test that SERVICE_NAME matches EXPECTED_SERVICE_NAME."""
6886

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

7189

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

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

7795

78-
def test_locale(connection: psycopg.Connection):
79-
"""Test that PostgreSQL's locale is 'en_US.UTF-8'."""
96+
def test_locale(connection: psycopg.Connection, is_windows_server_2019: bool):
97+
"""Test that PostgreSQL's locale matches the one we paased to initdb."""
98+
99+
locale_exp = "en_US.UTF-8"
100+
101+
if is_windows_server_2019:
102+
locale_exp = "en-US"
80103

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

84-
assert locale.normalize(lc_collate) == "en_US.UTF-8"
85-
assert locale.normalize(lc_ctype) == "en_US.UTF-8"
107+
assert locale.normalize(lc_collate) == locale_exp
108+
assert locale.normalize(lc_ctype) == locale_exp
86109

87110

88-
def test_environment_variables():
111+
def test_environment_variables(is_windows: bool):
89112
"""Test that only expected 'PG*' variables are set."""
90113

91114
pg_environ = {k: v for k, v in os.environ.items() if k.startswith("PG")}
@@ -96,7 +119,7 @@ def test_environment_variables():
96119
pg_servicefile_exp = pathlib.Path(os.environ["RUNNER_TEMP"], "pgdata", "pg_service.conf")
97120
assert pg_servicefile.resolve() == pg_servicefile_exp.resolve()
98121

99-
if os.name == "nt":
122+
if is_windows:
100123
pg_environ_exp = {
101124
"PGBIN": "",
102125
"PGDATA": "",

0 commit comments

Comments
 (0)