|
| 1 | +name: PyTorch IFU (Sync with upstream) |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + ifu_target_repo: |
| 7 | + description: "Target repo for IFU" |
| 8 | + required: false |
| 9 | + default: "ROCm/pytorch" |
| 10 | + type: string |
| 11 | + ifu_target_branch: |
| 12 | + description: "Target branch for IFU" |
| 13 | + required: true |
| 14 | + default: "rocm7.1_internal_testing" |
| 15 | + type: string |
| 16 | + ifu_source_repo: |
| 17 | + description: "Source repo for IFU" |
| 18 | + required: false |
| 19 | + default: "pytorch/pytorch" |
| 20 | + type: string |
| 21 | + ifu_source_branch: |
| 22 | + description: "Source branch for IFU" |
| 23 | + required: false |
| 24 | + default: "main" |
| 25 | + type: string |
| 26 | + # schedule: |
| 27 | + # # Runs every 14 days at 09:00 AM UTC/ 04:00 AM CST |
| 28 | + # - cron: "0 9 */14 * *" |
| 29 | + |
| 30 | +permissions: |
| 31 | + contents: write # push branches/tags |
| 32 | + pull-requests: write # create PRs |
| 33 | + |
| 34 | +concurrency: |
| 35 | + group: ifu |
| 36 | + # If two jobs are running simultaneously, we will queue them (not cancel the one running) |
| 37 | + cancel-in-progress: false |
| 38 | + |
| 39 | +jobs: |
| 40 | + ifu: |
| 41 | + runs-on: ubuntu-latest |
| 42 | + env: |
| 43 | + UPSTREAM_REMOTE: upstream # IFU source remote name |
| 44 | + UPSTREAM_REPO: ${{ inputs.ifu_source_repo }} # source repo for IFU |
| 45 | + UPSTREAM_BRANCH: ${{ inputs.ifu_source_branch }} # source branch for IFU |
| 46 | + DOWNSTREAM_REMOTE: origin # IFU target remote name |
| 47 | + DOWNSTREAM_REPO: ${{ inputs.ifu_target_repo }} # target repo for IFU (fork); actions/checkout sets this to origin |
| 48 | + DOWNSTREAM_BRANCH: ${{ inputs.ifu_target_branch }} # target branch for IFU |
| 49 | + GH_TOKEN: ${{ secrets.PG_GITHUB_TOKEN }} # used by gh; provided by Action @TODO remove PG before merging |
| 50 | + steps: |
| 51 | + - name: Checkout repository (${{ env.DOWNSTREAM_REPO }}) (full history) |
| 52 | + uses: actions/checkout@v4 |
| 53 | + with: |
| 54 | + repository: ${{ env.DOWNSTREAM_REPO }} |
| 55 | + path: ${{ env.DOWNSTREAM_REPO }} |
| 56 | + ref: ${{ env.DOWNSTREAM_BRANCH }} |
| 57 | + token: ${{ env.GH_TOKEN }} |
| 58 | + fetch-depth: 0 # need full history for merges/tags |
| 59 | + submodules: recursive |
| 60 | + |
| 61 | + - name: Add upstream remote (${{ env.UPSTREAM_REPO }}) |
| 62 | + working-directory: ${{ env.DOWNSTREAM_REPO }} |
| 63 | + run: | |
| 64 | + if ! git remote get-url ${UPSTREAM_REMOTE} >/dev/null 2>&1; then |
| 65 | + git remote add ${UPSTREAM_REMOTE} https://github.com/${UPSTREAM_REPO}.git |
| 66 | + fi |
| 67 | + # Confirm remotes |
| 68 | + git remote -v |
| 69 | +
|
| 70 | + - name: Configure Git user |
| 71 | + working-directory: ${{ env.DOWNSTREAM_REPO }} |
| 72 | + run: | |
| 73 | + git config user.name "github-actions[bot]" |
| 74 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 75 | +
|
| 76 | + - name: Fetch upstream and local branch |
| 77 | + working-directory: ${{ env.DOWNSTREAM_REPO }} |
| 78 | + run: | |
| 79 | + git fetch ${UPSTREAM_REMOTE} ${UPSTREAM_BRANCH} |
| 80 | + git fetch ${DOWNSTREAM_REMOTE} ${DOWNSTREAM_BRANCH} |
| 81 | +
|
| 82 | + - name: Compute date tag and create working branch |
| 83 | + working-directory: ${{ env.DOWNSTREAM_REPO }} |
| 84 | + id: tag |
| 85 | + shell: bash |
| 86 | + run: | |
| 87 | + DATE="$(date +"%Y-%m-%d")" |
| 88 | + TAG="${DOWNSTREAM_BRANCH}_IFU_${DATE}" |
| 89 | + echo "TAG=${TAG}" >> $GITHUB_OUTPUT |
| 90 | + # Start from rocm branch |
| 91 | + git checkout -b "$TAG" "${DOWNSTREAM_REMOTE}/${DOWNSTREAM_BRANCH}" |
| 92 | +
|
| 93 | + - name: Save ROCm base commit |
| 94 | + working-directory: ${{ env.DOWNSTREAM_REPO }} |
| 95 | + id: rocm_base |
| 96 | + run: | |
| 97 | + base_commit=`git rev-parse --short HEAD` |
| 98 | + echo "ROCM_BASE_COMMIT=$base_commit" >> $GITHUB_OUTPUT |
| 99 | + |
| 100 | + - name: Merge upstream into working branch (non-interactive) |
| 101 | + working-directory: ${{ env.DOWNSTREAM_REPO }} |
| 102 | + id: merge |
| 103 | + run: | |
| 104 | + if git merge "${UPSTREAM_REMOTE}/${UPSTREAM_BRANCH}" --no-edit; then |
| 105 | + echo "merge_status=clean" >> $GITHUB_OUTPUT |
| 106 | + else |
| 107 | + echo "Merge conflicts detected. Committing current resolution snapshot." |
| 108 | + git submodule sync |
| 109 | + git submodule update --init --recursive |
| 110 | + git add -A |
| 111 | + git status |
| 112 | + git commit --no-edit |
| 113 | + echo "merge_status=conflict" >> $GITHUB_OUTPUT |
| 114 | + fi |
| 115 | +
|
| 116 | + - name: Push branch & tag to fork |
| 117 | + working-directory: ${{ env.DOWNSTREAM_REPO }} |
| 118 | + run: | |
| 119 | + git push ${DOWNSTREAM_REMOTE} "${{ steps.tag.outputs.TAG }}" |
| 120 | +
|
| 121 | + - name: Authenticate gh (non-interactive) |
| 122 | + working-directory: ${{ env.DOWNSTREAM_REPO }} |
| 123 | + run: | |
| 124 | + # The GitHub-hosted runner has gh preinstalled. |
| 125 | + gh auth status || echo "$GH_TOKEN" | gh auth login --with-token |
| 126 | + gh repo set-default "${{ env.DOWNSTREAM_REPO }}" |
| 127 | +
|
| 128 | + - name: Create Pull Request with gh |
| 129 | + working-directory: ${{ env.DOWNSTREAM_REPO }} |
| 130 | + run: | |
| 131 | + BASE="${DOWNSTREAM_BRANCH}" |
| 132 | + HEAD="${{ steps.tag.outputs.TAG }}" |
| 133 | + TITLE="[AUTOGENERATED] $HEAD" |
| 134 | + BODY="rocm_base: ${{ steps.rocm_base.outputs.ROCM_BASE_COMMIT }}" |
| 135 | +
|
| 136 | + # If a PR for this head already exists, skip creating a new one |
| 137 | + if gh pr list --head "$HEAD" --base "$BASE" --state all --json number | grep -q '[0-9]'; then |
| 138 | + echo "PR already exists for $HEAD -> $BASE. Skipping creation." |
| 139 | + else |
| 140 | + gh pr create --base "$BASE" --head "$HEAD" --title "$TITLE" --body "$BODY" |
| 141 | + fi |
| 142 | +
|
| 143 | + - name: Summarize |
| 144 | + run: | |
| 145 | + echo "::notice title=IFU Completed::Branch ${{ steps.tag.outputs.TAG }} pushed. PR created (or already existed). Merge status: ${{ steps.merge.outputs.merge_status }}" |
0 commit comments