Skip to content
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

log: Also stamp version from env var #622

Merged
merged 1 commit into from
Jun 29, 2023
Merged
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
12 changes: 12 additions & 0 deletions log/version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package log

import (
"os"
"runtime/debug"
)

Expand Down Expand Up @@ -48,6 +49,11 @@ func init() {
Version = getVersionFromBuildInfo(info)
}
}
// Try to read version from environment variable if it's not stamped at
// compile time nor from go toolchain
if Version == "" {
Version = getVersionFromEnvVar()
}
}

func getVersionFromBuildInfo(info *debug.BuildInfo) string {
Expand Down Expand Up @@ -81,3 +87,9 @@ func getVersionFromBuildInfo(info *debug.BuildInfo) string {
}
return ""
}

const versionEnvVar = "VERSION"

func getVersionFromEnvVar() string {
return os.Getenv(versionEnvVar)
}