Skip to content

Add GitHub Action for checking out upstream PyTorch PRs - #178750

Closed
KarhouTam wants to merge 1 commit into
pytorch:mainfrom
KarhouTam:crcr-checkout-upstream-pr-action
Closed

KarhouTam wants to merge 1 commit into
pytorch:mainfrom
KarhouTam:crcr-checkout-upstream-pr-action

Conversation

@KarhouTam

@KarhouTam KarhouTam commented Mar 30, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

This pull request introduces a new GitHub Action, Checkout PyTorch PR, which streamlines the process of checking out a specific commit from an upstream PyTorch pull request into a downstream workspace.

This encapsulates all necessary git operations, making it easier for downstream repositories to integrate upstream changes without handling git commands or parsing payloads themselves.

New GitHub Action for Upstream PR Checkout:

  • Added .github/actions/checkout-upstream-pr/action.yml defining a composite action that:
    • Accepts path and token as inputs for customization.
    • Fetches and checks out a specific commit from an upstream repository using values from the repository_dispatch event payload.
    • Initializes the repository and submodules in the specified workspace path.
    • Encapsulates all git logic, reducing complexity for downstream repositories.

Context

This PR is a part of contribution to the feature: Cross-Repo-CI-Relay

TODO

  • Another GitHub action for reporting result back to the relay server (at L2 stage)

cc @fffrog @can-gaa-hou @ZainRizvi

@pytorch-bot

pytorch-bot Bot commented Mar 30, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/178750

Note: Links to docs will display an error until the docs builds have been completed.

⚠️ 4 Awaiting Approval

As of commit 9609d87 with merge base 0420c86 (image):

AWAITING APPROVAL - The following workflows need approval before CI can run:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot pytorch-bot Bot added the topic: not user facing topic category label Mar 30, 2026
@KarhouTam
KarhouTam marked this pull request as ready for review March 30, 2026 08:07
@KarhouTam
KarhouTam requested a review from a team as a code owner March 30, 2026 08:07

@ZainRizvi ZainRizvi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting this together! I have a suggestion on the approach.

runs:
using: composite
steps:
- name: Fetch and Checkout Upstream

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test-infra already has a checkout action at pytorch/test-infra/.github/actions/checkout that supports repository, ref, path, fetch-depth, submodules, and token auth — everything this custom action does.

I don't think we need a wrapper action here. Downstream repos can just call the existing checkout action directly with the dispatch payload fields:

# In downstream repo: .github/workflows/pytorch-ci.yml
on:
  repository_dispatch:
    types: [pytorch-pr-trigger]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: pytorch/test-infra/.github/actions/checkout@main
        with:
          repository: ${{ github.event.client_payload.upstream_repo }}
          ref: ${{ github.event.client_payload.head_sha }}
          path: pytorch
          fetch-depth: 1
          submodules: recursive

      - name: Build & test
        run: |
          cd pytorch
          # build pytorch, run downstream tests, etc.

The payload field names are stable and documented in the RFC. Using test-infra's checkout also means downstream repos get a smaller, faster checkout of the action itself (vs cloning all of pytorch/pytorch just to get the action).

If we do decide we want a convenience wrapper, it should live in test-infra rather than pytorch/pytorch, and just delegate to the existing checkout action.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ZainRizvi Thank you for your valuable suggestions.

Regarding this action, our preliminary idea was to ensure that downstream repositories only perceive the pytorch repository, and not the test-infra and ci-infra repositories. Therefore, we tried adding the action to the pytorch, but this did present some problems. For example, the workflow required cloning the entire pytorch to use the action, which was somewhat wasteful and unreasonable.

Therefore, placing all actions in test-infra seems like a better solution. Given this, I believe the action pytorch/test-infra/.github/actions/checkout is sufficient for our needs and can speed things up.

Furthermore, starting from L2, we need an action to feed the results of the downstream CI back to the HUD, so you think this action should also be placed in test-infra as well, right?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ZainRizvi, you're right. We can switch to the standard actions/checkout, as the version in test-infra is a fork and the original should fully meet CRCR's requirements. wdyt? If that sounds good, we can provide guidelines and example downstream workflow YAMLs to assist developers once CRCR L1 is landed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Furthermore, starting from L2, we need an action to feed the results of the downstream CI back to the HUD, so you think this action should also be placed in test-infra as well, right?

@fffrog Yes, I think test-infra would be an appropriate place to keep that action. It's our general home for pytorch CI infrastructure that's not limited to the pytorc/pytorch repo

We can switch to the standard actions/checkout, as the version in test-infra is a fork and the original should fully meet CRCR's requirements. wdyt?

@KarhouTam yes, using the default github actions checkout should be just fine

git submodule update --init --recursive --jobs 8

popd

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: git rev-parse HEAD runs after popd, so it executes in the original working directory, not the checkout path. Would need git -C "${CHECKOUT_PATH}" rev-parse HEAD. Moot if we drop this in favor of the existing checkout action though.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thank you.

@soulitzer soulitzer added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Apr 2, 2026
@KarhouTam

Copy link
Copy Markdown
Collaborator Author

Decide to reuse actions/checkout with proper guideline. This PR closed.

@KarhouTam KarhouTam closed this Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

open source topic: not user facing topic category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants