-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
Copy pathget_version.sh
executable file
·46 lines (39 loc) · 1.71 KB
/
get_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
#!/bin/bash
# Copyright 2020 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Outputs the main kops version; as reported in `kops version`.
GITSHA=$(git describe --always 2>/dev/null)
# When we cut a new release we need to increment these accordingly
KOPS_RELEASE_VERSION=$(grep 'KOPS_RELEASE_VERSION\s*=' kops-version.go | awk '{print $3}' | sed -e 's_"__g')
KOPS_CI_VERSION=$(grep 'KOPS_CI_VERSION\s*=' kops-version.go | awk '{print $3}' | sed -e 's_"__g')
if [[ -z "${VERSION}" ]]; then
if [[ -z "${CI}" ]]; then
VERSION=${KOPS_RELEASE_VERSION}
else
VERSION="${KOPS_CI_VERSION}+${GITSHA}"
fi
fi
# If we are CI-building something that is exactly a tag, then we use that as the version.
# This let us do release (candidate) builds from our CI pipeline.
if [[ -n "${CI}" ]]; then
EXACT_TAG=$(git describe --tags --exact-match 2>/dev/null || true)
if [[ -n "${EXACT_TAG}" ]]; then
VERSION="${EXACT_TAG#v}" # Remove the v prefix from the git tag
if [[ "${VERSION}" != "${KOPS_RELEASE_VERSION}" ]]; then
echo "Build was tagged with ${VERSION}, but kops-version.go had version ${KOPS_RELEASE_VERSION}"
exit 1
fi
fi
fi
echo "VERSION ${VERSION}"