From 3ec7c54ad448d26f98e97d227cbf16932ac7b64b Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Tue, 30 Jun 2026 17:13:41 +0800 Subject: [PATCH 1/2] Sync PR head with microsoft/typespec main before regeneration --- .../workflows/typespec-python-regenerate.yml | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/.github/workflows/typespec-python-regenerate.yml b/.github/workflows/typespec-python-regenerate.yml index a115f5466bff..2ab809b80f90 100644 --- a/.github/workflows/typespec-python-regenerate.yml +++ b/.github/workflows/typespec-python-regenerate.yml @@ -101,6 +101,29 @@ jobs: path: _typespec fetch-depth: 0 + - name: Sync PR head with microsoft/typespec main + # Only relevant for PR-sourced runs. Merging main into the PR head + # ensures the regenerated diff reflects only the PR's changes on top of + # current main, rather than including changes the PR is simply behind on. + if: steps.typespec-info.outputs.typespec_pr_number != '' + working-directory: _typespec + run: | + set -euo pipefail + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + # The checkout's "origin" points at the PR head repo (possibly a + # fork), so add microsoft/typespec explicitly to fetch its main. + git remote get-url upstream >/dev/null 2>&1 \ + && git remote set-url upstream https://github.com/microsoft/typespec.git \ + || git remote add upstream https://github.com/microsoft/typespec.git + git fetch --no-tags upstream main + if ! git merge --no-edit upstream/main; then + git merge --abort || true + echo "::error::microsoft/typespec PR #${{ steps.typespec-info.outputs.typespec_pr_number }} conflicts with microsoft/typespec main. Please update the PR branch by merging (or rebasing onto) the latest main and resolving the conflicts, then re-run this workflow." + exit 1 + fi + echo "::notice::Merged microsoft/typespec main into PR head ($(git rev-parse --short HEAD))" + - name: Setup Node.js # SHA corresponds to actions/setup-node@v6 uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e From 6990dad9a148651bc4b6f37de5593f6c7e8c7376 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Tue, 30 Jun 2026 17:15:42 +0800 Subject: [PATCH 2/2] Use if-then-else for upstream remote setup (shellcheck SC2015) --- .github/workflows/typespec-python-regenerate.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/typespec-python-regenerate.yml b/.github/workflows/typespec-python-regenerate.yml index 2ab809b80f90..b73ddc66278a 100644 --- a/.github/workflows/typespec-python-regenerate.yml +++ b/.github/workflows/typespec-python-regenerate.yml @@ -113,9 +113,11 @@ jobs: git config user.email "github-actions[bot]@users.noreply.github.com" # The checkout's "origin" points at the PR head repo (possibly a # fork), so add microsoft/typespec explicitly to fetch its main. - git remote get-url upstream >/dev/null 2>&1 \ - && git remote set-url upstream https://github.com/microsoft/typespec.git \ - || git remote add upstream https://github.com/microsoft/typespec.git + if git remote get-url upstream >/dev/null 2>&1; then + git remote set-url upstream https://github.com/microsoft/typespec.git + else + git remote add upstream https://github.com/microsoft/typespec.git + fi git fetch --no-tags upstream main if ! git merge --no-edit upstream/main; then git merge --abort || true