Skip to content

Commit 3bc43bc

Browse files
committed
Convert CI helper scripts to Python
1 parent f014ced commit 3bc43bc

11 files changed

Lines changed: 482 additions & 261 deletions

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
env:
3333
BASE_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}
3434
HEAD_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
35-
run: ./scripts/ci/clang-format-check.sh "${BASE_SHA}" "${HEAD_SHA}"
35+
run: python3 ./scripts/ci/clang_format_check.py "${BASE_SHA}" "${HEAD_SHA}"
3636
build-linux:
3737
strategy:
3838
matrix:

.github/workflows/sycl-ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ jobs:
5757
uses: ilammy/msvc-dev-cmd@v1
5858

5959
- name: Prepare platform settings
60-
run: ./scripts/ci/sycl-x86-setup.sh "${{ matrix.platform }}"
60+
run: python3 ./scripts/ci/sycl_x86_setup.py "${{ matrix.platform }}"
6161

6262
- name: Configure
63-
run: ./scripts/ci/sycl-configure.sh "${{ matrix.build_type }}" "${SYCL_TARGETS}" "${ITLABAI_ENABLE_OPENCV_APPS}"
63+
run: python3 ./scripts/ci/sycl_configure.py "${{ matrix.build_type }}" "${SYCL_TARGETS}" "${ITLABAI_ENABLE_OPENCV_APPS}"
6464

6565
- name: Build
6666
run: cmake --build build --parallel
@@ -98,10 +98,10 @@ jobs:
9898
max-size: 2G
9999

100100
- name: Install macOS prerequisites
101-
run: ./scripts/ci/sycl-macos-setup.sh
101+
run: python3 ./scripts/ci/sycl_macos_setup.py
102102

103103
- name: Configure
104-
run: ./scripts/ci/sycl-configure.sh "${{ matrix.build_type }}" "${SYCL_TARGETS}" "${ITLABAI_ENABLE_OPENCV_APPS}"
104+
run: python3 ./scripts/ci/sycl_configure.py "${{ matrix.build_type }}" "${SYCL_TARGETS}" "${ITLABAI_ENABLE_OPENCV_APPS}"
105105

106106
- name: Build
107107
run: cmake --build build --parallel

scripts/ci/clang-format-check.sh

Lines changed: 0 additions & 24 deletions
This file was deleted.

scripts/ci/clang_format_check.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env python3
2+
3+
from __future__ import annotations
4+
5+
import os
6+
import subprocess
7+
import sys
8+
9+
from common import capture, main_error, run
10+
11+
12+
def main() -> None:
13+
base_ref = sys.argv[1] if len(sys.argv) > 1 else ""
14+
head_ref = sys.argv[2] if len(sys.argv) > 2 else "HEAD"
15+
16+
if not base_ref or set(base_ref) == {"0"}:
17+
base_ref = capture(["git", "rev-parse", f"{head_ref}^"])
18+
19+
diff_output = subprocess.check_output(
20+
[
21+
"git",
22+
"diff",
23+
"--name-only",
24+
"--diff-filter=ACMR",
25+
base_ref,
26+
head_ref,
27+
"--",
28+
"app",
29+
"include",
30+
"src",
31+
"test",
32+
],
33+
text=True,
34+
)
35+
36+
valid_suffixes = {
37+
".c",
38+
".h",
39+
".C",
40+
".H",
41+
".cpp",
42+
".hpp",
43+
".cc",
44+
".hh",
45+
".c++",
46+
".h++",
47+
".cxx",
48+
".hxx",
49+
}
50+
files = [line for line in diff_output.splitlines() if any(line.endswith(suffix) for suffix in valid_suffixes)]
51+
52+
if not files:
53+
print("No source files changed.")
54+
return
55+
56+
clang_format_bin = os.environ.get("CLANG_FORMAT_BIN", "clang-format-18")
57+
run([clang_format_bin, "--dry-run", "-Werror", *files])
58+
59+
60+
if __name__ == "__main__":
61+
main()

scripts/ci/common.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/usr/bin/env python3
2+
3+
from __future__ import annotations
4+
5+
import os
6+
import shutil
7+
import subprocess
8+
import sys
9+
import tarfile
10+
import urllib.request
11+
from pathlib import Path
12+
13+
14+
def run(command: list[str], *, input_text: str | None = None) -> None:
15+
print("+", " ".join(command), flush=True)
16+
subprocess.run(command, check=True, text=True, input=input_text)
17+
18+
19+
def capture(command: list[str]) -> str:
20+
return subprocess.check_output(command, text=True).strip()
21+
22+
23+
def require_env(name: str) -> str:
24+
value = os.environ.get(name)
25+
if not value:
26+
raise SystemExit(f"Missing required environment variable: {name}")
27+
return value
28+
29+
30+
def write_env(name: str, value: str) -> None:
31+
github_env = os.environ.get("GITHUB_ENV")
32+
if github_env:
33+
with open(github_env, "a", encoding="utf-8") as handle:
34+
handle.write(f"{name}={value}\n")
35+
os.environ[name] = value
36+
37+
38+
def append_path(value: str) -> None:
39+
github_path = os.environ.get("GITHUB_PATH")
40+
if github_path:
41+
with open(github_path, "a", encoding="utf-8") as handle:
42+
handle.write(f"{value}\n")
43+
44+
45+
def prepend_env_path(name: str, value: str) -> None:
46+
current = os.environ.get(name, "")
47+
write_env(name, f"{value}:{current}" if current else value)
48+
49+
50+
def download(url: str, destination: Path) -> None:
51+
destination.parent.mkdir(parents=True, exist_ok=True)
52+
with urllib.request.urlopen(url) as response, open(destination, "wb") as handle:
53+
shutil.copyfileobj(response, handle)
54+
55+
56+
def extract_tarball(archive: Path, destination: Path) -> None:
57+
destination.mkdir(parents=True, exist_ok=True)
58+
with tarfile.open(archive, "r:gz") as tar_handle:
59+
tar_handle.extractall(destination)
60+
61+
62+
def cygpath(mode: str, path: str | Path) -> str:
63+
return capture(["cygpath", f"-{mode}", str(path)])
64+
65+
66+
def find_first_existing(paths: list[Path]) -> Path:
67+
for path in paths:
68+
if path.exists():
69+
return path
70+
raise SystemExit(f"Unable to locate any of: {', '.join(str(path) for path in paths)}")
71+
72+
73+
def find_file(root_candidates: list[Path], filename: str) -> Path | None:
74+
for root in root_candidates:
75+
if not root.exists():
76+
continue
77+
for current_root, _, files in os.walk(root):
78+
if filename in files:
79+
return Path(current_root) / filename
80+
return None
81+
82+
83+
def repo_root() -> Path:
84+
return Path(__file__).resolve().parents[2]
85+
86+
87+
def main_error(message: str) -> None:
88+
print(message, file=sys.stderr)
89+
raise SystemExit(1)

scripts/ci/sycl-configure.sh

Lines changed: 0 additions & 35 deletions
This file was deleted.

scripts/ci/sycl-macos-setup.sh

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)