Support CI for matching branches on forks

Currently, people with push access to the main Riot repos can push matching
branch names to Riot and the SDKs, and CI will test all the branches together.
This change allows contributors to access the same ability when submitting
several matching PRs from their fork of each repo.

Part of https://github.com/vector-im/riot-web/issues/9041
This commit is contained in:
J. Ryan Stinnett 2019-03-19 16:41:28 +00:00
parent 9735c332ff
commit f5c28a19e1

View file

@ -6,7 +6,7 @@
# the branch the current checkout is on, use that branch. Otherwise, # the branch the current checkout is on, use that branch. Otherwise,
# use develop. # use develop.
set -e set -ex
GIT_CLONE_ARGS=("$@") GIT_CLONE_ARGS=("$@")
[ -z "$defbranch" ] && defbranch="develop" [ -z "$defbranch" ] && defbranch="develop"
@ -33,27 +33,39 @@ function clone() {
} }
function dodep() { function dodep() {
org=$1 deforg=$1
repo=$2 defrepo=$2
rm -rf $repo rm -rf $defrepo
# 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.
# Try the target branch of the push or PR. # Try the target branch of the push or PR.
# Use the default branch as the last resort. # Use the default branch as the last resort.
if [[ "$BUILDKITE" == true ]]; then if [[ "$BUILDKITE" == true ]]; then
clone $org $repo $BUILDKITE_BRANCH || # If BUILDKITE_BRANCH is set, it will contain either:
clone $org $repo $BUILDKITE_PULL_REQUEST_BASE_BRANCH || # * "branch" when the author's branch and target branch are in the same repo
clone $org $repo $defbranch || # * "author:branch" when the author's branch is in their fork
# We can split on `:` into an array to check.
BUILDKITE_BRANCH_ARRAY=(${BUILDKITE_BRANCH//:/ })
if [[ "${#BUILDKITE_BRANCH_ARRAY[@]}" == "2" ]]; then
prAuthor=${BUILDKITE_BRANCH_ARRAY[0]}
prBranch=${BUILDKITE_BRANCH_ARRAY[1]}
else
prAuthor=$deforg
prBranch=$BUILDKITE_BRANCH
fi
clone $prAuthor $defrepo $prBranch ||
clone $deforg $defrepo $BUILDKITE_PULL_REQUEST_BASE_BRANCH ||
clone $deforg $defrepo $defbranch ||
return $? return $?
else else
clone $org $repo $ghprbSourceBranch || clone $deforg $defrepo $ghprbSourceBranch ||
clone $org $repo $GIT_BRANCH || clone $deforg $defrepo $GIT_BRANCH ||
clone $org $repo `git rev-parse --abbrev-ref HEAD` || clone $deforg $defrepo `git rev-parse --abbrev-ref HEAD` ||
clone $org $repo $defbranch || clone $deforg $defrepo $defbranch ||
return $? return $?
fi fi
echo "$repo set to branch "`git -C "$repo" rev-parse --abbrev-ref HEAD` echo "$defrepo set to branch "`git -C "$defrepo" rev-parse --abbrev-ref HEAD`
} }
############################## ##############################