Skip to content

Commit 2d20e22

Browse files
authored
Sync PR head with microsoft/typespec main before regeneration (#47770)
* Sync PR head with microsoft/typespec main before regeneration * Use if-then-else for upstream remote setup (shellcheck SC2015)
1 parent c3c5bf7 commit 2d20e22

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

.github/workflows/typespec-python-regenerate.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,31 @@ jobs:
101101
path: _typespec
102102
fetch-depth: 0
103103

104+
- name: Sync PR head with microsoft/typespec main
105+
# Only relevant for PR-sourced runs. Merging main into the PR head
106+
# ensures the regenerated diff reflects only the PR's changes on top of
107+
# current main, rather than including changes the PR is simply behind on.
108+
if: steps.typespec-info.outputs.typespec_pr_number != ''
109+
working-directory: _typespec
110+
run: |
111+
set -euo pipefail
112+
git config user.name "github-actions[bot]"
113+
git config user.email "github-actions[bot]@users.noreply.github.com"
114+
# The checkout's "origin" points at the PR head repo (possibly a
115+
# fork), so add microsoft/typespec explicitly to fetch its main.
116+
if git remote get-url upstream >/dev/null 2>&1; then
117+
git remote set-url upstream https://github.com/microsoft/typespec.git
118+
else
119+
git remote add upstream https://github.com/microsoft/typespec.git
120+
fi
121+
git fetch --no-tags upstream main
122+
if ! git merge --no-edit upstream/main; then
123+
git merge --abort || true
124+
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."
125+
exit 1
126+
fi
127+
echo "::notice::Merged microsoft/typespec main into PR head ($(git rev-parse --short HEAD))"
128+
104129
- name: Setup Node.js
105130
# SHA corresponds to actions/setup-node@v6
106131
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e

0 commit comments

Comments
 (0)