2018-07-04 15:43:52 +03:00
|
|
|
package version
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2019-05-16 10:45:29 +03:00
|
|
|
"strings"
|
2018-07-04 15:43:52 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
preReleaseVersion = "v1.0-alpha"
|
|
|
|
unversioned = "unversioned"
|
2019-05-16 10:45:29 +03:00
|
|
|
versioned = "versioned"
|
2018-07-04 15:43:52 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// GetConsoleTemplateVersion returns the template version tv required to render
|
|
|
|
// the console html.
|
|
|
|
func (v *Version) GetConsoleTemplateVersion() (tv string) {
|
|
|
|
// pre-release builds
|
|
|
|
if v.Server == "" {
|
|
|
|
return preReleaseVersion
|
|
|
|
}
|
2019-05-16 10:45:29 +03:00
|
|
|
// tagged build
|
2018-07-04 15:43:52 +03:00
|
|
|
if v.Server != "" {
|
|
|
|
if v.ServerSemver != nil {
|
|
|
|
return fmt.Sprintf("v%d.%d", v.ServerSemver.Major(), v.ServerSemver.Minor())
|
|
|
|
}
|
|
|
|
}
|
2019-05-16 10:45:29 +03:00
|
|
|
// untagged version
|
2018-07-04 15:43:52 +03:00
|
|
|
return unversioned
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetConsoleAssetsVersion returns the assets version av to be used in the
|
2019-05-16 10:45:29 +03:00
|
|
|
// console template. This function is supposed to return the following:
|
|
|
|
// > input -> output
|
|
|
|
// > dev-build -> versioned/dev-build
|
|
|
|
// > v1.0.0-beta.01 -> beta/v1.0
|
|
|
|
// > v1.0.0-alpha.01 -> alpha/v1.0
|
|
|
|
// > v1.2.1-rc.03 -> rc/v1.2
|
|
|
|
// > v1.1.0 -> stable/v1.1
|
2018-07-04 15:43:52 +03:00
|
|
|
func (v *Version) GetConsoleAssetsVersion() (av string) {
|
2019-05-16 10:45:29 +03:00
|
|
|
// server has a version
|
2018-07-04 15:43:52 +03:00
|
|
|
if v.Server != "" {
|
2019-05-16 10:45:29 +03:00
|
|
|
// version is semver
|
2018-07-04 15:43:52 +03:00
|
|
|
if v.ServerSemver != nil {
|
2019-05-16 10:45:29 +03:00
|
|
|
// check for release channels
|
|
|
|
preRelease := v.ServerSemver.Prerelease()
|
|
|
|
channel := "stable"
|
|
|
|
if strings.HasPrefix(preRelease, "alpha") {
|
|
|
|
channel = "alpha"
|
|
|
|
}
|
|
|
|
if strings.HasPrefix(preRelease, "beta") {
|
|
|
|
channel = "beta"
|
|
|
|
}
|
|
|
|
if strings.HasPrefix(preRelease, "rc") {
|
|
|
|
channel = "rc"
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("channel/%s/v%d.%d", channel, v.ServerSemver.Major(), v.ServerSemver.Minor())
|
2018-07-04 15:43:52 +03:00
|
|
|
}
|
2019-05-16 10:45:29 +03:00
|
|
|
// version is not semver
|
|
|
|
return fmt.Sprintf("%s/%s", versioned, v.Server)
|
2018-07-04 15:43:52 +03:00
|
|
|
}
|
2019-05-16 10:45:29 +03:00
|
|
|
// server doesn't have a version - very old server :(
|
2018-07-04 15:43:52 +03:00
|
|
|
return preReleaseVersion
|
|
|
|
}
|