Skip to content

Commit 2047a73

Browse files
author
OpenShift Bot
authored
Merge pull request #11506 from smarterclayton/actually_use_correct_version_metadata
Merged by openshift-bot
2 parents 6a6aef6 + c3de375 commit 2047a73

File tree

4 files changed

+15
-43
lines changed

4 files changed

+15
-43
lines changed

hack/build-images.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ if [[ "${OS_RELEASE:-}" == "n" ]]; then
1515
imagedir="${OS_OUTPUT_BINPATH}/linux/amd64"
1616
# identical to build-cross.sh
1717
os::build::os_version_vars
18-
OS_RELEASE_COMMIT="${OS_GIT_SHORT_VERSION}"
18+
OS_RELEASE_COMMIT="${OS_GIT_VERSION}"
1919
OS_BUILD_PLATFORMS=("${OS_IMAGE_COMPILE_PLATFORMS[@]-}")
2020

2121
echo "Building images from source ${OS_RELEASE_COMMIT}:"

hack/common.sh

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -479,11 +479,7 @@ function os::build::place_bins() {
479479
readonly -f os::build::place_bins
480480

481481
function os::build::archive_name() {
482-
if [[ "${OS_GIT_VERSION}" == *+${OS_GIT_COMMIT} ]]; then
483-
echo "${OS_RELEASE_ARCHIVE}-${OS_GIT_VERSION}-$1"
484-
return
485-
fi
486-
echo "${OS_RELEASE_ARCHIVE}-${OS_GIT_VERSION}-${OS_GIT_COMMIT}-$1"
482+
echo "${OS_RELEASE_ARCHIVE}-${OS_GIT_VERSION}-$1"
487483
}
488484
readonly -f os::build::archive_name
489485

@@ -672,10 +668,8 @@ function os::build::os_version_vars() {
672668
OS_GIT_TREE_STATE="dirty"
673669
fi
674670
fi
675-
OS_GIT_SHORT_VERSION="${OS_GIT_COMMIT}"
676-
677671
# Use git describe to find the version based on annotated tags.
678-
if [[ -n ${OS_GIT_VERSION-} ]] || OS_GIT_VERSION=$("${git[@]}" describe --tags --abbrev=7 "${OS_GIT_COMMIT}^{commit}" 2>/dev/null); then
672+
if [[ -n ${OS_GIT_VERSION-} ]] || OS_GIT_VERSION=$("${git[@]}" describe --long --tags --abbrev=7 "${OS_GIT_COMMIT}^{commit}" 2>/dev/null); then
679673
# Try to match the "git describe" output to a regex to try to extract
680674
# the "major" and "minor" versions and whether this is the exact tagged
681675
# version or whether the tree is between two tagged versions.
@@ -689,16 +683,14 @@ function os::build::os_version_vars() {
689683

690684
# This translates the "git describe" to an actual semver.org
691685
# compatible semantic version that looks something like this:
692-
# v1.1.0-alpha.0.6+84c76d1142ea4d
693-
#
694-
# TODO: We continue calling this "git version" because so many
695-
# downstream consumers are expecting it there.
696-
OS_GIT_VERSION=$(echo "${OS_GIT_VERSION}" | sed "s/-\([0-9]\{1,\}\)-g\([0-9a-f]\{7,40\}\)$/\+\2/")
686+
# v1.1.0-alpha.0.6+84c76d1-345
687+
OS_GIT_VERSION=$(echo "${OS_GIT_VERSION}" | sed "s/-\([0-9]\{1,\}\)-g\([0-9a-f]\{7,40\}\)$/\+\2-\1/")
688+
# If this is an exact tag, remove the last segment.
689+
OS_GIT_VERSION=$(echo "${OS_GIT_VERSION}" | sed "s/-0$//")
697690
if [[ "${OS_GIT_TREE_STATE}" == "dirty" ]]; then
698691
# git describe --dirty only considers changes to existing files, but
699692
# that is problematic since new untracked .go files affect the build,
700693
# so use our idea of "dirty" from git status instead.
701-
OS_GIT_SHORT_VERSION+="-dirty"
702694
OS_GIT_VERSION+="-dirty"
703695
fi
704696
fi

pkg/version/version.go

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package version
22

33
import (
4-
"regexp"
54
"strings"
65

76
"github.com/prometheus/client_golang/prometheus"
@@ -54,33 +53,12 @@ func (info Info) String() string {
5453
return version
5554
}
5655

57-
var (
58-
reCommitSegment = regexp.MustCompile(`\+[0-9a-f]{6,14}$`)
59-
reCommitIncrement = regexp.MustCompile(`^[0-9a-f]+$`)
60-
)
61-
6256
// LastSemanticVersion attempts to return a semantic version from the GitVersion - which
6357
// is either <semver>+<commit> or <semver> on release boundaries.
6458
func (info Info) LastSemanticVersion() string {
6559
version := info.GitVersion
66-
parts := strings.Split(version, "-")
67-
// strip the modifier
68-
if len(parts) > 1 && parts[len(parts)-1] == "dirty" {
69-
parts = parts[:len(parts)-1]
70-
}
71-
// strip the Git commit
72-
if len(parts) > 0 && reCommitSegment.MatchString(parts[len(parts)-1]) {
73-
parts[len(parts)-1] = reCommitSegment.ReplaceAllString(parts[len(parts)-1], "")
74-
if len(parts[len(parts)-1]) == 0 {
75-
parts = parts[:len(parts)-1]
76-
}
77-
// strip a version increment, but only if we found the commit
78-
if len(parts) > 1 && reCommitIncrement.MatchString(parts[len(parts)-1]) {
79-
parts = parts[:len(parts)-1]
80-
}
81-
}
82-
83-
return strings.Join(parts, "-")
60+
parts := strings.Split(version, "+")
61+
return parts[0]
8462
}
8563

8664
func init() {

pkg/version/version_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ func TestLastSemanticVersion(t *testing.T) {
88
testCases := []struct {
99
in, out string
1010
}{
11-
{"v1.3-11+abcdef-dirty", "v1.3"},
12-
{"v1.3-11+abcdef", "v1.3"},
11+
{"v1.3", "v1.3"},
12+
{"v1.3+dirty", "v1.3"},
13+
{"v1.3-11+abcdef-dirty", "v1.3-11"},
14+
{"v1.3-11+abcdef", "v1.3-11"},
1315
{"v1.3-11", "v1.3-11"},
1416
{"v1.3.0+abcdef", "v1.3.0"},
1517
{"v1.3+abcdef", "v1.3"},
1618
{"v1.3.0-alpha.1", "v1.3.0-alpha.1"},
17-
{"v1.3.0-alpha.1-dirty", "v1.3.0-alpha.1"},
18-
{"v1.3.0-alpha.1+abc-dirty", "v1.3.0-alpha.1+abc"},
19+
{"v1.3.0-alpha.1-dirty", "v1.3.0-alpha.1-dirty"},
20+
{"v1.3.0-alpha.1+abc-dirty", "v1.3.0-alpha.1"},
1921
{"v1.3.0-alpha.1+abcdef-dirty", "v1.3.0-alpha.1"},
2022
}
2123
for _, test := range testCases {

0 commit comments

Comments
 (0)