Skip to content

Commit

Permalink
checkout: allow an option PR number to be passed
Browse files Browse the repository at this point in the history
If an PR explicit PR number is passed, check out that PR, otherwise
check out GITHUB_REF. This enables pull_request_target actions to
provide an explicit target.

Signed-off-by: Gerwin Klein <[email protected]>
  • Loading branch information
lsf37 committed Jul 9, 2024
1 parent d2bd03d commit d8faf1b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions scripts/checkout.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@ else
REPO_URL="https://${REPO_PATH}"
fi

echo "Cloning ${REPO_PATH}@${GITHUB_REF}"
# if an explicit PR number is set as INPUT (e.g. for pull_request_target), prefer that
if [ -n "${INPUT_PR_NUM}" ]
then
REF="refs/pull/${INPUT_PR_NUM}/head"
else
REF="${GITHUB_REF}"
fi

echo "Cloning ${REPO_PATH}@${REF}"
git init -q .
git remote add origin ${REPO_URL}
git fetch -q --no-tags --depth ${DEPTH} origin +${GITHUB_REF}:refs/heads/test-revision
git fetch -q --no-tags --depth ${DEPTH} origin +${REF}:refs/heads/test-revision
git checkout -q test-revision

0 comments on commit d8faf1b

Please sign in to comment.