From d9d7473256c29d5286327ecba33379bdff793d3b Mon Sep 17 00:00:00 2001 From: Stephen Davies Date: Mon, 16 Oct 2023 12:52:26 +1100 Subject: [PATCH 1/4] Fix truncating branch name not working --- buildprocess/ci-deploy.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildprocess/ci-deploy.sh b/buildprocess/ci-deploy.sh index d878ab4b7a3..22d951cad0a 100644 --- a/buildprocess/ci-deploy.sh +++ b/buildprocess/ci-deploy.sh @@ -10,7 +10,7 @@ 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:40}" | sed -e 's/./\L&/g' -e 's/[^-a-z0-9]/-/g') 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} From 67e87b6f649bc8264946ce2091a6e0c7fd17bcb1 Mon Sep 17 00:00:00 2001 From: Stephen Davies Date: Mon, 16 Oct 2023 14:48:12 +1100 Subject: [PATCH 2/4] Change branch name substring length to 32 as 40 character branch names still have problems --- buildprocess/ci-cleanup.js | 2 +- buildprocess/ci-deploy.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/buildprocess/ci-cleanup.js b/buildprocess/ci-cleanup.js index be06458c747..0fd6099c280 100644 --- a/buildprocess/ci-cleanup.js +++ b/buildprocess/ci-cleanup.js @@ -51,7 +51,7 @@ function makeSafeName(name) { return name .toLowerCase() .replace(/[^-a-z0-9]/g, "-") - .substring(0, 40); + .substring(0, 32); } function createIngress(branches) { diff --git a/buildprocess/ci-deploy.sh b/buildprocess/ci-deploy.sh index 22d951cad0a..b2c217782ba 100644 --- a/buildprocess/ci-deploy.sh +++ b/buildprocess/ci-deploy.sh @@ -10,7 +10,7 @@ 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 -e 's/./\L&/g' -e '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') 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} From 76b2a0b7831898c835af68280f849a6a442cd2c4 Mon Sep 17 00:00:00 2001 From: Stephen Davies Date: Mon, 16 Oct 2023 15:17:14 +1100 Subject: [PATCH 3/4] Remove trailing dashes --- buildprocess/ci-cleanup.js | 3 ++- buildprocess/ci-deploy.sh | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/buildprocess/ci-cleanup.js b/buildprocess/ci-cleanup.js index 0fd6099c280..071c11cf2df 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, 32); + .substring(0, 32) + .replace(/-*$/, ""); } function createIngress(branches) { diff --git a/buildprocess/ci-deploy.sh b/buildprocess/ci-deploy.sh index b2c217782ba..c356eebc2d4 100644 --- a/buildprocess/ci-deploy.sh +++ b/buildprocess/ci-deploy.sh @@ -10,7 +10,7 @@ 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:32}" | sed -e 's/./\L&/g' -e '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/-*$//') 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} From c5fd9b7911e81e6354b296f69204ee5599c806cc Mon Sep 17 00:00:00 2001 From: Stephen Davies Date: Mon, 16 Oct 2023 16:33:57 +1100 Subject: [PATCH 4/4] Fix CI links for unsafe branch names --- buildprocess/ci-cleanup.js | 2 +- buildprocess/ci-deploy.sh | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/buildprocess/ci-cleanup.js b/buildprocess/ci-cleanup.js index 071c11cf2df..325a265b1ac 100644 --- a/buildprocess/ci-cleanup.js +++ b/buildprocess/ci-cleanup.js @@ -74,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 c356eebc2d4..06ff60bc1b0 100644 --- a/buildprocess/ci-deploy.sh +++ b/buildprocess/ci-deploy.sh @@ -12,6 +12,8 @@ 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: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} # Install some tools we need from npm