Skip to content

Commit 39f0002

Browse files
Copilotpetesramek
andauthored
fix: preserve workspace during branch creation in promote-branch workflow (#162)
`git switch <base-branch>` in the "Create target branch" step replaced the workspace with the base branch contents. Since `main` doesn't carry the composite actions, the immediately following `Lock target branch` step couldn't resolve `action.yml`. ## Change - **`promote-branch.yml`** — replaced the `git switch` + `git checkout -b` + `git push` sequence with a single refspec push: ```sh git fetch origin git push origin origin/<base-branch>:refs/heads/<target-branch> ``` Creates the remote branch from the base ref without touching the local workspace, so the source branch's composite actions remain accessible for subsequent steps. ## Side effect to handle `release/1.0` was already created by the failed run (off `main`, unprotected). After this fix lands on `preview/1.0`, delete `release/1.0` and re-run `promote-branch` to get a correctly locked branch. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: petesramek <2333452+petesramek@users.noreply.github.com>
1 parent 648eadd commit 39f0002

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

.github/workflows/promote-branch.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,12 @@ jobs:
205205
dotnet-version: ${{ env.dotnet-sdk-version }}
206206
- name: 'Create target branch'
207207
if: ${{ needs.workflow-variables.outputs.target-branch-exists == 'false' }}
208+
env:
209+
base-branch: ${{ needs.workflow-variables.outputs.base-branch }}
210+
target-branch: ${{ needs.workflow-variables.outputs.target-branch }}
208211
run: |
209-
git config user.name "$(git log -n 1 --pretty=format:%an)"
210-
git config user.email "$(git log -n 1 --pretty=format:%ae)"
211212
git fetch origin
212-
git switch ${{ needs.workflow-variables.outputs.base-branch }}
213-
git checkout -b ${{ needs.workflow-variables.outputs.target-branch }} origin/${{ needs.workflow-variables.outputs.target-branch }} || git checkout -b ${{ needs.workflow-variables.outputs.target-branch }}
214-
git push --set-upstream origin ${{ needs.workflow-variables.outputs.target-branch }}
213+
git push origin origin/${{ env.base-branch }}:refs/heads/${{ env.target-branch }}
215214
- name: 'Lock target branch'
216215
if: ${{ needs.workflow-variables.outputs.target-branch-exists == 'false' }}
217216
uses: './.github/actions/github/branch-protection/lock'

0 commit comments

Comments
 (0)