diff --git a/buildprocess/ci-cleanup.js b/buildprocess/ci-cleanup.js index be06458c747..325a265b1ac 100644 --- a/buildprocess/ci-cleanup.js +++ b/buildprocess/ci-cleanup.js @@ -51,7 +51,8 @@ function makeSafeName(name) { return name .toLowerCase() .replace(/[^-a-z0-9]/g, "-") - .substring(0, 40); + .substring(0, 32) + .replace(/-*$/, ""); } function createIngress(branches) { @@ -73,7 +74,7 @@ function createIngress(branches) { host: "ci.terria.io", http: { paths: branches.map((branch) => ({ - path: "/" + branch.name + "(/|$)(.*)", + path: "/" + makeSafeName(branch.name) + "(/|$)(.*)", pathType: "ImplementationSpecific", backend: { service: { diff --git a/buildprocess/ci-deploy.sh b/buildprocess/ci-deploy.sh index d878ab4b7a3..06ff60bc1b0 100644 --- a/buildprocess/ci-deploy.sh +++ b/buildprocess/ci-deploy.sh @@ -10,7 +10,9 @@ if [[ $GITHUB_BRANCH =~ ^greenkeeper/ ]]; then fi # A version of the branch name that can be used as a DNS name once we prepend and append some stuff. -SAFE_BRANCH_NAME=$(printf '%s' "${GITHUB_BRANCH,,:0:40}" | sed 's/[^-a-z0-9]/-/g') +SAFE_BRANCH_NAME=$(printf '%s' "${GITHUB_BRANCH:0:32}" | sed -e 's/./\L&/g' -e 's/[^-a-z0-9]/-/g' -e 's/-*$//') + +[[ $SAFE_BRANCH_NAME != $GITHUB_BRANCH ]] && echo "::warning file=buildprocess/ci-deploy.sh::Branch name sanitised to '${SAFE_BRANCH_NAME}' for kubernetes resources. This may work, however using branch names less than 32 characters long with [a-z0-9] and hyphen separators are preferred" gh api /repos/${GITHUB_REPOSITORY}/statuses/${GITHUB_SHA} -f state=pending -f context=deployment -f target_url=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}