From cb179daec2eb5d5e0d256e3a4294dc4a2f52641e Mon Sep 17 00:00:00 2001 From: Prachi Gupta Date: Fri, 3 Oct 2025 20:18:06 +0000 Subject: [PATCH 1/3] [rocm7.1_internal_testing] Add workflow to create IFU tags --- .github/workflows/create_ifu_tag.yml | 116 +++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 .github/workflows/create_ifu_tag.yml diff --git a/.github/workflows/create_ifu_tag.yml b/.github/workflows/create_ifu_tag.yml new file mode 100644 index 0000000000000..27b3aaef78824 --- /dev/null +++ b/.github/workflows/create_ifu_tag.yml @@ -0,0 +1,116 @@ +name: Create git tags for IFU PRs + +on: + pull_request: + types: [closed] + +permissions: + contents: write # create/push tags + pull-requests: write # edit PR body + +jobs: + tag-ifu: + # Only proceed if: merged AND title has both markers + if: > + github.event.pull_request.merged == true && + contains(github.event.pull_request.title, '[AUTOGENERATED]') && + contains(github.event.pull_request.title, 'IFU') + runs-on: ubuntu-latest + + steps: + - name: Checkout base repo (full history) + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.base.ref }} + fetch-depth: 0 + + - name: Configure Git user + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + - name: Derive key SHAs (rocm base, upstream main, merge) + id: shas + shell: bash + run: | + set -euo pipefail + + PR_NUM="${{ github.event.pull_request.number }}" + BASE_REF="${{ github.event.pull_request.base.ref }}" + HEAD_SHA="${{ github.event.pull_request.head.sha }}" + MERGE_SHA="${{ github.event.pull_request.merge_commit_sha }}" + + # The ROCm base commit is the first parent of the merge commit that landed the PR + # (i.e., the base branch tip BEFORE this PR merged). + ROCM_BASE_SHA=$(git rev-parse "${MERGE_SHA}^1") + + # Add and fetch upstream to identify the upstream/main commit that HEAD integrated. + git remote add upstream "https://github.com/pytorch/pytorch.git" + git fetch upstream "$BASE_REF" + + # Heuristic: the upstream commit integrated by the PR's head is the merge-base + # between the PR head commit and upstream/main as fetched now. + # This gives you the exact upstream commit (or the best common ancestor) that HEAD included. + UPSTREAM_MAIN_SHA=$(git merge-base "${HEAD_SHA}" "upstream/$BASE_REF") + echo "PR_NUM=$PR_NUM" + echo "BASE_REF=$BASE_REF" + echo "HEAD_SHA=$HEAD_SHA" + echo "MERGE_SHA=$MERGE_SHA" + echo "ROCM_BASE_SHA=$ROCM_BASE_SHA" + echo "UPSTREAM_MAIN_SHA=$UPSTREAM_MAIN_SHA" + + + echo "PR_NUM=$PR_NUM" >> "$GITHUB_OUTPUT" + echo "BASE_REF=$BASE_REF" >> "$GITHUB_OUTPUT" + echo "HEAD_SHA=$HEAD_SHA" >> "$GITHUB_OUTPUT" + echo "MERGE_SHA=$MERGE_SHA" >> "$GITHUB_OUTPUT" + echo "ROCM_BASE_SHA=$ROCM_BASE_SHA" >> "$GITHUB_OUTPUT" + echo "UPSTREAM_MAIN_SHA=$UPSTREAM_MAIN_SHA" >> "$GITHUB_OUTPUT" + + - name: Extract tag base from PR title + id: tagname + run: | + TITLE="${{ github.event.pull_request.title }}" + # Remove everything up to and including "[AUTOGENERATED]" + BASE_TAG=$(echo "$TITLE" | sed -E 's/^\[AUTOGENERATED\][[:space:]]*//') + + echo "BASE_TAG=$BASE_TAG" + echo "PRE_TAG=${BASE_TAG}_pre" + echo "POST_TAG=${BASE_TAG}_post" + + echo "BASE_TAG=$BASE_TAG" >> $GITHUB_OUTPUT + echo "PRE_TAG=${BASE_TAG}_pre" >> $GITHUB_OUTPUT + echo "POST_TAG=${BASE_TAG}_post" >> $GITHUB_OUTPUT + + - name: Create pre/post tags + shell: bash + run: | + set -euo pipefail + echo "Tagging:" + echo " ${{ steps.tagname.outputs.PRE_TAG }} @ ${{ steps.shas.outputs.ROCM_BASE_SHA }}" + echo " ${{ steps.tagname.outputs.POST_TAG }} @ ${{ steps.shas.outputs.MERGE_SHA }}" + + git tag -a "${{ steps.tagname.outputs.PRE_TAG }}" -m "IFU pre (PR #${{ steps.shas.outputs.PR_NUM }})" "${{ steps.shas.outputs.ROCM_BASE_SHA }}" + git tag -a "${{ steps.tagname.outputs.POST_TAG }}" -m "IFU post (PR #${{ steps.shas.outputs.PR_NUM }})" "${{ steps.shas.outputs.MERGE_SHA }}" + + #Force pushing is safe. If we land a new PR, we'd wanna retag a commit if we have to. + git push origin "refs/tags/${{ steps.tagname.outputs.PRE_TAG }}" -f + git push origin "refs/tags/${{ steps.tagname.outputs.POST_TAG }}" -f + + - name: Append rocm_base & upstream_main to PR body + env: + GH_TOKEN: ${{ secrets.IFU_GITHUB_TOKEN }} + shell: bash + run: | + set -euo pipefail + # Read current body + PR="${{ steps.shas.outputs.PR_NUM }}" + CURR=$(gh api repos/${{ github.repository }}/pulls/$PR --jq .body) + APPEND=$'\n'"rocm_base: ${{ steps.shas.outputs.ROCM_BASE_SHA }}"$'\n'"upstream_main: ${{ steps.shas.outputs.UPSTREAM_MAIN_SHA }}"$'\n' + NEW_BODY="${CURR}${APPEND}" + + # Write to a temp file and update PR body + printf '%s' "$NEW_BODY" > body.txt + gh api --method PATCH -H "Accept: application/vnd.github+json" \ + repos/${{ github.repository }}/pulls/$PR -F body=@body.txt + From 7374413cfec25039b52c4697dd9ea7599a3cb301 Mon Sep 17 00:00:00 2001 From: Prachi Gupta Date: Tue, 7 Oct 2025 14:07:42 -0400 Subject: [PATCH 2/3] Update create_ifu_tag.yml --- .github/workflows/create_ifu_tag.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/create_ifu_tag.yml b/.github/workflows/create_ifu_tag.yml index 27b3aaef78824..97dba1c97c385 100644 --- a/.github/workflows/create_ifu_tag.yml +++ b/.github/workflows/create_ifu_tag.yml @@ -36,13 +36,13 @@ jobs: set -euo pipefail PR_NUM="${{ github.event.pull_request.number }}" - BASE_REF="${{ github.event.pull_request.base.ref }}" - HEAD_SHA="${{ github.event.pull_request.head.sha }}" - MERGE_SHA="${{ github.event.pull_request.merge_commit_sha }}" + BASE_REF="${{ github.event.pull_request.base.ref }}" #Refers to upstream branch + HEAD_SHA="${{ github.event.pull_request.head.sha }}" #Refers to HEAD commit in PR branch + MERGE_SHA="${{ github.event.pull_request.merge_commit_sha }}" #Refers to merge commit that landed the PR # The ROCm base commit is the first parent of the merge commit that landed the PR # (i.e., the base branch tip BEFORE this PR merged). - ROCM_BASE_SHA=$(git rev-parse "${MERGE_SHA}^1") + ROCM_BASE_SHA=$(git rev-parse "${MERGE_SHA}^1") #Tip Of Tree of rocm branch pre-IFU merge # Add and fetch upstream to identify the upstream/main commit that HEAD integrated. git remote add upstream "https://github.com/pytorch/pytorch.git" @@ -51,7 +51,7 @@ jobs: # Heuristic: the upstream commit integrated by the PR's head is the merge-base # between the PR head commit and upstream/main as fetched now. # This gives you the exact upstream commit (or the best common ancestor) that HEAD included. - UPSTREAM_MAIN_SHA=$(git merge-base "${HEAD_SHA}" "upstream/$BASE_REF") + UPSTREAM_MAIN_SHA=$(git merge-base "${HEAD_SHA}" "upstream/$BASE_REF") #Tip of Tree of upstream branch that we pulled locally echo "PR_NUM=$PR_NUM" echo "BASE_REF=$BASE_REF" echo "HEAD_SHA=$HEAD_SHA" From bd62484d07db6cc6851858cc0c5cdcf12ba54ac5 Mon Sep 17 00:00:00 2001 From: Prachi Gupta Date: Tue, 7 Oct 2025 14:57:54 -0400 Subject: [PATCH 3/3] change base_ref to upstream_base_ref --- .github/workflows/create_ifu_tag.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/create_ifu_tag.yml b/.github/workflows/create_ifu_tag.yml index 97dba1c97c385..b6d69f6516ba8 100644 --- a/.github/workflows/create_ifu_tag.yml +++ b/.github/workflows/create_ifu_tag.yml @@ -36,7 +36,7 @@ jobs: set -euo pipefail PR_NUM="${{ github.event.pull_request.number }}" - BASE_REF="${{ github.event.pull_request.base.ref }}" #Refers to upstream branch + UPSTREAM_BASE_REF="${{ github.event.pull_request.base.ref }}" #Refers to upstream branch HEAD_SHA="${{ github.event.pull_request.head.sha }}" #Refers to HEAD commit in PR branch MERGE_SHA="${{ github.event.pull_request.merge_commit_sha }}" #Refers to merge commit that landed the PR @@ -46,14 +46,14 @@ jobs: # Add and fetch upstream to identify the upstream/main commit that HEAD integrated. git remote add upstream "https://github.com/pytorch/pytorch.git" - git fetch upstream "$BASE_REF" + git fetch upstream "$UPSTREAM_BASE_REF" # Heuristic: the upstream commit integrated by the PR's head is the merge-base # between the PR head commit and upstream/main as fetched now. # This gives you the exact upstream commit (or the best common ancestor) that HEAD included. - UPSTREAM_MAIN_SHA=$(git merge-base "${HEAD_SHA}" "upstream/$BASE_REF") #Tip of Tree of upstream branch that we pulled locally + UPSTREAM_MAIN_SHA=$(git merge-base "${HEAD_SHA}" "upstream/$UPSTREAM_BASE_REF") #Tip of Tree of upstream branch that we pulled locally echo "PR_NUM=$PR_NUM" - echo "BASE_REF=$BASE_REF" + echo "UPSTREAM_BASE_REF=$UPSTREAM_BASE_REF" echo "HEAD_SHA=$HEAD_SHA" echo "MERGE_SHA=$MERGE_SHA" echo "ROCM_BASE_SHA=$ROCM_BASE_SHA" @@ -61,7 +61,7 @@ jobs: echo "PR_NUM=$PR_NUM" >> "$GITHUB_OUTPUT" - echo "BASE_REF=$BASE_REF" >> "$GITHUB_OUTPUT" + echo "UPSTREAM_BASE_REF=$UPSTREAM_BASE_REF" >> "$GITHUB_OUTPUT" echo "HEAD_SHA=$HEAD_SHA" >> "$GITHUB_OUTPUT" echo "MERGE_SHA=$MERGE_SHA" >> "$GITHUB_OUTPUT" echo "ROCM_BASE_SHA=$ROCM_BASE_SHA" >> "$GITHUB_OUTPUT"