forked from kedacore/keda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.sh
executable file
·61 lines (50 loc) · 2.12 KB
/
version.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env bash
###############################################################
# version.sh : #
# This module is used by deployment to generate #
# version information for application to be used #
# in production. #
# warning : #
# This module can not ouput any error or debug msg #
# As the output of this module is used by the build #
# pipeline to name the final docker image. #
# This module should recover from all errors and #
# generate a unique image name each time #
###############################################################
# version module configuration
SUFFIX_SEP=${SUFFIX_SEP:--}
VERSION_SUFFIX=${VERSION_SUFFIX}
# Get current commit id
GIT_COMMIT=$(git rev-parse HEAD)
GIT_COMMIT_SHORT_SHA=$(git rev-parse --short HEAD)
# Buil dtimestamp
BUILD_TIMESTAMP=$(date +%FT%T%z)
# Get current git tag
GIT_TAG=$(git describe --abbrev=0 --tags 2>/dev/null)
# GIT TAGs
if [ -z "${GIT_TAG}" ]; then
GIT_TAG="0.0"
COMMIT_COUNT=$(git rev-list HEAD --count 2>/dev/null)
if [ -z "${COMMIT_COUNT}" ]; then
COMMIT_COUNT=0
fi
else
# Get commit count since last tag
COMMIT_COUNT=$(git rev-list ${GIT_TAG}.. --count 2>/dev/null)
if [ -z "${COMMIT_COUNT}" ]; then
COMMIT_COUNT=0
fi
fi
VERSION="${GIT_TAG}.${COMMIT_COUNT}"
VERSION_SUFFIX="${VERSION_SUFFIX}${SUFFIX_SEP}${GIT_COMMIT_SHORT_SHA}"
# Current Branch
GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
# Check current branch
# Master and release branch is not included in the prefix
if [ "${GIT_BRANCH}" != "master" ] && [ "${GIT_BRANCH}" != "release" ] && [ "${GIT_BRANCH}" != "main" ] && [ -n "${GIT_BRANCH}" ]; then
VERSION_SUFFIX="${VERSION_SUFFIX}${SUFFIX_SEP}${GIT_BRANCH}"
fi
# Full version specifier inluding branch information
VERSION_FULL=${VERSION}${VERSION_SUFFIX}
# Print current version to console. This will be used by build pipeline to decide name the final image
echo "${VERSION_FULL}"