Skip to content

Commit e44b7bc

Browse files
committed
fix: ensure we can checkout PR branches named identically to the base branch
Similar to the issue reported in laminas/laminas-ci-matrix-action#29, we need to ensure that when we fetch the `$GITHUB_REF`, we fetch it into a branch that is named differently than the base branch to avoid collisions and errors. This patch accomplishes it by adding a `pull/` prefix to the pull request branch name. Signed-off-by: Matthew Weier O'Phinney <[email protected]>
1 parent 9d8a5a0 commit e44b7bc

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

entrypoint.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@ function help {
1818
function checkout {
1919
local REF=
2020
local LOCAL_BRANCH=
21+
local LOCAL_BRANCH_NAME=
2122

2223
if [[ ! $GITHUB_EVENT_NAME || ! $GITHUB_REPOSITORY || ! $GITHUB_REF ]];then
2324
return
2425
fi
2526

27+
LOCAL_BRANCH_NAME=$GITHUB_HEAD_REF
28+
2629
case $GITHUB_EVENT_NAME in
2730
pull_request)
2831
REF=$GITHUB_REF
@@ -33,6 +36,8 @@ function checkout {
3336
echo "Missing head or base ref env variables; aborting"
3437
exit 1
3538
fi
39+
40+
LOCAL_BRANCH_NAME=pull/${LOCAL_BRANCH_NAME}
3641
;;
3742
push)
3843
REF=${GITHUB_REF/refs\/heads\//}
@@ -66,9 +71,9 @@ function checkout {
6671
echo "Checking out branch ${BASE_BRANCH}"
6772
git checkout ${BASE_BRANCH}
6873
echo "Fetching ref ${REF}"
69-
git fetch origin $REF:${GITHUB_HEAD_REF}
70-
echo "Checking out to ${GITHUB_HEAD_REF}"
71-
git checkout $GITHUB_HEAD_REF
74+
git fetch origin "${REF}":"${LOCAL_BRANCH_NAME}"
75+
echo "Checking out target ref to ${LOCAL_BRANCH_NAME}"
76+
git checkout "${LOCAL_BRANCH_NAME}"
7277
fi
7378
}
7479

0 commit comments

Comments
 (0)