Branch matching support for forked repository on GitHub actions

This commit is contained in:
Germain Souquet 2021-06-21 16:18:13 +01:00
parent 2d9e97a3e1
commit ca5f8f97bb

View file

@ -36,13 +36,19 @@ else
head=$(curl $apiEndpoint | jq -r '.head.label')
fi
# If head is set, it will contain either:
# If head is set, it will contain on BuilKite either:
# * "branch" when the author's branch and target branch are in the same repo
# * "fork:branch" when the author's branch is in their fork or if this is a Netlify build
# We can split on `:` into an array to check.
# For GitHub Actions we need to inspect GITHUB_REPOSITORY and GITHUB_ACTOR
# to determine whether the branch is from a fork or not
BRANCH_ARRAY=(${head//:/ })
if [[ "${#BRANCH_ARRAY[@]}" == "1" ]]; then
clone $deforg $defrepo $head
if [[ "$GITHUB_REPOSITORY" = "$deforg/$defrepo" ]]; then
clone $deforg $defrepo $head
else
clone $GITHUB_ACTOR $defrepo $head
fi
elif [[ "${#BRANCH_ARRAY[@]}" == "2" ]]; then
clone ${BRANCH_ARRAY[0]} $defrepo ${BRANCH_ARRAY[1]}
fi