mirror of https://github.com/coder/coder.git
fix: consider all 'devel' builds as 'dev' builds (#9794)
* fix: all 'devel' builds should be considered 'dev' builds. If CI needs to be distinguished from a dev build, we should add a different pre-release tag for those builds. * change CI version checking to be more strict
This commit is contained in:
parent
47d3161b0b
commit
b6c5e94ffa
|
@ -30,8 +30,15 @@ var (
|
|||
)
|
||||
|
||||
const (
|
||||
// develPrefix is prefixed to developer versions of the application.
|
||||
develPrefix = "v0.0.0-devel"
|
||||
// noVersion is the reported version when the version cannot be determined.
|
||||
// Usually because `go build` is run instead of `make build`.
|
||||
noVersion = "v0.0.0"
|
||||
|
||||
// develPreRelease is the pre-release tag for developer versions of the
|
||||
// application. This includes CI builds. The pre-release tag should be appended
|
||||
// to the version with a "-".
|
||||
// Example: v0.0.0-devel
|
||||
develPreRelease = "devel"
|
||||
)
|
||||
|
||||
// Version returns the semantic version of the build.
|
||||
|
@ -45,7 +52,8 @@ func Version() string {
|
|||
if tag == "" {
|
||||
// This occurs when the tag hasn't been injected,
|
||||
// like when using "go run".
|
||||
version = develPrefix + revision
|
||||
// <version>-<pre-release>+<revision>
|
||||
version = fmt.Sprintf("%s-%s%s", noVersion, develPreRelease, revision)
|
||||
return
|
||||
}
|
||||
version = "v" + tag
|
||||
|
@ -63,18 +71,23 @@ func Version() string {
|
|||
// disregarded. If it detects that either version is a developer build it
|
||||
// returns true.
|
||||
func VersionsMatch(v1, v2 string) bool {
|
||||
// Developer versions are disregarded...hopefully they know what they are
|
||||
// doing.
|
||||
if strings.HasPrefix(v1, develPrefix) || strings.HasPrefix(v2, develPrefix) {
|
||||
// If no version is attached, then it is a dev build outside of CI. The version
|
||||
// will be disregarded... hopefully they know what they are doing.
|
||||
if strings.Contains(v1, noVersion) || strings.Contains(v2, noVersion) {
|
||||
return true
|
||||
}
|
||||
|
||||
return semver.MajorMinor(v1) == semver.MajorMinor(v2)
|
||||
}
|
||||
|
||||
func IsDevVersion(v string) bool {
|
||||
return strings.Contains(v, "-"+develPreRelease)
|
||||
}
|
||||
|
||||
// IsDev returns true if this is a development build.
|
||||
// CI builds are also considered development builds.
|
||||
func IsDev() bool {
|
||||
return strings.HasPrefix(Version(), develPrefix)
|
||||
return IsDevVersion(Version())
|
||||
}
|
||||
|
||||
// IsSlim returns true if this is a slim build.
|
||||
|
|
|
@ -57,13 +57,19 @@ func TestBuildInfo(t *testing.T) {
|
|||
expectMatch: true,
|
||||
},
|
||||
// Our CI instance uses a "-devel" prerelease
|
||||
// flag. This is not the same as a developer WIP build.
|
||||
// flag.
|
||||
{
|
||||
name: "DevelPreleaseNotIgnored",
|
||||
name: "DevelPreleaseMajor",
|
||||
v1: "v1.1.1-devel+123abac",
|
||||
v2: "v1.2.3",
|
||||
expectMatch: false,
|
||||
},
|
||||
{
|
||||
name: "DevelPreleaseSame",
|
||||
v1: "v1.1.1-devel+123abac",
|
||||
v2: "v1.1.9",
|
||||
expectMatch: true,
|
||||
},
|
||||
{
|
||||
name: "MajorMismatch",
|
||||
v1: "v1.2.3",
|
||||
|
|
Loading…
Reference in New Issue