diff --git a/Makefile b/Makefile index bdd821c7..c9b885b4 100644 --- a/Makefile +++ b/Makefile @@ -3,9 +3,12 @@ PKG := git.blender.org/flamenco # To update the version number in all the relevant places, update the VERSION # variable below and run `make update-version`. VERSION := 3.0-dev0 +RELEASE_CYCLE := alpha GITHASH := $(shell git describe --dirty --always) -LDFLAGS := -X ${PKG}/internal/appinfo.ApplicationVersion=${VERSION} -X ${PKG}/internal/appinfo.ApplicationGitHash=${GITHASH} +LDFLAGS := -X ${PKG}/internal/appinfo.ApplicationVersion=${VERSION} \ + -X ${PKG}/internal/appinfo.ApplicationGitHash=${GITHASH} \ + -X ${PKG}/internal/appinfo.ReleaseCycle=${RELEASE_CYCLE} BUILD_FLAGS = -ldflags="${LDFLAGS}" # Package name of the generated Python/JavaScript code for the Flamenco API. diff --git a/cmd/flamenco-manager/main.go b/cmd/flamenco-manager/main.go index ed1e74e2..0bd9a5ee 100644 --- a/cmd/flamenco-manager/main.go +++ b/cmd/flamenco-manager/main.go @@ -73,6 +73,7 @@ func main() { log.Info(). Str("version", appinfo.ApplicationVersion). Str("git", appinfo.ApplicationGitHash). + Str("releaseCycle", appinfo.ReleaseCycle). Str("os", runtime.GOOS). Str("arch", runtime.GOARCH). Msgf("starting %v", appinfo.ApplicationName) diff --git a/cmd/flamenco-worker/main.go b/cmd/flamenco-worker/main.go index ae19ca0b..986c8acd 100644 --- a/cmd/flamenco-worker/main.go +++ b/cmd/flamenco-worker/main.go @@ -63,6 +63,7 @@ func main() { log.Info(). Str("version", appinfo.ApplicationVersion). Str("git", appinfo.ApplicationGitHash). + Str("releaseCycle", appinfo.ReleaseCycle). Str("OS", runtime.GOOS). Str("ARCH", runtime.GOARCH). Int("pid", os.Getpid()). diff --git a/internal/appinfo/appinfo.go b/internal/appinfo/appinfo.go index 7d927e24..7b08b7f5 100644 --- a/internal/appinfo/appinfo.go +++ b/internal/appinfo/appinfo.go @@ -15,6 +15,17 @@ var ApplicationVersion = "set-during-build" // It is set during the build. var ApplicationGitHash = "set-during-build" +// ReleaseCycle determines whether this is marked as release or whether it's +// an development version. This is used to determine wehtehr ExtendedVersion() +// actually returns just the version ("release") or also has the Git hash +// (any other string). +// +// This is a string and not a boolean, because it must be set by the linker and +// that only supports strings. +var ReleaseCycle string = "set-during-build" + +const releaseCycleRelease = "release" + // FormattedApplicationInfo returns the application name & version as single string. func FormattedApplicationInfo() string { return fmt.Sprintf("%s %s", ApplicationName, ApplicationVersion) @@ -24,3 +35,13 @@ func FormattedApplicationInfo() string { func UserAgent() string { return fmt.Sprintf("%s/%s (%s)", ApplicationName, ApplicationVersion, ApplicationGitHash) } + +// ExtendedVersion returns the application version, and includes the Git hash if +// this is not a release version. See `IsReleaseVersion`. +func ExtendedVersion() string { + if ReleaseCycle == releaseCycleRelease { + return ApplicationVersion + } + + return fmt.Sprintf("%s-%s", ApplicationVersion, ApplicationGitHash) +} diff --git a/internal/manager/api_impl/meta.go b/internal/manager/api_impl/meta.go index 41c5a10e..0d940c93 100644 --- a/internal/manager/api_impl/meta.go +++ b/internal/manager/api_impl/meta.go @@ -23,7 +23,7 @@ import ( func (f *Flamenco) GetVersion(e echo.Context) error { return e.JSON(http.StatusOK, api.FlamencoVersion{ - Version: appinfo.ApplicationVersion, + Version: appinfo.ExtendedVersion(), Name: appinfo.ApplicationName, }) } diff --git a/internal/worker/registration.go b/internal/worker/registration.go index a2e9acfd..fab65901 100644 --- a/internal/worker/registration.go +++ b/internal/worker/registration.go @@ -153,7 +153,7 @@ func signOn(ctx context.Context, cfg WorkerConfig, client FlamencoClient) (api.W req := api.SignOnJSONRequestBody{ Name: workerName(), SupportedTaskTypes: cfg.TaskTypes, - SoftwareVersion: appinfo.ApplicationVersion, + SoftwareVersion: appinfo.ExtendedVersion(), } logger.Info().