Files
TheRock/build_tools/github_actions/generate_jax_manifest.py
T
derek.holloway 7502bf64a4
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
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

161 lines
4.1 KiB
Python

#!/usr/bin/env python3
"""
Generate a manifest for JAX external builds.
Writes a JSON manifest containing:
- jax: git commit + origin repo (+ branch best-effort)
- therock: repo + commit + branch from GitHub Actions env (best-effort)
Filename format:
therock-manifest_jax_py<python_version>_<jax_git_ref>.json
"""
import argparse
import json
import os
from pathlib import Path
import sys
from github_actions.manifest_utils import (
GitSourceInfo,
git_branch_best_effort,
git_head,
log,
normalize_python_version_for_filename,
normalize_ref_for_filename,
resolve_branch,
)
def manifest_filename(*, python_version: str, jax_git_ref: str) -> str:
py = normalize_python_version_for_filename(python_version)
ref = normalize_ref_for_filename(jax_git_ref)
return f"therock-manifest_jax_py{py}_{ref}.json"
def build_sources(*, jax_dir: Path, jax_git_ref: str) -> dict[str, dict[str, str]]:
jax = git_head(jax_dir, label="jax")
jax_branch = resolve_branch(
inferred=git_branch_best_effort(jax_dir),
provided=jax_git_ref,
)
return {
"jax": GitSourceInfo(
commit=jax.commit, repo=jax.repo, branch=jax_branch
).to_dict(),
}
def build_manifest(
*,
sources: dict[str, dict[str, str]],
therock_repo: str,
therock_commit: str,
therock_branch: str,
) -> dict[str, object]:
manifest: dict[str, object] = {}
manifest.update(sources)
manifest["therock"] = {
"commit": therock_commit,
"repo": therock_repo,
"branch": therock_branch,
}
return manifest
def generate_manifest_dict(
*,
jax_dir: Path,
python_version: str,
jax_git_ref: str,
) -> tuple[str, dict[str, object]]:
sources = build_sources(jax_dir=jax_dir, jax_git_ref=jax_git_ref)
server_url = os.environ.get("GITHUB_SERVER_URL")
repo = os.environ.get("GITHUB_REPOSITORY")
sha = os.environ.get("GITHUB_SHA")
ref = os.environ.get("GITHUB_REF")
therock_repo = "unknown"
if server_url and repo:
therock_repo = f"{server_url}/{repo}.git"
therock_commit = sha or "unknown"
therock_branch = "unknown"
if ref:
if ref.startswith("refs/heads/"):
therock_branch = ref[len("refs/heads/") :]
else:
therock_branch = ref
name = manifest_filename(
python_version=python_version,
jax_git_ref=jax_git_ref,
)
manifest = build_manifest(
sources=sources,
therock_repo=therock_repo,
therock_commit=therock_commit,
therock_branch=therock_branch,
)
return name, manifest
def parse_args(argv: list[str]) -> argparse.Namespace:
ap = argparse.ArgumentParser(description="Generate JAX manifest.")
ap.add_argument(
"--manifest-dir",
type=Path,
required=True,
help="Output directory for the manifest JSON.",
)
ap.add_argument(
"--python-version",
required=True,
help="Python version for manifest naming (e.g. 3.11 or py3.11).",
)
ap.add_argument(
"--jax-git-ref",
required=True,
help=(
"Git ref used for manifest naming and branch fallback "
"(e.g. nightly, release/0.4.28, rocm-jaxlib-v0.8.2)."
),
)
ap.add_argument("--jax-dir", type=Path, required=True)
return ap.parse_args(argv)
def main(argv: list[str]) -> None:
args = parse_args(argv)
manifest_dir = args.manifest_dir.resolve()
manifest_dir.mkdir(parents=True, exist_ok=True)
name, manifest = generate_manifest_dict(
jax_dir=args.jax_dir,
python_version=args.python_version,
jax_git_ref=args.jax_git_ref,
)
out_path = manifest_dir / name
out_path.write_text(
json.dumps(manifest, indent=2, sort_keys=False) + "\n",
encoding="utf-8",
)
if not out_path.exists():
raise RuntimeError(f"Failed to write manifest: {out_path}")
if out_path.stat().st_size == 0:
raise RuntimeError(f"Manifest is empty: {out_path}")
log(f"[jax-sources-manifest] wrote {out_path}")
if __name__ == "__main__":
main(sys.argv[1:])