@@ -17,64 +17,8 @@ set -o errexit
17
17
set -o nounset
18
18
set -o pipefail
19
19
20
- GIT_COMMIT=" $( git describe --always --dirty --abbrev=14) "
20
+ # Override by passing in VERSION
21
+ VERSION=${VERSION:- $(git tag --sort taggerdate | tail -n 1)}
21
22
22
- if git_status=$( git status --porcelain 2> /dev/null) && [[ -z ${git_status} ]]; then
23
- GIT_TREE_STATE=" clean"
24
- else
25
- GIT_TREE_STATE=" dirty"
26
- fi
27
-
28
- # mostly stolen from k8s.io/hack/lib/version.sh
29
- # Use git describe to find the version based on tags.
30
- if GIT_VERSION=$( git describe --tags --abbrev=14 2> /dev/null) ; then
31
- # This translates the "git describe" to an actual semver.org
32
- # compatible semantic version that looks something like this:
33
- # v1.1.0-alpha.0.6+84c76d1142ea4d
34
- #
35
- # TODO: We continue calling this "git version" because so many
36
- # downstream consumers are expecting it there.
37
- DASHES_IN_VERSION=$( echo " ${GIT_VERSION} " | sed " s/[^-]//g" )
38
- if [[ " ${DASHES_IN_VERSION} " == " ---" ]] ; then
39
- # We have distance to subversion (v1.1.0-subversion-1-gCommitHash)
40
- GIT_VERSION=$( echo " ${GIT_VERSION} " | sed " s/-\([0-9]\{1,\}\)-g\([0-9a-f]\{14\}\)$/.\1\-\2/" )
41
- elif [[ " ${DASHES_IN_VERSION} " == " --" ]] ; then
42
- # We have distance to base tag (v1.1.0-1-gCommitHash)
43
- GIT_VERSION=$( echo " ${GIT_VERSION} " | sed " s/-g\([0-9a-f]\{14\}\)$/-\1/" )
44
- fi
45
- if [[ " ${GIT_TREE_STATE} " == " dirty" ]]; then
46
- # git describe --dirty only considers changes to existing files, but
47
- # that is problematic since new untracked .go files affect the build,
48
- # so use our idea of "dirty" from git status instead.
49
- GIT_VERSION+=" -dirty"
50
- fi
51
-
52
-
53
- # Try to match the "git describe" output to a regex to try to extract
54
- # the "major" and "minor" versions and whether this is the exact tagged
55
- # version or whether the tree is between two tagged versions.
56
- if [[ " ${GIT_VERSION} " =~ ^v([0-9]+)\. ([0-9]+)(\. [0-9]+)? ([-].* )? ([+].* )? $ ]]; then
57
- GIT_MAJOR=${BASH_REMATCH[1]}
58
- GIT_MINOR=${BASH_REMATCH[2]}
59
- fi
60
-
61
- # If GIT_VERSION is not a valid Semantic Version, then refuse to build.
62
- if ! [[ " ${GIT_VERSION} " =~ ^v([0-9]+)\. ([0-9]+)(\. [0-9]+)? (-[0-9A-Za-z.-]+)? (\+ [0-9A-Za-z.-]+)? $ ]]; then
63
- GIT_VERSION=v0.0.0+${GIT_VERSION}
64
- GIT_MAJOR=0
65
- GIT_MINOR=0
66
- fi
67
- else
68
- GIT_VERSION=" UNKNOWN_GIT_VERSION"
69
- GIT_MAJOR=" UNKNOWN_GIT_MAJOR_VERSION"
70
- GIT_MINOR=" UNKNOWN_GIT_MINOR_VERSION"
71
- fi
72
-
73
- if GIT_RELEASE_TAG=$( git describe --abbrev=0 --tags 2> /dev/null) ; then
74
- GIT_RELEASE_COMMIT=$( git rev-list -n 1 ${GIT_RELEASE_TAG} | head -c 14)
75
- else
76
- GIT_RELEASE_TAG=" UNKNOWN_RELEASE"
77
- GIT_RELEASE_COMMIT=" UNKNOWN_RELEAE_COMMIT"
78
- fi
79
-
80
- GIT_BRANCH=$( git branch | grep \* | cut -d ' ' -f2)
23
+ # Override by passing in SHORT
24
+ SHORT=${SHORT:- $(git rev-parse --short " ${VERSION} " )}
0 commit comments