From e8a3bfc4b64fef2d100564d85f0fee9ad7fdedf5 Mon Sep 17 00:00:00 2001 From: Alfredo Deza Date: Fri, 9 Sep 2016 14:54:12 -0400 Subject: [PATCH] scripts: create a branch filtering for slashes Signed-off-by: Alfredo Deza --- scripts/build_utils.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/scripts/build_utils.sh b/scripts/build_utils.sh index 147a9af8..75108391 100644 --- a/scripts/build_utils.sh +++ b/scripts/build_utils.sh @@ -5,6 +5,24 @@ set -ex TEMPVENV=$(mktemp -td venv.XXXXXXXXXX) VENV="$TEMPVENV/bin" +branch_slash_filter() { + # The build system relies on an HTTP binary store that uses branches/refs + # as URL parts. A literal extra slash in the branch name is considered + # illegal, so this function performs a check *and* prunes the common + # `origin/branch-name` scenario (which is OK to have). + RAW_BRANCH=$1 + branch_slashes=$(grep -o "/" <<< ${RAW_BRANCH} | wc -l) + FILTERED_BRANCH=`echo ${RAW_BRANCH} | rev | cut -d '/' -f 1 | rev` + + # Prevent building branches that have slashes in their name + if [ "$((branch_slashes))" -gt 1 ] ; then + echo "Will refuse to build branch: ${RAW_BRANCH}" + echo "Invalid branch name (contains slashes): ${FILTERED_BRANCH}" + exit 1 + fi + echo $FILTERED_BRANCH +} + install_python_packages () { # Use this function to create a virtualenv and install # python packages. Pass a list of package names. -- 2.39.5