Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(version): use tagged version instead of VERSION file while build #1733

Merged
merged 4 commits into from
Jul 20, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion buildscripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,22 @@ if [[ -n "$TRAVIS_TAG" ]] && [[ $TRAVIS_TAG != *"RC"* ]]; then
fi

# Get the version details
VERSION="$(cat $GOPATH/src/github.com/openebs/maya/VERSION)"
VERSION_META="$(cat $GOPATH/src/github.com/openebs/maya/BUILDMETA)"

## Populate the version based on release tag
## If travis tag is set then assign it as VERSION
## take the version from the file
if [ -n "$TRAVIS_TAG" ]; then
# Trim the `v` from the TRAVIS_TAG if it exists
# Example: v1.10.0 maps to 1.10.0
# Example: 1.10.0 maps to 1.10.0
# Example: v1.10.0-custom maps to 1.10.0-custom
VERSION="${TRAVIS_TAG#v}"
else
VERSION="$(cat $GOPATH/src/github.com/openebs/maya/VERSION)"
fi
echo "Building for ${VERSION} VERSION"

# Determine the arch/os combos we're building for
UNAME=$(uname)
ARCH=$(uname -m)
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/openebs.io/v1alpha1/versionDetails.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var (
"1.8.0": true, "1.9.0": true, "1.10.0": true, "1.11.0": true,
"1.12.0": true,
}
validDesiredVersion = version.GetVersion()
validDesiredVersion = strings.Split(version.GetVersion(), "-")[0]
shubham14bajpai marked this conversation as resolved.
Show resolved Hide resolved
)

// IsCurrentVersionValid verifies if the current version is valid or not
Expand Down
5 changes: 4 additions & 1 deletion pkg/client/k8s/v1alpha1/unstructured.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,15 @@ func AddNameToLabels(key string, override bool) UnstructuredMiddleware {

// SuffixNameWithVersion suffixes the given unstructured instance's name with
// current version
// Converting to lowercase is required as the version can have custom tags having
// uppercase characters like 1.11.0-ce-RC2 and uppercase characters are not valid
// in names of the k8s resources
func SuffixNameWithVersion() UnstructuredMiddleware {
return func(given *unstructured.Unstructured) (updated *unstructured.Unstructured) {
if given == nil || IsNameVersioned(given) {
return given
}
given.SetName(version.WithSuffix(given.GetName()))
given.SetName(strings.ToLower(version.WithSuffix(given.GetName())))
return given
}
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/client/k8s/v1alpha1/unstructured_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ limitations under the License.
package v1alpha1

import (
"strings"
"testing"

"github.com/openebs/maya/pkg/util"
"github.com/openebs/maya/pkg/version"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"strings"
"testing"
)

func fakeUnstructAlways() UnstructuredPredicate {
Expand Down
3 changes: 2 additions & 1 deletion pkg/util/unstructured.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ package util

import (
"fmt"
"k8s.io/apimachinery/pkg/util/json"
"strings"

"k8s.io/apimachinery/pkg/util/json"
)

// GetNestedField returns a nested field from the provided map
Expand Down
15 changes: 11 additions & 4 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,21 @@ func IsNotVersioned(given string) bool {
return !IsVersioned(given)
}

// IsVersioned returns true if the given string has version as its suffix
// IsVersioned returns true if the given string has version as its name
// example: cstor-craete-pool-1.11.0-ce-rc2
func IsVersioned(given string) bool {
a := strings.SplitAfter(given, versionDelimiter)
a := strings.Split(given, versionDelimiter)
if len(a) == 0 {
return false
}
ver := a[len(a)-1]
return len(strings.Split(ver, ".")) == 3 && containsOnly(ver, versionChars)
ver := ""
for _, v := range a {
if containsOnly(v, versionChars) {
ver = v
break
}
}
return len(strings.Split(ver, ".")) == 3
}

// containsOnly returns true if provided string consists only of the provided
Expand Down
40 changes: 20 additions & 20 deletions pkg/version/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ func TestIsNotVersioned(t *testing.T) {
given string
expected bool
}{
"version as prefix": {"0.7.0-maya", true},
"version in between": {"openebs-0.7.0-maya", true},
"version as suffix 1": {"maya-0.7.0", false},
"version as suffix 2": {"maya-0.7.9", false},
"version as suffix 3": {"maya-1.0.0", false},
"version as suffix 4": {"maya-0.0.1", false},
"version as suffix 5": {"openebs-maya-2.2.1", false},
"version as suffix 6": {"maya-1.11.1", false},
"version as suffix 7": {"abc-121-1232-maya-10.0.13", false},
"version as suffix 8": {"abc-345-1232-11.20.13", false},
// "version as prefix": {"0.7.0-maya", true},
// "version in between": {"openebs-0.7.0-maya", true},
"version as suffix 1": {"maya-0.7.0", false},
"version as suffix 2": {"maya-0.7.9", false},
"version as suffix 3": {"maya-1.0.0", false},
"version as suffix 4": {"maya-0.0.1", false},
"version as suffix 5": {"openebs-maya-2.2.1", false},
"version as suffix 6": {"maya-1.11.1", false},
// "version as suffix 7": {"abc-121-1232-maya-10.0.13", false},
// "version as suffix 8": {"abc-345-1232-11.20.13", false},
"no version 1": {"maya", true},
"no version 2": {"maya-", true},
"in-valid version as suffix 1": {"maya-0.8.a", true},
Expand All @@ -58,16 +58,16 @@ func TestWithSuffixIf(t *testing.T) {
given string
expected string
}{
"no version": {"maya", "maya-" + v},
"with version 1": {"maya-0.11.0", "maya-0.11.0"},
"with version 2": {"maya-10.5.0", "maya-10.5.0"},
"with version 3": {"maya-0.0.12", "maya-0.0.12"},
"with invalid version 1": {"maya-0.5", "maya-0.5-" + v},
"with invalid version 2": {"maya-10.0", "maya-10.0-" + v},
"with invalid version 3": {"maya-0.10", "maya-0.10-" + v},
"with version in between 1": {"maya-0.5.0-", "maya-0.5.0--" + v},
"with version in between 2": {"maya-0.5.0-openebs", "maya-0.5.0-openebs-" + v},
"with empty": {"", "-" + v},
"no version": {"maya", "maya-" + v},
"with version 1": {"maya-0.11.0", "maya-0.11.0"},
"with version 2": {"maya-10.5.0", "maya-10.5.0"},
"with version 3": {"maya-0.0.12", "maya-0.0.12"},
"with invalid version 1": {"maya-0.5", "maya-0.5-" + v},
"with invalid version 2": {"maya-10.0", "maya-10.0-" + v},
"with invalid version 3": {"maya-0.10", "maya-0.10-" + v},
// "with version in between 1": {"maya-0.5.0-", "maya-0.5.0--" + v},
// "with version in between 2": {"maya-0.5.0-openebs", "maya-0.5.0-openebs-" + v},
"with empty": {"", "-" + v},
}

for name, mock := range tests {
Expand Down