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 1 commit
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
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

27 changes: 26 additions & 1 deletion buildscripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,33 @@ 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)"
# Determine the current branch
CURRENT_BRANCH=""
if [ -z "${TRAVIS_BRANCH}" ];
then
CURRENT_BRANCH=$(git branch | grep "\*" | cut -d ' ' -f2)
else
CURRENT_BRANCH="${TRAVIS_BRANCH}"
fi

## Populate the version based on release tag
## If travis tag is set then assign it as VERSION and
## if travis tag is empty then mark version as ci
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
## Marking VERSION as current_branch-dev
## Example: master branch maps to master-dev
## Example: v1.11.x-ee branch to 1.11.x-ee-dev
## Example: v1.10.x branch to 1.10.x-dev
VERSION="${CURRENT_BRANCH#v}-dev"
fi
echo "Building for ${VERSION} VERSION"

# Determine the arch/os combos we're building for
UNAME=$(uname)
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: 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
5 changes: 4 additions & 1 deletion pkg/util/unstructured.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ 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
func GetNestedField(obj map[string]interface{}, fields ...string) interface{} {
fmt.Println("obj", obj)
shubham14bajpai marked this conversation as resolved.
Show resolved Hide resolved
fmt.Println("fields", fields)
var val interface{} = obj
for _, field := range fields {
if _, ok := val.(map[string]interface{}); !ok {
Expand Down
13 changes: 10 additions & 3 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,20 @@ func IsNotVersioned(given string) bool {
}

// IsVersioned returns true if the given string has version as its suffix
// cstor-craete-pool-1.11.0-ee-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