CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
77 lines
2.3 KiB
Python
77 lines
2.3 KiB
Python
"""Shared CI utilities for GitHub Actions workflow scripts."""
|
|
|
|
import fnmatch
|
|
import logging
|
|
import os
|
|
import subprocess
|
|
import time
|
|
from typing import Callable, Iterable, Mapping, Tuple, Type, TypeVar
|
|
|
|
F = TypeVar("F", bound=Callable[..., object])
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
|
|
def retry(
|
|
max_attempts: int,
|
|
delay_seconds: float,
|
|
exceptions: Tuple[Type[BaseException], ...],
|
|
) -> Callable[[F], F]:
|
|
"""Retry decorator with exponential backoff."""
|
|
|
|
def decorator(func: F) -> F:
|
|
def wrapper(*args, **kwargs):
|
|
attempt = 0
|
|
while attempt < max_attempts:
|
|
try:
|
|
return func(*args, **kwargs)
|
|
except exceptions as e:
|
|
print(
|
|
f"Exception {str(e)} thrown when attempting to run, "
|
|
f"attempt {attempt} of {max_attempts}"
|
|
)
|
|
attempt += 1
|
|
if attempt < max_attempts:
|
|
backoff = delay_seconds * (2 ** (attempt - 1))
|
|
time.sleep(backoff)
|
|
return func(*args, **kwargs)
|
|
|
|
return wrapper
|
|
|
|
return decorator
|
|
|
|
|
|
@retry(max_attempts=3, delay_seconds=2, exceptions=(TimeoutError,))
|
|
def get_modified_paths(base_ref: str) -> set[str]:
|
|
"""Returns paths of files changed relative to the base reference."""
|
|
result = subprocess.run(
|
|
["git", "diff", "--name-only", base_ref],
|
|
capture_output=True,
|
|
text=True,
|
|
check=True,
|
|
timeout=60,
|
|
)
|
|
return set(result.stdout.splitlines())
|
|
|
|
|
|
def matches_paths(changed_files: Iterable[str], patterns: Iterable[str]) -> bool:
|
|
"""Returns True if any changed file matches any of the fnmatch patterns."""
|
|
for f in changed_files:
|
|
for pattern in patterns:
|
|
if fnmatch.fnmatch(f, pattern):
|
|
return True
|
|
return False
|
|
|
|
|
|
def set_github_output(outputs: Mapping[str, str]):
|
|
"""Writes key=value pairs to GITHUB_OUTPUT (or prints if not in CI)."""
|
|
logging.info(f"Setting github output:\n{dict(outputs)}")
|
|
output_file = os.environ.get("GITHUB_OUTPUT", "")
|
|
if not output_file:
|
|
for k, v in outputs.items():
|
|
print(f"{k}={v}")
|
|
return
|
|
with open(output_file, "a") as f:
|
|
for k, v in outputs.items():
|
|
f.write(f"{k}={v}\n")
|