diff --git a/scripts/version b/scripts/version new file mode 100755 index 00000000..d4af4084 --- /dev/null +++ b/scripts/version @@ -0,0 +1,57 @@ +#!/bin/bash +shopt -s extglob + +if [ -n "$(git status --porcelain --untracked-files=no)" ]; then + DIRTY="-dirty" +fi + +COMMIT=$(git rev-parse --short HEAD) +COMMIT_DATE=$(git --no-pager log -1 --format='%ct') +COMMIT_BRANCH=$(git rev-parse --abbrev-ref HEAD | sed -E 's/[^a-zA-Z0-9.-]+/-/g') +GIT_TAG=${CI_BUILD_TAG:-$(git tag -l --contains HEAD | head -n 1)} +LAST_TAG=${GIT_TAG:-'v0.0.0'} + +if [[ -z "$DIRTY" && -n "$GIT_TAG" ]]; then + # human readable version used on rancher dashboard about page + export DASHBOARD_VERSION=$GIT_TAG + # computer readable version + VERSION=$GIT_TAG +else + # human readable version used on rancher dashboard about page + export DASHBOARD_VERSION="${COMMIT_BRANCH} ${COMMIT}" + # computer readable version + VERSION="${COMMIT}${DIRTY}" +fi + +# Chart tag. +if [[ -z "${DIRTY}" && -n "${GIT_TAG}" ]]; then + CHART_VERSION="${GIT_TAG}" +elif [[ "$DIRTY" ]]; then + CHART_VERSION="${LAST_TAG}${DIRTY}.${COMMIT}" +else + CHART_VERSION="${LAST_TAG}-${COMMIT_DATE}.${COMMIT}.${COMMIT_BRANCH}" +fi + +# Drop the v prefix for Chart Version to follow existing pattern. +CHART_VERSION="$(echo ${CHART_VERSION} | sed -E 's/^v//' | sed -e 's/^\(.\{55\}\).*/\1/')" + +# Chart Repo - Target Repo for releases. +case $CHART_VERSION in + *-alpha*) # All alpha tags + CHART_REPO="alpha" ;; + *-rc*) # All rc tags + CHART_REPO="latest" ;; + +([0-9]).+([0-9]).+([0-9])) # All release tags + CHART_REPO="latest" ;; + *) # Anything else - Future use + CHART_REPO="dev" ;; +esac + +if [ -z "$ARCH" ]; then + ARCH=amd64 +fi + +echo "ARCH: $ARCH" +echo "CHART_REPO: $CHART_REPO" +echo "CHART_VERSION: $CHART_VERSION" +echo "VERSION: $VERSION"