From 711a27ac602b813b00ff3884191fe28ccf120a36 Mon Sep 17 00:00:00 2001 From: Karl Date: Sat, 19 Oct 2024 21:15:54 +1100 Subject: [PATCH 1/5] verison fix Signed-off-by: Karl --- .goreleaser.yml | 12 ++++++------ service/library/version.go | 36 +++++++++++++++++++++++++++++------- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index f92172ce..6fc0121e 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -18,9 +18,9 @@ builds: env: - CGO_ENABLED=0 ldflags: - - -X main.Version={{.Tag}} - - -X main.CommitSHA={{.FullCommit}} - - -X main.BuildDate={{.CommitDate}} + - -X main.version={{.Version}} + - -X main.commit={{.Commit}} + - -X main.date={{.Date}} - -X main.GoOS={{.Os}} - -X main.GoArch={{.Arch}} goos: @@ -46,9 +46,9 @@ builds: flags: - -a ldflags: - - -X main.Version={{.Tag}} - - -X main.CommitSHA={{.FullCommit}} - - -X main.BuildDate={{.CommitDate}} + - -X main.version={{.Version}} + - -X main.commit={{.Commit}} + - -X main.date={{.Date}} - -X main.GoOS={{.Os}} - -X main.GoArch={{.Arch}} - -extldflags "-static" diff --git a/service/library/version.go b/service/library/version.go index 0d2f8fed..70312aba 100644 --- a/service/library/version.go +++ b/service/library/version.go @@ -2,17 +2,39 @@ package library import ( "fmt" + "log" "runtime/debug" + "strings" +) + +var ( + version = "dev" + commit = "none" + date = "unknown" ) // Version describes which version of Pygmy is running. -func Version(c Config) { - info, _ := debug.ReadBuildInfo() +func Version(c Config) error { - if info.Main.Version == "(devel)" { - fmt.Println("Development version") - return - } + version = getVersion() + fmt.Printf("Application version: %s\n", version) + + // Use the version information as needed + log.Printf("Running version %s (commit: %s, built on: %s)", version, commit, date) - fmt.Printf("Pygmy %s\n", info.Main.Version) + return nil +} + +func getVersion() string { + if info, ok := debug.ReadBuildInfo(); ok { + for _, setting := range info.Settings { + switch setting.Key { + case "vcs.revision": + commit = setting.Value[:8] // Short commit hash + case "vcs.time": + date = setting.Value + } + } + } + return strings.TrimPrefix(version, "v") } From ecfa815098b5415d30d4a5957de54cdc15e68a9a Mon Sep 17 00:00:00 2001 From: Karl Date: Sat, 19 Oct 2024 21:28:11 +1100 Subject: [PATCH 2/5] update Signed-off-by: Karl --- .goreleaser.yml | 4 ++++ service/library/version.go | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/.goreleaser.yml b/.goreleaser.yml index 6fc0121e..c338da9c 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -18,6 +18,8 @@ builds: env: - CGO_ENABLED=0 ldflags: + - -s + - -w - -X main.version={{.Version}} - -X main.commit={{.Commit}} - -X main.date={{.Date}} @@ -46,6 +48,8 @@ builds: flags: - -a ldflags: + - -s + - -w - -X main.version={{.Version}} - -X main.commit={{.Commit}} - -X main.date={{.Date}} diff --git a/service/library/version.go b/service/library/version.go index 70312aba..956d92de 100644 --- a/service/library/version.go +++ b/service/library/version.go @@ -33,8 +33,17 @@ func getVersion() string { commit = setting.Value[:8] // Short commit hash case "vcs.time": date = setting.Value + case "vcs.modified": + if setting.Value == "true" { + commit += "-dirty" + } } } } + + if version == "dev" { + return fmt.Sprintf("%s-%s", version, commit) + } + return strings.TrimPrefix(version, "v") } From 4a85241ba6637be716569f5bac2231ec6f656de1 Mon Sep 17 00:00:00 2001 From: Karl Date: Sat, 19 Oct 2024 21:31:15 +1100 Subject: [PATCH 3/5] update Signed-off-by: Karl --- .goreleaser.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.goreleaser.yml b/.goreleaser.yml index c338da9c..baf596e4 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -42,6 +42,16 @@ builds: - 386 - amd64 - arm + flags: + - -a + ldflags: + - -s + - -w + - -X main.version={{.Version}} + - -X main.commit={{.Commit}} + - -X main.date={{.Date}} + - -X main.GoOS={{.Os}} + - -X main.GoArch={{.Arch}} - id: pygmy-static env: - CGO_ENABLED=0 From 33fb4f01325c3e096ad28fad518764b6d1237bd1 Mon Sep 17 00:00:00 2001 From: Karl Date: Sat, 19 Oct 2024 22:07:47 +1100 Subject: [PATCH 4/5] updates Signed-off-by: Karl --- .goreleaser.yml | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index baf596e4..23dfb41c 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -15,16 +15,17 @@ archives: builds: - id: pygmy +# binary: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}' env: - CGO_ENABLED=0 ldflags: - -s - -w - - -X main.version={{.Version}} - - -X main.commit={{.Commit}} - - -X main.date={{.Date}} - - -X main.GoOS={{.Os}} - - -X main.GoArch={{.Arch}} + - -X 'main.version={{.Version}}' + - -X 'main.commit={{.Commit}}' + - -X 'main.date={{.Date}}' + - -X 'main.GoOS={{.Os}}' + - -X 'main.GoArch={{.Arch}}' goos: - linux - darwin @@ -34,6 +35,7 @@ builds: - arm - arm64 - id: pygmy-windows +# binary: '{{ .ProjectName }}-windows_{{ .Version }}_{{ .Os }}_{{ .Arch }}' env: - CGO_ENABLED=0 goos: @@ -47,12 +49,13 @@ builds: ldflags: - -s - -w - - -X main.version={{.Version}} - - -X main.commit={{.Commit}} - - -X main.date={{.Date}} - - -X main.GoOS={{.Os}} - - -X main.GoArch={{.Arch}} + - -X 'main.version={{.Version}}' + - -X 'main.commit={{.Commit}}' + - -X 'main.date={{.Date}}' + - -X 'main.GoOS={{.Os}}' + - -X 'main.GoArch={{.Arch}}' - id: pygmy-static +# binary: '{{ .ProjectName }}-static_{{ .Version }}_{{ .Os }}_{{ .Arch }}' env: - CGO_ENABLED=0 flags: @@ -60,11 +63,11 @@ builds: ldflags: - -s - -w - - -X main.version={{.Version}} - - -X main.commit={{.Commit}} - - -X main.date={{.Date}} - - -X main.GoOS={{.Os}} - - -X main.GoArch={{.Arch}} + - -X 'main.version={{.Version}}' + - -X 'main.commit={{.Commit}}' + - -X 'main.date={{.Date}}' + - -X 'main.GoOS={{.Os}}' + - -X 'main.GoArch={{.Arch}}' - -extldflags "-static" goos: - linux From 310c81d69153b973eb7fcafc3cbd605d5aeb582e Mon Sep 17 00:00:00 2001 From: Karl Date: Sat, 19 Oct 2024 22:26:11 +1100 Subject: [PATCH 5/5] cleanup Signed-off-by: Karl --- .goreleaser.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index 23dfb41c..fa9e0467 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -15,7 +15,6 @@ archives: builds: - id: pygmy -# binary: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}' env: - CGO_ENABLED=0 ldflags: @@ -35,7 +34,6 @@ builds: - arm - arm64 - id: pygmy-windows -# binary: '{{ .ProjectName }}-windows_{{ .Version }}_{{ .Os }}_{{ .Arch }}' env: - CGO_ENABLED=0 goos: @@ -55,7 +53,6 @@ builds: - -X 'main.GoOS={{.Os}}' - -X 'main.GoArch={{.Arch}}' - id: pygmy-static -# binary: '{{ .ProjectName }}-static_{{ .Version }}_{{ .Os }}_{{ .Arch }}' env: - CGO_ENABLED=0 flags: