44 lines
1.5 KiB
Go
44 lines
1.5 KiB
Go
package scaffold
|
|
|
|
import (
|
|
"regexp"
|
|
"runtime/debug"
|
|
)
|
|
|
|
const frameworkModule = "git.yuntuo.hk/k2safe/go-omni"
|
|
|
|
// Source builds can carry an unpublished VCS version (including +dirty).
|
|
// Keep this fallback in sync with the next release; installed CLIs use their
|
|
// downloaded module version, which also has a module checksum.
|
|
const defaultFrameworkVersion = "v0.28.0-preview"
|
|
|
|
// This target is not a claim that the release already exists. Source users
|
|
// select a local framework checkout until the module templates are published.
|
|
const modulesFrameworkVersion = "v0.22.0-preview"
|
|
|
|
func installedFrameworkVersion() string {
|
|
info, _ := debug.ReadBuildInfo()
|
|
if info != nil && info.Main.Path == frameworkModule && info.Main.Sum != "" && validFrameworkVersion(info.Main.Version) {
|
|
return info.Main.Version
|
|
}
|
|
return ""
|
|
}
|
|
|
|
var frameworkVersionPattern = regexp.MustCompile(`^v[01]\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*)(\.(0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*))*))?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$`)
|
|
|
|
func validFrameworkVersion(version string) bool {
|
|
return frameworkVersionPattern.MatchString(version)
|
|
}
|
|
|
|
func currentFrameworkVersion() string {
|
|
info, _ := debug.ReadBuildInfo()
|
|
return frameworkVersion(info)
|
|
}
|
|
|
|
func frameworkVersion(info *debug.BuildInfo) string {
|
|
if info != nil && info.Main.Path == frameworkModule && info.Main.Sum != "" && validFrameworkVersion(info.Main.Version) {
|
|
return info.Main.Version
|
|
}
|
|
return defaultFrameworkVersion
|
|
}
|