Test: Fix ci script to use pr author's fork when looking for source branch (elastic/x-pack-elasticsearch#1548)
Original commit: elastic/x-pack-elasticsearch@faf72043be
This commit is contained in:
parent
f5e86cabaf
commit
404ba010ad
38
dev-tools/ci
38
dev-tools/ci
|
@ -93,16 +93,34 @@ if [ -z ${USE_EXISTING_ES:+x} ]; then
|
||||||
echo "Either define 'USE_EXISTING_ES' or remove the existing 'elasticsearch' sibling."
|
echo "Either define 'USE_EXISTING_ES' or remove the existing 'elasticsearch' sibling."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
BRANCH=${PR_SOURCE_BRANCH:-${GIT_BRANCH#*/}} # GIT_BRANCH starts with the repo, i.e., origin/master
|
|
||||||
BRANCH=${BRANCH:-master} # fall back to CI branch if not testing a PR
|
function pick_clone_target {
|
||||||
echo "Checking if branch '$BRANCH' has elasticsearch sibling..."
|
echo "picking which branch of elasticsearch to clone"
|
||||||
if [[ -z "$(git ls-remote --heads https://github.com/elastic/elasticsearch.git $BRANCH)" ]]; then
|
|
||||||
echo "No sibling branch, using PR target branch"
|
# PR_* are provided by the CI git plugin for pull requests
|
||||||
BRANCH=$PR_TARGET_BRANCH
|
if [[ -n "$PR_AUTHOR" && -n "$PR_SOURCE_BRANCH" ]]; then
|
||||||
fi
|
GH_USER="$PR_AUTHOR"
|
||||||
echo "Checking out Elasticsearch '$BRANCH' branch..."
|
BRANCH="$PR_SOURCE_BRANCH"
|
||||||
git clone -b $BRANCH https://github.com/elastic/elasticsearch.git
|
echo " -> using pull request author $GH_USER and branch $BRANCH"
|
||||||
printf "Checked out Elasticsearch revision: %s\n" "$(git -C elasticsearch rev-parse HEAD)"
|
if [[ -n "$(git ls-remote --heads https://github.com/$GH_USER/elasticsearch.git $BRANCH 2>/dev/null)" ]]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
GH_USER="elastic"
|
||||||
|
# GIT_BRANCH is provided by normal CI runs. It starts with the repo, i.e., origin/master
|
||||||
|
# If we are not in CI, we fall back to the master branch
|
||||||
|
BRANCH="${PR_TARGET_BRANCH:-${GIT_BRANCH#*/}}"
|
||||||
|
BRANCH="${BRANCH:-master}"
|
||||||
|
echo " -> using CI branch $BRANCH from elastic repo"
|
||||||
|
}
|
||||||
|
|
||||||
|
pick_clone_target
|
||||||
|
|
||||||
|
echo " -> checking out '$BRANCH' branch from $GH_USER/elasticsearch..."
|
||||||
|
git clone -b $BRANCH "https://github.com/$GH_USER/elasticsearch.git" --depth=1
|
||||||
|
echo " -> checked out elasticsearch revision: $(git -C elasticsearch rev-parse HEAD)"
|
||||||
|
echo
|
||||||
|
|
||||||
else
|
else
|
||||||
if [ -d "./elasticsearch" ]; then
|
if [ -d "./elasticsearch" ]; then
|
||||||
echo "Using existing 'elasticsearch' checkout"
|
echo "Using existing 'elasticsearch' checkout"
|
||||||
|
|
Loading…
Reference in New Issue