@@ -95,10 +95,7 @@ function have_gpg_key {
95
95
96
96
function parse_version {
97
97
# Arguments:
98
- # $1 - Path to the top level Consul K8s source
99
- # $2 - boolean value for whether the release version should be parsed from the source
100
- # $3 - boolean whether to use GIT_DESCRIBE and GIT_COMMIT environment variables
101
- # $4 - boolean whether to omit the version part of the version string. (optional)
98
+ # $1 - Path to the top level Consul K8s source. Defaults to current directory.
102
99
#
103
100
# Return:
104
101
# 0 - success (will write the version to stdout)
@@ -108,70 +105,34 @@ function parse_version {
108
105
# If the GOTAGS environment variable is present then it is used to determine which
109
106
# version file to use for parsing.
110
107
111
- local vfile=" ${1} /version/version.go "
108
+ local vfile=" ${1:- . } /version/VERSION "
112
109
113
110
# ensure the version file exists
114
111
if ! test -f " ${vfile} " ; then
115
112
err " Error - File not found: ${vfile} "
116
113
return 1
117
114
fi
118
115
119
- local include_release=" $2 "
120
- local use_git_env=" $3 "
121
- local omit_version=" $4 "
122
-
123
116
local git_version=" "
124
117
local git_commit=" "
125
118
126
- if test -z " ${include_release} " ; then
127
- include_release=true
128
- fi
129
-
130
- if test -z " ${use_git_env} " ; then
131
- use_git_env=true
132
- fi
133
-
134
- if is_set " ${use_git_env} " ; then
135
- git_version=" ${GIT_DESCRIBE} "
136
- git_commit=" ${GIT_COMMIT} "
137
- fi
138
-
139
119
# Get the main version out of the source file
140
- version_main=$( awk ' $1 == "Version" && $2 == "=" { gsub(/"/, "", $3); print $3 }' < ${vfile} )
141
- release_main=$( awk ' $1 == "VersionPrerelease" && $2 == "=" { gsub(/"/, "", $3); print $3 }' < ${vfile} )
142
-
143
- # try to determine the version if we have build tags
144
- for tag in " $GOTAGS " ; do
145
- for vfile in $( find " ${1} /version" -name " version_*.go" 2> /dev/null | sort) ; do
146
- if grep -q " // +build $tag " " ${vfile} " ; then
147
- version_main=$( awk ' $1 == "Version" && $2 == "=" { gsub(/"/, "", $3); print $3 }' < ${vfile} )
148
- release_main=$( awk ' $1 == "VersionPrerelease" && $2 == "=" { gsub(/"/, "", $3); print $3 }' < ${vfile} )
149
- fi
150
- done
151
- done
120
+ version_main=$( cat ${vfile} | awk ' { split($0, arr, "-"); print arr[1]; }' )
121
+ release_main=$( cat ${vfile} | awk ' { split($0, arr, "-"); print arr[2]; }' )
152
122
153
123
local version=" ${version_main} "
154
124
# override the version from source with the value of the GIT_DESCRIBE env var if present
155
125
if test -n " ${git_version} " ; then
156
126
version=" ${git_version} "
157
127
fi
158
128
159
- local rel_ver=" "
160
- if is_set " ${include_release} " ; then
161
- # Default to pre-release from the source
162
- rel_ver=" ${release_main} "
163
-
164
- # When no GIT_DESCRIBE env var is present and no release is in the source then we
165
- # are definitely in dev mode
166
- if test -z " ${git_version} " -a -z " ${rel_ver} " && is_set " ${use_git_env} " ; then
167
- rel_ver=" dev"
168
- fi
129
+ # Default to pre-release from the source
130
+ local rel_ver=" ${release_main} "
169
131
170
- # Add the release to the version
171
- if test -n " ${rel_ver} " -a -n " ${git_commit} " ; then
172
- rel_ver=" ${rel_ver} (${git_commit} )"
173
- fi
174
- fi
132
+ # Add the release to the version
133
+ if test -n " ${rel_ver} " -a -n " ${git_commit} " ; then
134
+ rel_ver=" ${rel_ver} (${git_commit} )"
135
+ fi
175
136
176
137
if test -n " ${rel_ver} " ; then
177
138
if is_set " ${omit_version} " ; then
@@ -191,23 +152,18 @@ function parse_version {
191
152
function get_version {
192
153
# Arguments:
193
154
# $1 - Path to the top level Consul K8s source
194
- # $2 - Whether the release version should be parsed from source (optional)
195
- # $3 - Whether to use GIT_DESCRIBE and GIT_COMMIT environment variables
196
155
#
197
156
# Returns:
198
157
# 0 - success (the version is also echoed to stdout)
199
158
# 1 - error
200
159
#
201
160
# Notes:
202
- # If a VERSION environment variable is present it will override any parsing of the version from the source
203
- # In addition to processing the main version.go, version_*.go files will be processed if they have
204
- # a Go build tag that matches the one in the GOTAGS environment variable. This tag processing is
205
- # primitive though and will not match complex build tags in the files with negation etc.
161
+ # If a VERSION environment variable is present it will override any parsing of the version from the source.
206
162
207
163
local vers=" $VERSION "
208
164
if test -z " $vers " ; then
209
165
# parse the OSS version from version.go
210
- vers=" $( parse_version ${1} ${2} ${3} ) "
166
+ vers=" $( parse_version ${1} ) "
211
167
fi
212
168
213
169
if test -z " $vers " ; then
@@ -574,7 +530,7 @@ function update_version {
574
530
# * - error
575
531
576
532
if ! test -f " $1 " ; then
577
- err " ERROR: '$1 ' is not a regular file. update_version must be called with the path to a go version file"
533
+ err " ERROR: '$1 ' is not a regular file. update_version must be called with the path to a version file"
578
534
return 1
579
535
fi
580
536
@@ -586,8 +542,11 @@ function update_version {
586
542
local vfile=" $1 "
587
543
local version=" $2 "
588
544
local prerelease=" $3 "
545
+ if ! test -z " $prerelease " ; then
546
+ version=" ${version} -${prerelease} "
547
+ fi
589
548
590
- sed_i ${SED_EXT} -e " s/(Version[[:space:]]*=[[:space:]]*) \" [^ \" ]* \" /\1 \" ${version} \" /g " -e " s/(VersionPrerelease[[:space:]]*=[[:space:]]*) \" [^ \" ]* \" /\1 \" ${prerelease} \" /g " " ${vfile} "
549
+ echo -n " ${version} " > " ${vfile} "
591
550
return $?
592
551
}
593
552
@@ -710,8 +669,8 @@ function set_version {
710
669
local consul_vers=" $6 "
711
670
local consul_dataplane_vers=" $8 "
712
671
713
- status_stage " ==> Updating version/version.go with version info : ${vers} " $4 " "
714
- if ! update_version " ${sdir} /version/version.go " " ${vers} " " $4 " ; then
672
+ status_stage " ==> Updating version/VERSION : ${vers} " $4 " "
673
+ if ! update_version " ${sdir} /version/VERSION " " ${vers} " " $4 " ; then
715
674
return 1
716
675
fi
717
676
0 commit comments