diff --git a/.github/workflows/lt-rebase-merge.yml b/.github/workflows/lt-rebase-merge.yml index 7e94232b14df6..1f09811040896 100644 --- a/.github/workflows/lt-rebase-merge.yml +++ b/.github/workflows/lt-rebase-merge.yml @@ -228,7 +228,40 @@ jobs: git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" git config --global user.name "github-actions[bot]" + - name: Park open PRs on temporary branch + env: + GH_TOKEN: ${{ steps.generate-token.outputs.token }} + REPOSITORY: ${{ github.repository }} + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + run: | + set -e + + OPEN_PRS=$(gh pr list --repo "$REPOSITORY" --base "$TARGET_BRANCH" --state open --json number --jq '[.[].number | tostring] | join(" ")') + + if [ -z "$OPEN_PRS" ]; then + echo "No open PRs targeting ${TARGET_BRANCH}" + exit 0 + fi + + TEMP_BRANCH="_pr_parking_${TARGET_BRANCH}_run${GITHUB_RUN_ID}" + echo "Parking PRs on ${TEMP_BRANCH}: ${OPEN_PRS}" + + cd kernel-src-tree + git push origin "origin/${TARGET_BRANCH}:refs/heads/${TEMP_BRANCH}" + echo "TEMP_BRANCH=$TEMP_BRANCH" >> $GITHUB_ENV + + for pr in $OPEN_PRS; do + echo "Parking PR #$pr on ${TEMP_BRANCH}" + gh pr edit "$pr" --repo "$REPOSITORY" --base "${TEMP_BRANCH}" + gh pr comment "$pr" --repo "$REPOSITORY" --body-file - </dev/null || true + exit 0 + fi + + if [ "$SCRIPT_OUTCOME" = "success" ]; then + cd kernel-src-tree + git fetch origin --tags --quiet 2>/dev/null || true + NEW_VERSION=$(git describe --tags --abbrev=0 --match='v*' "origin/${TARGET_BRANCH}" 2>/dev/null || echo "the latest upstream release") + + RESTORE_FAILURES=0 + for pr in $PARKED_PRS; do + echo "Retargeting PR #$pr to ${TARGET_BRANCH}" + if ! gh pr edit "$pr" --repo "$REPOSITORY" --base "${TARGET_BRANCH}"; then + echo "❌ Failed to retarget PR #$pr" + gh pr comment "$pr" --repo "$REPOSITORY" --body-file - </dev/null || true + fi + elif [ "$SCRIPT_OUTCOME" = "skipped" ]; then + # Script never ran — TARGET_BRANCH is intact, safe to move PRs back + echo "Rebase was skipped, restoring PRs to ${TARGET_BRANCH}" + RESTORE_FAILURES=0 + for pr in $PARKED_PRS; do + echo "Restoring PR #$pr to ${TARGET_BRANCH}" + if ! gh pr edit "$pr" --repo "$REPOSITORY" --base "${TARGET_BRANCH}"; then + echo "❌ Failed to restore PR #$pr" + gh pr comment "$pr" --repo "$REPOSITORY" --body-file - </dev/null || true + fi + else + # Script ran and failed — TARGET_BRANCH may be in unknown state, don't move PRs + echo "⚠️ Rebase merge failed, leaving PRs on ${TEMP_BRANCH}" + for pr in $PARKED_PRS; do + gh pr comment "$pr" --repo "$REPOSITORY" --body-file - <