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