From 686de9996788f24b77f555b19adf7bfdd66644b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20M=C3=B6hlmann?= Date: Thu, 8 Jan 2026 07:22:36 +0100 Subject: [PATCH] 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 --- backend/v3/api/instance/v2/convert/instance_test.go | 11 +++++++++-- cmd/build/info.go | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/backend/v3/api/instance/v2/convert/instance_test.go b/backend/v3/api/instance/v2/convert/instance_test.go index ef11b0386..0eff83be0 100644 --- a/backend/v3/api/instance/v2/convert/instance_test.go +++ b/backend/v3/api/instance/v2/convert/instance_test.go @@ -9,6 +9,7 @@ import ( "google.golang.org/protobuf/types/known/timestamppb" "github.com/zitadel/zitadel/backend/v3/domain" + "github.com/zitadel/zitadel/cmd/build" filter_v2 "github.com/zitadel/zitadel/pkg/grpc/filter/v2" filter_v2beta "github.com/zitadel/zitadel/pkg/grpc/filter/v2beta" instance_v2 "github.com/zitadel/zitadel/pkg/grpc/instance/v2" @@ -62,7 +63,7 @@ func TestDomainInstanceModelToGRPCBetaResponse(t *testing.T) { ChangeDate: timestamppb.New(now), CreationDate: timestamppb.New(yesterday), Name: "Instance One", - Version: "", + Version: build.Version(), Domains: []*instance_v2beta.Domain{ { InstanceId: "instance-1", @@ -150,7 +151,7 @@ func TestDomainInstanceModelToGRPCResponse(t *testing.T) { CreationDate: timestamppb.New(yesterday), State: instance_v2.State_STATE_RUNNING, Name: "Instance One", - Version: "", + Version: build.Version(), CustomDomains: []*instance_v2.CustomDomain{ { InstanceId: "instance-1", @@ -221,6 +222,7 @@ func TestDomainInstanceListModelToGRPCBetaResponse(t *testing.T) { Name: "test-instance", CreationDate: timestamppb.New(now), ChangeDate: timestamppb.New(now), + Version: build.Version(), Domains: []*instance_v2beta.Domain{}, }, }, @@ -257,6 +259,7 @@ func TestDomainInstanceListModelToGRPCBetaResponse(t *testing.T) { Name: "test-instance-1", CreationDate: timestamppb.New(now), ChangeDate: timestamppb.New(now), + Version: build.Version(), Domains: []*instance_v2beta.Domain{ { InstanceId: "instance1", @@ -272,6 +275,7 @@ func TestDomainInstanceListModelToGRPCBetaResponse(t *testing.T) { Name: "test-instance-2", CreationDate: timestamppb.New(now), ChangeDate: timestamppb.New(now), + Version: build.Version(), Domains: []*instance_v2beta.Domain{}, }, }, @@ -322,6 +326,7 @@ func TestDomainInstanceListModelToGRPCResponse(t *testing.T) { CreationDate: timestamppb.New(now), ChangeDate: timestamppb.New(now), State: instance_v2.State_STATE_RUNNING, + Version: build.Version(), CustomDomains: []*instance_v2.CustomDomain{}, }, }, @@ -359,6 +364,7 @@ func TestDomainInstanceListModelToGRPCResponse(t *testing.T) { CreationDate: timestamppb.New(now), ChangeDate: timestamppb.New(now), State: instance_v2.State_STATE_RUNNING, + Version: build.Version(), CustomDomains: []*instance_v2.CustomDomain{ { InstanceId: "instance1", @@ -375,6 +381,7 @@ func TestDomainInstanceListModelToGRPCResponse(t *testing.T) { CreationDate: timestamppb.New(now), ChangeDate: timestamppb.New(now), State: instance_v2.State_STATE_RUNNING, + Version: build.Version(), CustomDomains: []*instance_v2.CustomDomain{}, }, }, diff --git a/cmd/build/info.go b/cmd/build/info.go index 0f61f6022..8d0b18931 100644 --- a/cmd/build/info.go +++ b/cmd/build/info.go @@ -23,6 +23,7 @@ func init() { 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")