detached 6f8e085

Refactor: Update version handling and build process for improved consistency

commit
6f8e085883ff3594cd061a15c7fa659e35638ea0
author
bamen · · 2024-09-27 05:55 UTC
parent
4a603f2
signature
unsigned
4 files · +15 -12
M build-dev.sh +2 -2
@@ -14,7 +14,7 @@ rm -f $DIST_DIR/*
1414
1515 # Build Go binaries for multiple platforms with CGO_ENABLED=0
1616 echo "Building Go binaries..."
17-CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $DIST_DIR/gordon-linux-amd64 ./cmd/cli
18-CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o $DIST_DIR/gordon-linux-arm64 ./cmd/cli
17+CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $DIST_DIR/gordon-linux-amd64 ./main.go
18+CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o $DIST_DIR/gordon-linux-arm64 ./main.go
1919
2020 echo "Successfully built Go binaries"
@@ -14,7 +14,7 @@ rm -f $DIST_DIR/*
14 14
15 # Build Go binaries for multiple platforms with CGO_ENABLED=015 # Build Go binaries for multiple platforms with CGO_ENABLED=0
16 echo "Building Go binaries..."16 echo "Building Go binaries..."
17-CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $DIST_DIR/gordon-linux-amd64 ./cmd/cli17+CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $DIST_DIR/gordon-linux-amd64 ./main.go
18-CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o $DIST_DIR/gordon-linux-arm64 ./cmd/cli18+CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o $DIST_DIR/gordon-linux-arm64 ./main.go
19 19
20 echo "Successfully built Go binaries"20 echo "Successfully built Go binaries"
M internal/cli/cmd/version.go +3 -3
@@ -12,11 +12,11 @@ func NewVersionCommand(a *cli.App) *cobra.Command {
1212 Use: "version",
1313 Short: "Display the version of Gordon",
1414 Run: func(cmd *cobra.Command, args []string) {
15- version := a.Config.GetVersion()
15+ version := a.Config.Build.BuildVersion
1616 if version == "" {
17- fmt.Println("Version : devel")
17+ fmt.Println("Version: devel")
1818 } else {
19- fmt.Printf("Version : %s\n", version)
19+ fmt.Printf("Version: %s\n", version)
2020 }
2121 },
2222 }
@@ -12,11 +12,11 @@ func NewVersionCommand(a *cli.App) *cobra.Command {
12 Use: "version",12 Use: "version",
13 Short: "Display the version of Gordon",13 Short: "Display the version of Gordon",
14 Run: func(cmd *cobra.Command, args []string) {14 Run: func(cmd *cobra.Command, args []string) {
15- version := a.Config.GetVersion()15+ version := a.Config.Build.BuildVersion
16 if version == "" {16 if version == "" {
17- fmt.Println("Version : devel")17+ fmt.Println("Version: devel")
18 } else {18 } else {
19- fmt.Printf("Version : %s\n", version)19+ fmt.Printf("Version: %s\n", version)
20 }20 }
21 },21 },
22 }22 }
M internal/common/initconfig.go +0 -5
@@ -214,11 +214,6 @@ func (config *BuildConfig) GetRunEnv() string {
214214 return config.RunEnv
215215 }
216216
217-// GetVersion returns the version
218-func (config *Config) GetVersion() string {
219- return config.Build.BuildVersion
220-}
221-
222217 // get storage dir
223218 func (config *Config) GetStorageDir() string {
224219 return config.General.StorageDir
@@ -214,11 +214,6 @@ func (config *BuildConfig) GetRunEnv() string {
214 return config.RunEnv214 return config.RunEnv
215 }215 }
216 216
217-// GetVersion returns the version
218-func (config *Config) GetVersion() string {
219- return config.Build.BuildVersion
220-}
221-
222 // get storage dir217 // get storage dir
223 func (config *Config) GetStorageDir() string {218 func (config *Config) GetStorageDir() string {
224 return config.General.StorageDir219 return config.General.StorageDir
M internal/common/version.go +10 -2
@@ -4,12 +4,12 @@ import (
44 "encoding/json"
55 "fmt"
66 "io"
7- "log"
87 "net/http"
98 "runtime"
109 "time"
1110
1211 "github.com/bnema/gordon/pkg/docker"
12+ "github.com/charmbracelet/log"
1313 )
1414
1515 type CurrentVersion struct {
@@ -76,6 +76,14 @@ func checkAndUpdateVersion(c *Config) (string, error) {
7676 return message, nil
7777 }
7878
79+// GetVersion returns the version
80+func (c *Config) GetVersion() string {
81+ if c.Build.BuildVersion != "" {
82+ return c.Build.BuildVersion
83+ }
84+ return "devel"
85+}
86+
7987 func CheckVersionPeriodically(c *Config) (string, error) {
8088 // Check if version is "devel"
8189 if c.GetVersion() == "devel" {
@@ -90,7 +98,7 @@ func CheckVersionPeriodically(c *Config) (string, error) {
9098 }
9199
92100 if newVersionMessage != "" {
93- fmt.Println(newVersionMessage)
101+ log.Info(newVersionMessage)
94102 return "", nil
95103 }
96104
@@ -4,12 +4,12 @@ import (
4 "encoding/json"4 "encoding/json"
5 "fmt"5 "fmt"
6 "io"6 "io"
7- "log"
8 "net/http"7 "net/http"
9 "runtime"8 "runtime"
10 "time"9 "time"
11 10
12 "github.com/bnema/gordon/pkg/docker"11 "github.com/bnema/gordon/pkg/docker"
12+ "github.com/charmbracelet/log"
13 )13 )
14 14
15 type CurrentVersion struct {15 type CurrentVersion struct {
@@ -76,6 +76,14 @@ func checkAndUpdateVersion(c *Config) (string, error) {
76 return message, nil76 return message, nil
77 }77 }
78 78
79+// GetVersion returns the version
80+func (c *Config) GetVersion() string {
81+ if c.Build.BuildVersion != "" {
82+ return c.Build.BuildVersion
83+ }
84+ return "devel"
85+}
86+
79 func CheckVersionPeriodically(c *Config) (string, error) {87 func CheckVersionPeriodically(c *Config) (string, error) {
80 // Check if version is "devel"88 // Check if version is "devel"
81 if c.GetVersion() == "devel" {89 if c.GetVersion() == "devel" {
@@ -90,7 +98,7 @@ func CheckVersionPeriodically(c *Config) (string, error) {
90 }98 }
91 99
92 if newVersionMessage != "" {100 if newVersionMessage != "" {
93- fmt.Println(newVersionMessage)101+ log.Info(newVersionMessage)
94 return "", nil102 return "", nil
95 }103 }
96 104

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