8000 gha: rework git remote handling for checkout, commit, push · sec-js/st2@6bbaaa3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6bbaaa3

Browse files
committed
gha: rework git remote handling for checkout, commit, push
It needs to handle new PR and exiting PR. The existing PR can be from a branch in a fork or in this repo.
1 parent 9ed0c12 commit 6bbaaa3

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

.github/workflows/lockfiles.yaml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,17 @@ jobs:
450450
git config --local committer.email "${{ env.BOT_GHA_EMAIL }}"
451451
452452
- name: Create local branch for PR
453+
env:
454+
PR_IS_CROSS_REPOSITORY: ${{ fromJSON(needs.pr.outputs.JSON).isCrossRepository }}
455+
PR_REMOTE: "origin"
456+
PR_REF: ${{ needs.pr.outputs.PR_REF }}
453457
run: |
454-
git checkout -b "${{ needs.pr.outputs.PR_REF }}" FETCH_HEAD
458+
if [[ "${PR_IS_CROSS_REPOSITORY}" == "true" ]]; then
459+
PR_REMOTE="fork"
460+
git remote add "${PR_REMOTE}" "${GITHUB_SERVER_URL}/${{ needs.pr.outputs.PR_REPO }}"
461+
fi
462+
echo "PR_REMOTE=${PR_REMOTE}" >> "${GITHUB_ENV}"
463+
git checkout -b "${PR_REF}" --track "${PR_REMOTE}/${PR_REF}"
455464
456465
- name: Download lockfiles and lockfile diff files
457466
uses: actions/download-artifact@v5
@@ -540,9 +549,7 @@ jobs:
540549
# git push --force is for workflow re-runs, but only for new PRs.
541550
run: |
542551
git commit -F "${COMMIT_MSG}"
543-
git push${{ inputs.pr == 'new' && ' --force' || '' }} \
544-
"${GITHUB_SERVER_URL}/${{ needs.pr.outputs.PR_REPO }}" \
545-
"HEAD:${{ needs.pr.outputs.PR_REF }}"
552+
git push${{ inputs.pr == 'new' && ' --force' || '' }} "${PR_REMOTE}" "${{ needs.pr.outputs.PR_REF }}"
546553
547554
- name: Create new PR
548555
if: inputs.pr == 'new' && fromJSON(needs.pr.outputs.JSON).number == 'new' && env.CHANGED == 'true'

0 commit comments

Comments
 (0)
0