Files
mattermost/model/version.go

97 lines
2.0 KiB
Go
Raw Normal View History

// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package model
import (
"strconv"
"strings"
)
2015-09-17 13:01:40 -07:00
// This is a list of all the current viersions including any patches.
// It should be maitained in chronological order with most current
// release at the front of the list.
var versions = []string{
2015-11-09 14:23:09 -05:00
"1.2.0",
2015-10-08 16:14:19 -04:00
"1.1.0",
2015-09-28 07:55:59 -04:00
"1.0.0",
2015-09-17 13:01:40 -07:00
"0.7.1",
"0.7.0",
"0.6.0",
"0.5.0",
}
2015-09-17 13:01:40 -07:00
var CurrentVersion string = versions[0]
2015-09-17 13:06:25 -07:00
var BuildNumber = "_BUILD_NUMBER_"
var BuildDate = "_BUILD_DATE_"
var BuildHash = "_BUILD_HASH_"
2015-09-17 13:01:40 -07:00
func SplitVersion(version string) (int64, int64, int64) {
parts := strings.Split(version, ".")
major := int64(0)
minor := int64(0)
patch := int64(0)
if len(parts) > 0 {
major, _ = strconv.ParseInt(parts[0], 10, 64)
}
if len(parts) > 1 {
minor, _ = strconv.ParseInt(parts[1], 10, 64)
}
if len(parts) > 2 {
patch, _ = strconv.ParseInt(parts[2], 10, 64)
}
return major, minor, patch
}
2015-09-17 13:01:40 -07:00
func GetPreviousVersion(currentVersion string) (int64, int64) {
currentIndex := -1
currentMajor, currentMinor, _ := SplitVersion(currentVersion)
2015-09-17 13:01:40 -07:00
for index, version := range versions {
major, minor, _ := SplitVersion(version)
if currentMajor == major && currentMinor == minor {
currentIndex = index
}
if currentIndex >= 0 {
if currentMajor != major || currentMinor != minor {
return major, minor
}
}
}
2015-09-17 13:01:40 -07:00
return 0, 0
}
2015-10-02 09:01:50 -07:00
func IsOfficalBuild() bool {
2015-10-02 09:16:03 -07:00
return BuildNumber != "_BUILD_NUMBER_"
2015-10-02 09:01:50 -07:00
}
func IsCurrentVersion(versionToCheck string) bool {
2015-09-17 13:01:40 -07:00
currentMajor, currentMinor, _ := SplitVersion(CurrentVersion)
toCheckMajor, toCheckMinor, _ := SplitVersion(versionToCheck)
2015-09-17 13:01:40 -07:00
if toCheckMajor == currentMajor && toCheckMinor == currentMinor {
return true
} else {
return false
}
}
2015-09-17 13:01:40 -07:00
func IsPreviousVersion(versionToCheck string) bool {
toCheckMajor, toCheckMinor, _ := SplitVersion(versionToCheck)
2015-09-17 13:01:40 -07:00
prevMajor, prevMinor := GetPreviousVersion(CurrentVersion)
if toCheckMajor == prevMajor && toCheckMinor == prevMinor {
return true
} else {
return false
}
}