Merge pull request #6236 from matrix-org/gsouquet/bk-branch-matching
Fix branch matching for Buildkite
This commit is contained in:
commit
cbfab29a5c
1 changed files with 21 additions and 14 deletions
|
@ -24,19 +24,19 @@ clone() {
|
||||||
# Try the PR author's branch in case it exists on the deps as well.
|
# Try the PR author's branch in case it exists on the deps as well.
|
||||||
# First we check if GITHUB_HEAD_REF is defined,
|
# First we check if GITHUB_HEAD_REF is defined,
|
||||||
# Then we check if BUILDKITE_BRANCH is defined,
|
# Then we check if BUILDKITE_BRANCH is defined,
|
||||||
# if it isn't we can assume this is a Netlify build
|
# if they aren't we can assume this is a Netlify build
|
||||||
if [ -n ${GITHUB_HEAD_REF+x} ]; then
|
if [ -n "$GITHUB_HEAD_REF" ]; then
|
||||||
head=$GITHUB_HEAD_REF
|
head=$GITHUB_HEAD_REF
|
||||||
elif [ -n ${BUILDKITE_BRANCH+x} ]; then
|
elif [ -n "$BUILDKITE_BRANCH" ]; then
|
||||||
head=$BUILDKITE_BRANCH
|
head=$BUILDKITE_BRANCH
|
||||||
else
|
else
|
||||||
# Netlify doesn't give us info about the fork so we have to get it from GitHub API
|
# Netlify doesn't give us info about the fork so we have to get it from GitHub API
|
||||||
apiEndpoint="https://api.github.com/repos/matrix-org/matrix-react-sdk/pulls/"
|
apiEndpoint="https://api.github.com/repos/matrix-org/matrix-react-sdk/pulls/"
|
||||||
apiEndpoint+=$REVIEW_ID
|
apiEndpoint+=$REVIEW_ID
|
||||||
head=$(curl $apiEndpoint | jq -r '.head.label')
|
head=$(curl $apiEndpoint | jq -r '.head.label')
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If head is set, it will contain on BuilKite either:
|
# If head is set, it will contain on Buildkite either:
|
||||||
# * "branch" when the author's branch and target branch are in the same repo
|
# * "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
|
# * "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.
|
# We can split on `:` into an array to check.
|
||||||
|
@ -44,19 +44,26 @@ fi
|
||||||
# to determine whether the branch is from a fork or not
|
# to determine whether the branch is from a fork or not
|
||||||
BRANCH_ARRAY=(${head//:/ })
|
BRANCH_ARRAY=(${head//:/ })
|
||||||
if [[ "${#BRANCH_ARRAY[@]}" == "1" ]]; then
|
if [[ "${#BRANCH_ARRAY[@]}" == "1" ]]; then
|
||||||
if [[ "$GITHUB_REPOSITORY" = "$deforg/$defrepo" ]]; then
|
|
||||||
clone $deforg $defrepo $head
|
if [ -n "$GITHUB_HEAD_REF" ]; then
|
||||||
|
if [[ "$GITHUB_REPOSITORY" == "$deforg"* ]]; then
|
||||||
|
clone $deforg $defrepo $GITHUB_HEAD_REF
|
||||||
|
else
|
||||||
|
REPO_ARRAY=(${GITHUB_REPOSITORY//\// })
|
||||||
|
clone $REPO_ARRAY[0] $defrepo $GITHUB_HEAD_REF
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
clone $GITHUB_ACTOR $defrepo $head
|
clone $deforg $defrepo $BUILDKITE_BRANCH
|
||||||
fi
|
fi
|
||||||
|
|
||||||
elif [[ "${#BRANCH_ARRAY[@]}" == "2" ]]; then
|
elif [[ "${#BRANCH_ARRAY[@]}" == "2" ]]; then
|
||||||
clone ${BRANCH_ARRAY[0]} $defrepo ${BRANCH_ARRAY[1]}
|
clone ${BRANCH_ARRAY[0]} $defrepo ${BRANCH_ARRAY[1]}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Try the target branch of the push or PR.
|
# Try the target branch of the push or PR.
|
||||||
if [ -n ${GITHUB_BASE_REF+x} ]; then
|
if [ -n $GITHUB_BASE_REF ]; then
|
||||||
clone $deforg $defrepo $GITHUB_BASE_REF
|
clone $deforg $defrepo $GITHUB_BASE_REF
|
||||||
elif [ -n ${BUILDKITE_PULL_REQUEST_BASE_BRANCH+x} ]; then
|
elif [ -n $BUILDKITE_PULL_REQUEST_BASE_BRANCH ]; then
|
||||||
clone $deforg $defrepo $BUILDKITE_PULL_REQUEST_BASE_BRANCH
|
clone $deforg $defrepo $BUILDKITE_PULL_REQUEST_BASE_BRANCH
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue