From 375f74867059bdbe19855b6ca6ebb8c1536fa4c1 Mon Sep 17 00:00:00 2001 From: Iain Sproat <68657+iainsproat@users.noreply.github.com> Date: Wed, 8 Feb 2023 19:40:07 +0000 Subject: [PATCH] fix(circleci): include get_version.sh (#3) --- .circleci/get_version.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 .circleci/get_version.sh diff --git a/.circleci/get_version.sh b/.circleci/get_version.sh new file mode 100755 index 0000000..1542159 --- /dev/null +++ b/.circleci/get_version.sh @@ -0,0 +1,23 @@ +#!/bin/bash +set -eo pipefail + +if [[ "${CIRCLE_TAG}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "${CIRCLE_TAG}" + exit 0 +fi + +# shellcheck disable=SC2068,SC2046 +LAST_RELEASE="$(git describe --always --tags $(git rev-list --tags) | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1)" +NEXT_RELEASE="$(echo "${LAST_RELEASE}" | awk -F. -v OFS=. '{$NF += 1 ; print}')" +if [[ "${CIRCLE_BRANCH}" == "main" ]]; then + echo "${NEXT_RELEASE}-alpha.${CIRCLE_BUILD_NUM}" + exit 0 +fi + + # docker has a 128 character tag limit, so ensuring the branch name will be short enough + # helm uses semver 2, only valid characters are a-zA-Z0-9 and hyphen '-' +# shellcheck disable=SC2034 +BRANCH_NAME_TRUNCATED="$(echo "${CIRCLE_BRANCH}" | cut -c -50 | sed 's/[^a-zA-Z0-9.-]/-/g')" + +echo "${NEXT_RELEASE}-branch.${BRANCH_NAME_TRUNCATED}.${CIRCLE_BUILD_NUM}" +exit 0