diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2063749..cad94f4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -105,7 +105,7 @@ jobs: - name: Collect Environment run: | - python dev/github_env.py $GITHUB_ENV + python dev/github_env.py - name: Test run: | diff --git a/dev/github_env.py b/dev/github_env.py index 4904f96..d561aca 100644 --- a/dev/github_env.py +++ b/dev/github_env.py @@ -1,10 +1,10 @@ """Helper to determine to correct Python and OS version.""" +import os import platform -import sys -def os(): +def get_os(): if platform.system() == "Linux": try: import subprocess @@ -13,6 +13,7 @@ def os(): ["/usr/bin/lsb_release", "--description", "--short"], capture_output=True, shell=False, + check=False, text=True, ).stdout.splitlines()[0] except Exception: @@ -20,33 +21,39 @@ def os(): if platform.system() == "Windows": versions = { - 10240: 1507, - 10586: 1511, - 14393: 1607, - 15063: 1703, - 16299: 1709, - 17134: 1803, - 17763: 1809, - 18362: 1903, - 18363: 1909, - 19041: 2004, - 19042: "20H2", - 19043: "21H1", - 19044: "21H2", - 19045: "22H2", - 22000: "21H2", - 22621: "22H2", - 22631: "23H2", + 14393: "Windows Server 2016 (1607)", + 16299: "Windows Server 2016 (1709)", + 17134: "Windows Server 2016 (1803)", + 17763: "Windows Server 2019 (1809)", + 18362: "Windows Server 2019 (1903)", + 18363: "Windows Server 2019 (1909)", + 19041: "Windows Server 2019 (2004)", + 19042: "Windows Server 2019 (20H2)", + 20348: "Windows Server 2022 (21H2)", } try: - version = int(platform.version().split(".")[-1]) - return f"Windows-{platform.release()} ({versions[version]})" + build = int(platform.version().split(".")[-1]) + return versions[build] except Exception: pass - return platform.platform(terse=True) + if platform.system() == "Darwin": + versions = { + 20: "macOS Big Sur", + 21: "macOS Monterey", + 22: "macOS Ventura", + 23: "macOS Sonoma", + } + try: + darwin = int(platform.release().split(".")[0]) + version = platform.platform().split("-")[1] + return f"{versions[darwin]} ({version})" + except Exception: + pass + + return platform.platform() -with open(sys.argv[1], "a") as f: +with open(os.environ["GITHUB_ENV"], "a") as f: f.write(f"PYTHON={platform.python_version()}\n") - f.write(f"OS={os()}\n") + f.write(f"OS={get_os()}\n") diff --git a/dev/os_version.py b/dev/os_version.py deleted file mode 100644 index f6f2c8f..0000000 --- a/dev/os_version.py +++ /dev/null @@ -1,36 +0,0 @@ -"""Helper to determine to correct OS.""" -import platform - - -if platform.system() == "Linux": - import os - - os.system("/usr/bin/lsb_release -ds") - -elif platform.system() == "Windows": - versions = { - 10240: (10, 1507), - 10586: (10, 1511), - 14393: (10, 1607), - 15063: (10, 1703), - 16299: (10, 1709), - 17134: (10, 1803), - 17763: (10, 1809), - 18362: (10, 1903), - 18363: (10, 1909), - 19041: (10, 2004), - 19042: (10, "20H2"), - 19043: (10, "21H1"), - 19044: (10, "21H2"), - 19045: (10, "22H2"), - 22000: (11, "21H2"), - 22621: (11, "22H2"), - } - result = platform.platform() - for i in versions: - if str(i) in result: - result = f"Windows-{versions[i][0]} ({versions[i][1]})" - print(result) - -else: - print(platform.platform(terse=True))