detached 1d06a33

feat(build): Add version command and fix goreleaser configuration for Linux/macOS builds

- Add gordon version command with full and short output options
- Integrate version information from goreleaser via ldflags
- Remove Windows builds to focus on Linux and macOS platforms
- Fix deprecated goreleaser archive format configuration
- Make config file optional for version command
commit
1d06a33854e5a23d27ace82c1cfcfd248e3bb5eb
author
bamen · · 2025-06-09 16:49 UTC
parent
9cb47e4
signature
unsigned
4 files · +60 -6
M .goreleaser.yaml +1 -3
@@ -12,7 +12,6 @@ builds:
1212 binary: gordon
1313 goos:
1414 - linux
15- - windows
1615 - darwin
1716 goarch:
1817 - amd64
@@ -63,8 +62,7 @@ docker_manifests:
6362 - ghcr.io/bnema/gordon:{{ .Tag }}-arm64
6463
6564 archives:
66- - format: zip
67- name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
65+ - name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
6866
6967 changelog:
7068 sort: asc
@@ -12,7 +12,6 @@ builds:
12 binary: gordon12 binary: gordon
13 goos:13 goos:
14 - linux14 - linux
15- - windows
16 - darwin15 - darwin
17 goarch:16 goarch:
18 - amd6417 - amd64
@@ -63,8 +62,7 @@ docker_manifests:
63 - ghcr.io/bnema/gordon:{{ .Tag }}-arm6462 - ghcr.io/bnema/gordon:{{ .Tag }}-arm64
64 63
65 archives:64 archives:
66- - format: zip65+ - name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
67- name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
68 66
69 changelog:67 changelog:
70 sort: asc68 sort: asc
M cmd/root.go +16 -3
@@ -4,13 +4,19 @@ import (
44 "fmt"
55 "os"
66
7- "github.com/rs/zerolog/log"
87 "github.com/spf13/cobra"
98 "github.com/spf13/viper"
109 )
1110
1211 var cfgFile string
1312
13+// Version information set by main.go from goreleaser
14+var (
15+ BuildVersion = "dev"
16+ BuildCommit = "unknown"
17+ BuildDate = "unknown"
18+)
19+
1420 var rootCmd = &cobra.Command{
1521 Use: "gordon",
1622 Short: "Gordon - Container Registry & Deployment System",
@@ -22,6 +28,13 @@ func Execute() error {
2228 return rootCmd.Execute()
2329 }
2430
31+// SetVersionInfo sets the build information from main.go
32+func SetVersionInfo(version, commit, date string) {
33+ BuildVersion = version
34+ BuildCommit = commit
35+ BuildDate = date
36+}
37+
2538 func init() {
2639 cobra.OnInitialize(initConfig)
2740 rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is ./gordon.toml)")
@@ -61,8 +74,8 @@ func initConfig() {
6174 } else {
6275 if cfgFile != "" {
6376 fmt.Fprintf(os.Stderr, "Error reading config file: %v\n", err)
64- } else {
65- log.Fatal().Msg("config file not found - please specify with --config flag or ensure gordon.toml exists in current directory")
6677 }
78+ // Don't fatal for version command - config not needed
79+ // Other commands will check for config when needed
6780 }
6881 }
@@ -4,13 +4,19 @@ import (
4 "fmt"4 "fmt"
5 "os"5 "os"
6 6
7- "github.com/rs/zerolog/log"
8 "github.com/spf13/cobra"7 "github.com/spf13/cobra"
9 "github.com/spf13/viper"8 "github.com/spf13/viper"
10 )9 )
11 10
12 var cfgFile string11 var cfgFile string
13 12
13+// Version information set by main.go from goreleaser
14+var (
15+ BuildVersion = "dev"
16+ BuildCommit = "unknown"
17+ BuildDate = "unknown"
18+)
19+
14 var rootCmd = &cobra.Command{20 var rootCmd = &cobra.Command{
15 Use: "gordon",21 Use: "gordon",
16 Short: "Gordon - Container Registry & Deployment System",22 Short: "Gordon - Container Registry & Deployment System",
@@ -22,6 +28,13 @@ func Execute() error {
22 return rootCmd.Execute()28 return rootCmd.Execute()
23 }29 }
24 30
31+// SetVersionInfo sets the build information from main.go
32+func SetVersionInfo(version, commit, date string) {
33+ BuildVersion = version
34+ BuildCommit = commit
35+ BuildDate = date
36+}
37+
25 func init() {38 func init() {
26 cobra.OnInitialize(initConfig)39 cobra.OnInitialize(initConfig)
27 rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is ./gordon.toml)")40 rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is ./gordon.toml)")
@@ -61,8 +74,8 @@ func initConfig() {
61 } else {74 } else {
62 if cfgFile != "" {75 if cfgFile != "" {
63 fmt.Fprintf(os.Stderr, "Error reading config file: %v\n", err)76 fmt.Fprintf(os.Stderr, "Error reading config file: %v\n", err)
64- } else {
65- log.Fatal().Msg("config file not found - please specify with --config flag or ensure gordon.toml exists in current directory")
66 }77 }
78+ // Don't fatal for version command - config not needed
79+ // Other commands will check for config when needed
67 }80 }
68 }81 }
A cmd/version.go +33 -0
@@ -0,0 +1,33 @@
1+package cmd
2+
3+import (
4+ "fmt"
5+
6+ "github.com/spf13/cobra"
7+)
8+
9+var versionCmd = &cobra.Command{
10+ Use: "version",
11+ Short: "Show version information",
12+ Long: `Display the Gordon version, commit hash, and build date.`,
13+ Run: func(cmd *cobra.Command, args []string) {
14+ fmt.Printf("Gordon %s\n", BuildVersion)
15+ fmt.Printf("Commit: %s\n", BuildCommit)
16+ fmt.Printf("Built: %s\n", BuildDate)
17+ },
18+}
19+
20+func init() {
21+ rootCmd.AddCommand(versionCmd)
22+ versionCmd.Flags().BoolP("short", "s", false, "Show only version number")
23+
24+ // Override run function to handle short flag
25+ originalRun := versionCmd.Run
26+ versionCmd.Run = func(cmd *cobra.Command, args []string) {
27+ if short, _ := cmd.Flags().GetBool("short"); short {
28+ fmt.Println(BuildVersion)
29+ return
30+ }
31+ originalRun(cmd, args)
32+ }
33+}⏎̸
@@ -0,0 +1,33 @@
1+package cmd
2+
3+import (
4+ "fmt"
5+
6+ "github.com/spf13/cobra"
7+)
8+
9+var versionCmd = &cobra.Command{
10+ Use: "version",
11+ Short: "Show version information",
12+ Long: `Display the Gordon version, commit hash, and build date.`,
13+ Run: func(cmd *cobra.Command, args []string) {
14+ fmt.Printf("Gordon %s\n", BuildVersion)
15+ fmt.Printf("Commit: %s\n", BuildCommit)
16+ fmt.Printf("Built: %s\n", BuildDate)
17+ },
18+}
19+
20+func init() {
21+ rootCmd.AddCommand(versionCmd)
22+ versionCmd.Flags().BoolP("short", "s", false, "Show only version number")
23+
24+ // Override run function to handle short flag
25+ originalRun := versionCmd.Run
26+ versionCmd.Run = func(cmd *cobra.Command, args []string) {
27+ if short, _ := cmd.Flags().GetBool("short"); short {
28+ fmt.Println(BuildVersion)
29+ return
30+ }
31+ originalRun(cmd, args)
32+ }
33+}⏎̸
M main.go +10 -0
@@ -6,7 +6,17 @@ import (
66 "gordon/cmd"
77 )
88
9+// Build information set by goreleaser via ldflags
10+var (
11+ version = "dev"
12+ commit = "unknown"
13+ date = "unknown"
14+)
15+
916 func main() {
17+ // Set version information for the CLI
18+ cmd.SetVersionInfo(version, commit, date)
19+
1020 if err := cmd.Execute(); err != nil {
1121 os.Exit(1)
1222 }
@@ -6,7 +6,17 @@ import (
6 "gordon/cmd"6 "gordon/cmd"
7 )7 )
8 8
9+// Build information set by goreleaser via ldflags
10+var (
11+ version = "dev"
12+ commit = "unknown"
13+ date = "unknown"
14+)
15+
9 func main() {16 func main() {
17+ // Set version information for the CLI
18+ cmd.SetVersionInfo(version, commit, date)
19+
10 if err := cmd.Execute(); err != nil {20 if err := cmd.Execute(); err != nil {
11 os.Exit(1)21 os.Exit(1)
12 }22 }

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close