Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: consider all 'devel' builds as 'dev' builds #9794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions buildinfo/buildinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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.
Expand Down
10 changes: 8 additions & 2 deletions buildinfo/buildinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down