Skip to content

Commit 63c70e5

Browse files
committed
Add create_ifu_tag.yml
This github workflow file acts when an AUTOGENERATED IFU PR is merged. It figures out rocm base and upstream commit that we pulled and create pre and post tags for future reference. Additionally, it also adds this information to the IFU PR.
1 parent 8dda29a commit 63c70e5

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
name: Create git tags for IFU PRs
2+
3+
on:
4+
pull_request_target:
5+
types: [closed]
6+
7+
permissions:
8+
contents: write # create/push tags
9+
pull-requests: write # edit PR body
10+
11+
jobs:
12+
tag-ifu:
13+
# Only proceed if: merged AND title has both markers
14+
if: >
15+
github.event.pull_request.merged == true &&
16+
contains(github.event.pull_request.title, '[AUTOGENERATED]') &&
17+
contains(github.event.pull_request.title, 'IFU')
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout base repo (full history)
22+
uses: actions/checkout@v4
23+
with:
24+
ref: ${{ github.event.pull_request.base.ref }}
25+
fetch-depth: 0
26+
27+
- name: Configure Git user
28+
run: |
29+
git config user.name "github-actions[bot]"
30+
git config user.email "github-actions[bot]@users.noreply.github.com"
31+
32+
- name: Derive key SHAs (rocm base, upstream main, merge)
33+
id: shas
34+
shell: bash
35+
run: |
36+
set -euo pipefail
37+
38+
PR_NUM="${{ github.event.pull_request.number }}"
39+
BASE_REF="${{ github.event.pull_request.base.ref }}"
40+
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
41+
MERGE_SHA="${{ github.event.pull_request.merge_commit_sha }}"
42+
43+
# The ROCm base commit is the first parent of the merge commit that landed the PR
44+
# (i.e., the base branch tip BEFORE this PR merged).
45+
ROCM_BASE_SHA=$(git rev-parse "${MERGE_SHA}^1")
46+
47+
# Add and fetch upstream to identify the upstream/main commit that HEAD integrated.
48+
git remote add upstream "https://github.com/pytorch/pytorch.git"
49+
git fetch upstream "$BASE_REF"
50+
51+
# Heuristic: the upstream commit integrated by the PR's head is the merge-base
52+
# between the PR head commit and upstream/main as fetched now.
53+
# This gives you the exact upstream commit (or the best common ancestor) that HEAD included.
54+
UPSTREAM_MAIN_SHA=$(git merge-base "${HEAD_SHA}" "upstream/$BASE_REF")
55+
echo "PR_NUM=$PR_NUM"
56+
echo "BASE_REF=$BASE_REF"
57+
echo "HEAD_SHA=$HEAD_SHA"
58+
echo "MERGE_SHA=$MERGE_SHA"
59+
echo "ROCM_BASE_SHA=$ROCM_BASE_SHA"
60+
echo "UPSTREAM_MAIN_SHA=$UPSTREAM_MAIN_SHA"
61+
62+
63+
echo "PR_NUM=$PR_NUM" >> "$GITHUB_OUTPUT"
64+
echo "BASE_REF=$BASE_REF" >> "$GITHUB_OUTPUT"
65+
echo "HEAD_SHA=$HEAD_SHA" >> "$GITHUB_OUTPUT"
66+
echo "MERGE_SHA=$MERGE_SHA" >> "$GITHUB_OUTPUT"
67+
echo "ROCM_BASE_SHA=$ROCM_BASE_SHA" >> "$GITHUB_OUTPUT"
68+
echo "UPSTREAM_MAIN_SHA=$UPSTREAM_MAIN_SHA" >> "$GITHUB_OUTPUT"
69+
70+
- name: Extract tag base from PR title
71+
id: tagname
72+
run: |
73+
TITLE="${{ github.event.pull_request.title }}"
74+
# Remove everything up to and including "[AUTOGENERATED]"
75+
BASE_TAG=$(echo "$TITLE" | sed -E 's/^\[AUTOGENERATED\][[:space:]]*//')
76+
77+
echo "BASE_TAG=$BASE_TAG"
78+
echo "PRE_TAG=${BASE_TAG}_pre"
79+
echo "POST_TAG=${BASE_TAG}_post"
80+
81+
echo "BASE_TAG=$BASE_TAG" >> $GITHUB_OUTPUT
82+
echo "PRE_TAG=${BASE_TAG}_pre" >> $GITHUB_OUTPUT
83+
echo "POST_TAG=${BASE_TAG}_post" >> $GITHUB_OUTPUT
84+
85+
- name: Create pre/post tags
86+
shell: bash
87+
run: |
88+
set -euo pipefail
89+
echo "Tagging:"
90+
echo " ${{ steps.tagname.outputs.PRE_TAG }} @ ${{ steps.shas.outputs.ROCM_BASE_SHA }}"
91+
echo " ${{ steps.tagname.outputs.POST_TAG }} @ ${{ steps.shas.outputs.MERGE_SHA }}"
92+
93+
git tag -a "${{ steps.tagname.outputs.PRE_TAG }}" -m "IFU pre (PR #${{ steps.shas.outputs.PR_NUM }})" "${{ steps.shas.outputs.ROCM_BASE_SHA }}"
94+
git tag -a "${{ steps.tagname.outputs.POST_TAG }}" -m "IFU post (PR #${{ steps.shas.outputs.PR_NUM }})" "${{ steps.shas.outputs.MERGE_SHA }}"
95+
96+
#Force pushing is safe. If we land a new PR, we'd wanna retag a commit if we have to.
97+
git push origin "refs/tags/${{ steps.tagname.outputs.PRE_TAG }}" -f
98+
git push origin "refs/tags/${{ steps.tagname.outputs.POST_TAG }}" -f
99+
100+
- name: Append rocm_base & upstream_main to PR body
101+
env:
102+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
103+
shell: bash
104+
run: |
105+
set -euo pipefail
106+
# Read current body
107+
PR="${{ steps.shas.outputs.PR_NUM }}"
108+
CURR=$(gh api repos/${{ github.repository }}/pulls/$PR --jq .body)
109+
APPEND=$'\n'"rocm_base: ${{ steps.shas.outputs.ROCM_BASE_SHA }}"$'\n'"upstream_main: ${{ steps.shas.outputs.UPSTREAM_MAIN_SHA }}"$'\n'
110+
NEW_BODY="${CURR}${APPEND}"
111+
112+
# Write to a temp file and update PR body
113+
printf '%s' "$NEW_BODY" > body.txt
114+
gh api --method PATCH -H "Accept: application/vnd.github+json" \
115+
repos/${{ github.repository }}/pulls/$PR -F [email protected]
116+

0 commit comments

Comments
 (0)