← Back to Pull requests

[ci] Fetch external CI sources through fetch_sources.py #9854

Merged
ScottTodd merged 18 files (2479 lines) on Nov 11, 2026 21:19 UTC
View on GitHub
ScottTodd ScottTodd commented on Nov 09, 2026 23:52 UTC
Author

Motivation

Part 2/2 of following up on https://github.com/ROCm/TheRock/pull/9618#discussion_r4461999657 to solve https://github.com/ROCm/TheRock/issues/9573 cleanly.

This folds away a large chunk of code custom to "external repo" CI runs.

Technical Details

We currently have code in build_tools/github_actions/detect_external_repo_config.py that passes arguments like

EXTERNAL_FETCH_SOURCES_ARGS: --skip-submodules rocm-libraries --dvc-projects external-rocm-libraries rocm-systems
EXTERNAL_REPO_CONFIG: {"repository": "ROCm/rocm-libraries", "ref": "148db25d37ff5fbd3a8e19596c8e9a561846fb3c", "checkout_path": "external-rocm-libraries", "source_package": "ROCM_LIBRARIES", "submodule_path": "rocm-libraries", "fetch_sources_args": "--skip-submodules rocm-libraries --dvc-projects external-rocm-libraries rocm-systems", "extra_cmake_options": "-DTHEROCK_FLAG_HIPKERNELPROVIDER_ENABLE_ROCKE=ON", "projects": "", "family_overrides": {}}

This feeds into

1. One job running actions/checkout, only for "external repo" CI runs:

    - name: Checkout external repository
      if: ${{ inputs.external_repo_config != '' && fromJSON(inputs.external_repo_config).stages[inputs.stage_name].needs_source }}
      timeout-minutes: 10
      uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
    

2. Another job running build_tools/fetch_sources.py with the extra --skip-submodules rocm-libraries --dvc-projects external-rocm-libraries rocm-systems args:
    - name: Fetch sources
      env:
        EXTERNAL_FETCH_SOURCES_ARGS: ${{ inputs.external_repo_config != '' && fromJSON(inputs.external_repo_config).stages[inputs.stage_name].fetch_sources_args || '' }}
      run: |
        ./build_tools/fetch_sources.py --stage ${STAGE_NAME} --jobs 12 --depth 1 ${EXTERNAL_FETCH_SOURCES_ARGS}
    

Instead we can teach fetch_sources.py to directly read submodule_path and ref from EXTERNAL_REPO_CONFIG and use that to decide whether to redirect a particular submodule during checkout (_if_ checkout is needed).

This guarantees (without forking implementation code from other files) that we
1. Only fetch git submodules that are required by each build stage
2. Only fetch DVC files when we fetch the associated git submodules
3. Benefit from shared optimizations to checkout performance (e.g. git mirrors)

The implementation in fetch_sources.py uses git config --file .gitmodules to cheaply edit the git submodule state prior to running git submodule update. We could implement something similar as a layer on top of git by using our manifest files as the checkout source.

Test Plan

Unit tests on this PR

  • E2E testing as part of the full stack: https://github.com/ROCm/rocm-libraries/actions/runs/42720646408

  • 1. No "Checkout external repository"
    2. compiler-runtime stage clones llvm, rocm-systems, etc. and _not_ rocm-libraries
    4. math-libs stage clones rocm-libraries from the EXTERNAL_REPO_CONFIG ref

    Submission Checklist

  • Look over the contributing guidelines at https://github.com/ROCm/TheRock/blob/main/CONTRIBUTING.md.
  • Diff: 2479 lines (+739 / -1740) across 18 files Reviewer: geomin12 Review duration: 2727m
    All Vouch review confidence checks passed
    Residual risk 0.07 = Change Risk (0.72) × (1 − Review Confidence (0.90)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.72 · 2479 lines diff across 18 files
    0.72
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.88 · 5 substantive comment(s)
    0.88
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    90%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.400
    Mass File Touch mass_file_touch
    0.080
    Real PR Conversation Timeline
    11 items
    therock-pr-bot[bot] therock-pr-bot[bot] commented on Nov 09, 2026 23:53 UTC
    Bot

    <!-- therock-pr-bot-policy-check -->

    ✅ All Checks Passed — Ready for Review

    | Check | Status | Details |
    |---|:---:|---|
    | 📝 PR Description | ✅ Pass | — |
    | ⛔ Forbidden Files | ✅ Pass | — |
    | 🧪 Unit Test | ✅ Pass | — |
    | 🔎 pre-commit | ✅ Pass | — |
    | 🚫 Draft PR | 🔜 To Be Enabled | — |
    | 🚩 Feature Flag | 🔜 To Be Enabled | — |
    | 📊 Code Coverage | 🔜 To Be Enabled | — |
    | 🤖 therock-pr-bot | ✅ Pass | — |

    🎉 All checks passed! This PR is ready for review.

    📖 Need help? See the Policy FAQ for details on every check and how to fix failures.

    🙋 Wish to Override Policy?

    therock-pr-bot[bot] therock-pr-bot[bot] commented on Nov 09, 2026 23:53 UTC
    Bot

    <!-- therock-pr-bot-fix-policies -->
    🎉 All checks passed! This PR is ready for review.

    geomin12 geomin12 commented on code on Nov 10, 2026 22:05 UTC
    Code Review
    build_tools/_therock_utils/external_repo_config.py:1

    needs a rebase?

    this has landed! https://github.com/ROCm/TheRock/pull/9853

    geomin12 geomin12 commented on code on Nov 10, 2026 22:06 UTC
    Code Review
    build_tools/tests/external_repo_config_test.py:1

    rebase! i reviewed and it landed here: https://github.com/ROCm/TheRock/pull/9853/changes

    geomin12 geomin12 commented on code on Nov 10, 2026 22:12 UTC
    Code Review
    build_tools/fetch_sources.py:1
    @@ -497,8 +567,60 @@ def _fetch_one_external_git_source(
         run_command(["git", "reset", "--hard", source.commit], cwd=source_dir)
     
     
    +def apply_external_repo_override(config: dict) -> str:
    +    """Stage the external commit pin without changing submodule remotes.
    +
    +    Intended for disposable CI checkouts: the gitlink change stays in the index,
    +    while HEAD remains the original TheRock commit. Only submodule_path and ref
    +    control checkout; repository is metadata, not a remote override. Normal
    +    submodule initialization uses .gitmodules. Manifest generation receives
    +    the same EXTERNAL_REPO_CONFIG to describe the effective source identity.
    +    """
    +    if not re.fullmatch(r"[0-9a-fA-F]{40}", config["ref"]):
    +        raise ValueError("EXTERNAL_REPO_CONFIG 'ref' must be a full commit SHA")
    +    output = subprocess.check_output(
    +        [
    +            "git",
    +            "config",
    +            "--file",
    +            ".gitmodules",
    +            "--get-regexp",
    +            r"^submodule\..*\.path$",
    +        ],
    +        cwd=THEROCK_DIR,
    +        text=True,
    +    )
    +    matches = [
    +        key.removeprefix("submodule.").removesuffix(".path")
    +        for key, path in (line.split(maxsplit=1) for line in output.splitlines())
    +        if path == config["submodule_path"]
    +    ]
    +    if len(matches) != 1:
    +        raise ValueError(
    +            f"External path {config['submodule_path']!r} must match one submodule"
    +        )
    +    name = matches[0]
    +    path = config["submodule_path"]
    +    run_command(
    +        ["git", "update-index", "--no-skip-worktree", "--", path], cwd=THEROCK_DIR

    nit: i see this in https://github.com/ROCm/rocm-libraries/actions/runs/42720646408/job/129527701470#step:11:43 and it works! (needed to confirm)

    however, it's quite deep and hidden, really had to hunt for it. when we did have the checkout step, it was nice to confirm what hash it was (and it was very easy to find)

    could we perhaps add some logging to indicating that we got a custom checkout and this is hash? from EXTERNAL_REPO?

    geomin12 geomin12 approved these changes on Nov 10, 2026 22:12 UTC
    Approved Reviewer

    lgtm, few comments

    ScottTodd ScottTodd commented on code on Nov 10, 2026 22:42 UTC
    Code Review
    build_tools/_therock_utils/external_repo_config.py:1

    Just an artifact of using github's stacked PRs. The second commit is what's new in this PR. I can rebase to make that more clear.

    ScottTodd ScottTodd commented on code on Nov 11, 2026 00:29 UTC
    Code Review
    build_tools/fetch_sources.py:1
    @@ -497,8 +567,60 @@ def _fetch_one_external_git_source(
         run_command(["git", "reset", "--hard", source.commit], cwd=source_dir)
     
     
    +def apply_external_repo_override(config: dict) -> str:
    +    """Stage the external commit pin without changing submodule remotes.
    +
    +    Intended for disposable CI checkouts: the gitlink change stays in the index,
    +    while HEAD remains the original TheRock commit. Only submodule_path and ref
    +    control checkout; repository is metadata, not a remote override. Normal
    +    submodule initialization uses .gitmodules. Manifest generation receives
    +    the same EXTERNAL_REPO_CONFIG to describe the effective source identity.
    +    """
    +    if not re.fullmatch(r"[0-9a-fA-F]{40}", config["ref"]):
    +        raise ValueError("EXTERNAL_REPO_CONFIG 'ref' must be a full commit SHA")
    +    output = subprocess.check_output(
    +        [
    +            "git",
    +            "config",
    +            "--file",
    +            ".gitmodules",
    +            "--get-regexp",
    +            r"^submodule\..*\.path$",
    +        ],
    +        cwd=THEROCK_DIR,
    +        text=True,
    +    )
    +    matches = [
    +        key.removeprefix("submodule.").removesuffix(".path")
    +        for key, path in (line.split(maxsplit=1) for line in output.splitlines())
    +        if path == config["submodule_path"]
    +    ]
    +    if len(matches) != 1:
    +        raise ValueError(
    +            f"External path {config['submodule_path']!r} must match one submodule"
    +        )
    +    name = matches[0]
    +    path = config["submodule_path"]
    +    run_command(
    +        ["git", "update-index", "--no-skip-worktree", "--", path], cwd=THEROCK_DIR

    Sure, will do.

    I think I'll add logs/output in two places:
    1. During submodule fetching in this script itself
    2. During CI configure, highlighting the current branch and which commits of both TheRock and submodule overrides are used. That is also available in the manifest file but we can make it more directly usable by working it into the output here: <img width="798" height="648" alt="image" src="https://github.com/user-attachments/assets/79345fa5-4712-4ba2-9c78-6f9372dc7964" />

    Leaning towards text like

    > Trigger: workflow_dispatch on users/scotttodd/unify-external-source-fetching, release variant.
    >
    > Source: TheRock at be98e6d575a7 with submodule override rocm-libraries at e32d55782c6b.

    ScottTodd ScottTodd commented on code on Nov 11, 2026 00:43 UTC
    Code Review
    build_tools/fetch_sources.py:1
    @@ -497,8 +567,60 @@ def _fetch_one_external_git_source(
         run_command(["git", "reset", "--hard", source.commit], cwd=source_dir)
     
     
    +def apply_external_repo_override(config: dict) -> str:
    +    """Stage the external commit pin without changing submodule remotes.
    +
    +    Intended for disposable CI checkouts: the gitlink change stays in the index,
    +    while HEAD remains the original TheRock commit. Only submodule_path and ref
    +    control checkout; repository is metadata, not a remote override. Normal
    +    submodule initialization uses .gitmodules. Manifest generation receives
    +    the same EXTERNAL_REPO_CONFIG to describe the effective source identity.
    +    """
    +    if not re.fullmatch(r"[0-9a-fA-F]{40}", config["ref"]):
    +        raise ValueError("EXTERNAL_REPO_CONFIG 'ref' must be a full commit SHA")
    +    output = subprocess.check_output(
    +        [
    +            "git",
    +            "config",
    +            "--file",
    +            ".gitmodules",
    +            "--get-regexp",
    +            r"^submodule\..*\.path$",
    +        ],
    +        cwd=THEROCK_DIR,
    +        text=True,
    +    )
    +    matches = [
    +        key.removeprefix("submodule.").removesuffix(".path")
    +        for key, path in (line.split(maxsplit=1) for line in output.splitlines())
    +        if path == config["submodule_path"]
    +    ]
    +    if len(matches) != 1:
    +        raise ValueError(
    +            f"External path {config['submodule_path']!r} must match one submodule"
    +        )
    +    name = matches[0]
    +    path = config["submodule_path"]
    +    run_command(
    +        ["git", "update-index", "--no-skip-worktree", "--", path], cwd=THEROCK_DIR
    ScottTodd ScottTodd commented on Nov 11, 2026 00:45 UTC
    Author

    Pushed a commit changing the logging / summary information. I'll let the CI runs complete on those test runs and plan on merging tomorrow.

    Reviewers
    Assignees
    ScottTodd ScottTodd
    Labels
    risk: low confidence: 90.1% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 71.5% (HIGH) · Higher = larger blast radius
    71.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 90.1% · Lower = rushed or shallow review
    90.1%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 7.1% · Safe to merge
    7.1%
    Repository