Skip to content

Commit 8f520b3

Browse files
committed
fix(main): forward release ldflags into internal/version; dev --frozen-lockfile
Addresses two copilot review follow-ups from #561: 1. release-time ldflags now land in real package-level variables. The go-app template sets '-X main.version=<tag>' and '-X main.build=<commit>' — but this repo reads build metadata from github.com/netresearch/ldap-manager/internal/version (Version / CommitHash / BuildTimestamp), so the ldflags were a silent no-op and tagged releases still reported 'dev'. Add 'var version, build string' to cmd/ldap-manager/main.go, alias the internal/version import to 'internalversion' to avoid shadowing, and forward the build-injected values into internalversion.Version / CommitHash at init() time. The existing FormatVersion() / 'version --json' subcommand now reflect the actual release info. Switch all 'version.' uses in main.go to 'internalversion.' to match the alias. 2. Dockerfile dev stage: add --frozen-lockfile to 'bun install' for reproducibility parity with the release matrix's 'bun install --frozen-lockfile'. Signed-off-by: Sebastian Mendel <info@sebastianmendel.de>
1 parent 68ce50f commit 8f520b3

2 files changed

Lines changed: 26 additions & 7 deletions

File tree

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ COPY go.mod go.sum package.json bun.lock ./
4242
RUN --mount=type=cache,target=/go/pkg/mod,sharing=locked \
4343
--mount=type=cache,target=/root/.bun/install/cache,sharing=locked \
4444
go mod download && \
45-
bun install
45+
bun install --frozen-lockfile
4646

4747
CMD ["sh"]
4848

cmd/ldap-manager/main.go

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/rs/zerolog/log"
1717

1818
"github.com/netresearch/ldap-manager/internal/options"
19-
"github.com/netresearch/ldap-manager/internal/version"
19+
internalversion "github.com/netresearch/ldap-manager/internal/version"
2020
"github.com/netresearch/ldap-manager/internal/web"
2121
)
2222

@@ -26,6 +26,25 @@ const (
2626
defaultPort = "3000"
2727
)
2828

29+
// Build-injected version metadata. Populated by release.yml's ldflags
30+
// (`-X main.version=<tag>`, `-X main.build=<commit-sha>`); forwarded
31+
// into internal/version at init() so FormatVersion() / the `version`
32+
// subcommand report the release info without requiring each repo to
33+
// invent its own ldflag target-path convention.
34+
var (
35+
version = ""
36+
build = ""
37+
)
38+
39+
func init() {
40+
if version != "" {
41+
internalversion.Version = version
42+
}
43+
if build != "" {
44+
internalversion.CommitHash = build
45+
}
46+
}
47+
2948
func main() {
3049
port := os.Getenv("PORT")
3150
if port == "" {
@@ -38,16 +57,16 @@ func main() {
3857
case "version", "--version":
3958
if len(os.Args) == 3 && os.Args[2] == "--json" {
4059
info := map[string]string{
41-
"version": version.Version,
42-
"commit": version.CommitHash,
43-
"buildTime": version.BuildTimestamp,
60+
"version": internalversion.Version,
61+
"commit": internalversion.CommitHash,
62+
"buildTime": internalversion.BuildTimestamp,
4463
}
4564
enc := json.NewEncoder(os.Stdout)
4665
enc.SetIndent("", " ")
4766
_ = enc.Encode(info)
4867
os.Exit(0)
4968
}
50-
fmt.Println(version.FormatVersion())
69+
fmt.Println(internalversion.FormatVersion())
5170
os.Exit(0)
5271
case "--health-check":
5372
os.Exit(runHealthCheck(port))
@@ -56,7 +75,7 @@ func main() {
5675

5776
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
5877

59-
log.Info().Msgf("LDAP Manager %s starting...", version.FormatVersion())
78+
log.Info().Msgf("LDAP Manager %s starting...", internalversion.FormatVersion())
6079

6180
opts, err := options.Parse()
6281
if err != nil {

0 commit comments

Comments
 (0)