Files
zitadel/cmd/build/info.go
T
Tim MöhlmannandGitHub 686de99967 fix(cmd/build): populate date variable when not set through ldflags (#11316)
# Which Problems Are Solved

When building zitadel through `go build` or using an IDE debugging tool,
ldflags are not passed by dedault. In the past this was taken care of by
the `make compile` command, which got replaced by NX. The `nx
@zitadel/api:build` command does not set the ldflags either. Only the
`pack-platform` command does.

Because the ldflags aren't passed, the `date` and other variables remain
empty in the `cmd/build` package. During init of the package, if the
`version` is empty it defaults to the `date` variable. When the `date`
field was empty, the parsed `dateTime` would default to `time.Now()`,
but the `date` variable remained empty, resulting in a empty version.

A consistently empty version string prevents upgrades of projections on
dev systems, as the version from the last run is used.

# How the Problems Are Solved

If date failed to parse and `dateTime` is set to Now, use the formated
string of `dateTime` as `date`.

# Additional Context

- Blocks https://github.com/zitadel/zitadel/pull/11239
2026-01-08 07:22:36 +01:00

48 lines
984 B
Go

package build
import (
"time"
"github.com/zitadel/logging"
)
// These variables are set via ldflags in the Makefile
var (
version = ""
commit = ""
date = ""
)
// dateTime is the parsed version of [date]
var dateTime time.Time
// init prevents race conditions when accessing dateTime and version.
func init() {
var err error
dateTime, err = time.Parse(time.RFC3339, date)
if err != nil {
logging.WithError(err).Warn("could not parse build date, using current time instead")
dateTime = time.Now()
date = dateTime.Format(time.RFC3339)
}
if version == "" {
logging.Warn("no build version set, using timestamp as version")
version = date
}
}
// Version returns the current build version of Zitadel
func Version() string {
return version
}
// Commit returns the git commit hash of the current build of Zitadel
func Commit() string {
return commit
}
// Date returns the build date of the current build of Zitadel
func Date() time.Time {
return dateTime
}