Skip to content

Commit 7da28a9

Browse files
committed
Deduplicate CI GitHub env helper
1 parent 3664830 commit 7da28a9

4 files changed

Lines changed: 26 additions & 26 deletions

File tree

.github/scripts/ci_common.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import os
2+
3+
4+
def append_github_env(name: str, value: str) -> None:
5+
github_env = os.environ.get("GITHUB_ENV")
6+
if not github_env:
7+
return
8+
with open(github_env, "a", encoding="utf-8") as fh:
9+
fh.write(f"{name}={value}\n")

.github/scripts/ci_gpu.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
import urllib.parse
99
import urllib.request
1010

11+
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
12+
if SCRIPT_DIR not in sys.path:
13+
sys.path.insert(0, SCRIPT_DIR)
14+
15+
from ci_common import append_github_env
16+
1117

1218
def now_ms() -> int:
1319
return time.time_ns() // 1_000_000
@@ -172,14 +178,6 @@ def format_info_url(base_url: str, platform_name: str) -> str:
172178
return f"{normalize_base_url(base_url)}/info?{query}"
173179

174180

175-
def append_github_env(name: str, value: str) -> None:
176-
github_env = os.environ.get("GITHUB_ENV")
177-
if not github_env:
178-
return
179-
with open(github_env, "a", encoding="utf-8") as fh:
180-
fh.write(f"{name}={value}\n")
181-
182-
183181
def print_status(base_url: str, runner_name: str) -> None:
184182
server = build_server_info()
185183
try:

.github/scripts/ci_tests.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
import urllib.error
99
from pathlib import Path
1010

11+
SCRIPT_DIR = Path(__file__).resolve().parent
12+
if str(SCRIPT_DIR) not in sys.path:
13+
sys.path.insert(0, str(SCRIPT_DIR))
14+
15+
from ci_common import append_github_env
1116
from ci_gpu import (
1217
build_job_request,
1318
extract_gpu_ids,
@@ -22,14 +27,6 @@
2227
)
2328

2429

25-
def append_github_env(name: str, value: str) -> None:
26-
github_env = os.environ.get("GITHUB_ENV")
27-
if not github_env:
28-
return
29-
with open(github_env, "a", encoding="utf-8") as fh:
30-
fh.write(f"{name}={value}\n")
31-
32-
3330
def kill_process_group(proc: subprocess.Popen[str]) -> None:
3431
try:
3532
os.killpg(proc.pid, signal.SIGKILL)

.github/scripts/ci_workflow.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
from pathlib import PurePosixPath
1010
from typing import Any
1111

12+
SCRIPT_DIR = Path(__file__).resolve().parent
13+
if str(SCRIPT_DIR) not in sys.path:
14+
sys.path.insert(0, str(SCRIPT_DIR))
15+
16+
from ci_common import append_github_env
17+
1218
import pcre
1319

1420

@@ -20,16 +26,6 @@ def split_csv(raw: str | None) -> list[str]:
2026

2127
def strip_py_suffix(name: str) -> str:
2228
return name.removesuffix(".py")
23-
24-
25-
def append_github_env(name: str, value: str) -> None:
26-
github_env = os.environ.get("GITHUB_ENV")
27-
if not github_env:
28-
return
29-
with open(github_env, "a", encoding="utf-8") as fh:
30-
fh.write(f"{name}={value}\n")
31-
32-
3329
@dataclass(frozen=True)
3430
class TestRuntime:
3531
test_name: str

0 commit comments

Comments
 (0)