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 (
|
const (
|
||||||
// develPrefix is prefixed to developer versions of the application.
|
// noVersion is the reported version when the version cannot be determined.
|
||||||
develPrefix = "v0.0.0-devel"
|
// 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.
|
// Version returns the semantic version of the build.
|
||||||
|
@ -45,7 +52,8 @@ func Version() string {
|
||||||
if tag == "" {
|
if tag == "" {
|
||||||
// This occurs when the tag hasn't been injected,
|
// This occurs when the tag hasn't been injected,
|
||||||
// like when using "go run".
|
// like when using "go run".
|
||||||
version = develPrefix + revision
|
// <version>-<pre-release>+<revision>
|
||||||
|
version = fmt.Sprintf("%s-%s%s", noVersion, develPreRelease, revision)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
version = "v" + tag
|
version = "v" + tag
|
||||||
|
@ -63,18 +71,23 @@ func Version() string {
|
||||||
// disregarded. If it detects that either version is a developer build it
|
// disregarded. If it detects that either version is a developer build it
|
||||||
// returns true.
|
// returns true.
|
||||||
func VersionsMatch(v1, v2 string) bool {
|
func VersionsMatch(v1, v2 string) bool {
|
||||||
// Developer versions are disregarded...hopefully they know what they are
|
// If no version is attached, then it is a dev build outside of CI. The version
|
||||||
// doing.
|
// will be disregarded... hopefully they know what they are doing.
|
||||||
if strings.HasPrefix(v1, develPrefix) || strings.HasPrefix(v2, develPrefix) {
|
if strings.Contains(v1, noVersion) || strings.Contains(v2, noVersion) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
return semver.MajorMinor(v1) == semver.MajorMinor(v2)
|
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.
|
// IsDev returns true if this is a development build.
|
||||||
|
// CI builds are also considered development builds.
|
||||||
func IsDev() bool {
|
func IsDev() bool {
|
||||||
return strings.HasPrefix(Version(), develPrefix)
|
return IsDevVersion(Version())
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsSlim returns true if this is a slim build.
|
// IsSlim returns true if this is a slim build.
|
||||||
|
|
|
@ -57,13 +57,19 @@ func TestBuildInfo(t *testing.T) {
|
||||||
expectMatch: true,
|
expectMatch: true,
|
||||||
},
|
},
|
||||||
// Our CI instance uses a "-devel" prerelease
|
// 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",
|
v1: "v1.1.1-devel+123abac",
|
||||||
v2: "v1.2.3",
|
v2: "v1.2.3",
|
||||||
expectMatch: false,
|
expectMatch: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "DevelPreleaseSame",
|
||||||
|
v1: "v1.1.1-devel+123abac",
|
||||||
|
v2: "v1.1.9",
|
||||||
|
expectMatch: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "MajorMismatch",
|
name: "MajorMismatch",
|
||||||
v1: "v1.2.3",
|
v1: "v1.2.3",
|
||||||
|
|
Loading…
Reference in New Issue