graphql-engine/cli/version/console.go
Aravind Shankar 45bcb6b536
cli, server: use prerelease tag as channel for console assets cdn (#3975)
Co-authored-by: Shahidh K Muhammed <muhammedshahid.k@gmail.com>
2020-03-04 20:10:47 +05:30

63 lines
1.6 KiB
Go

package version
import (
"fmt"
"regexp"
)
var (
preReleaseVersion = "v1.0-alpha"
unversioned = "unversioned"
versioned = "versioned"
)
// 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
}
// tagged build
if v.Server != "" {
if v.ServerSemver != nil {
return fmt.Sprintf("v%d.%d", v.ServerSemver.Major(), v.ServerSemver.Minor())
}
}
// untagged version
return unversioned
}
// GetConsoleAssetsVersion returns the assets version av to be used in the
// 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
func (v *Version) GetConsoleAssetsVersion() (av string) {
// server has a version
if v.Server != "" {
// version is semver
if v.ServerSemver != nil {
// check for release channels
preRelease := v.ServerSemver.Prerelease()
channel := "stable"
if preRelease != "" {
// Get the correct channel from the prerelease tag
var re = regexp.MustCompile(`^[a-z]+`)
tag := re.FindString(preRelease)
if tag != "" {
channel = tag
}
}
return fmt.Sprintf("channel/%s/v%d.%d", channel, v.ServerSemver.Major(), v.ServerSemver.Minor())
}
// version is not semver
return fmt.Sprintf("%s/%s", versioned, v.Server)
}
// server doesn't have a version - very old server :(
return preReleaseVersion
}