Umechand origami #18
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 }}" | |
| # For release branches, local branch is same as remote branch. But, for rocm/pytorch's | |
| # develop branch, we want to use main branch upstream | |
| if [ "$BASE_REF" == "develop" ]; then | |
| BASE_REF="main" | |
| fi | |
| echo "PR_NUM=$PR_NUM" | |
| echo "BASE_REF=$BASE_REF" | |
| echo "HEAD_SHA=$HEAD_SHA" | |
| echo "MERGE_SHA=$MERGE_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 "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]" | |
| # Remove trailing whitespace | |
| BASE_TAG=$(echo "$TITLE" | sed -E 's/^\[AUTOGENERATED\][[:space:]]*//' | sed -E 's/[[: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.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 [email protected] | |