Skip to content

Commit

Permalink
add scripts/version.sh
Browse files Browse the repository at this point in the history
Signed-off-by: andy.lee <[email protected]>
  • Loading branch information
a110605 committed Jan 6, 2025
1 parent 0171f70 commit a6f2301
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions scripts/version
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit a6f2301

Please sign in to comment.