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/* | |||
| 14 | 14 | ||
| 15 | 15 | # Build Go binaries for multiple platforms with CGO_ENABLED=0 | |
| 16 | 16 | 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 | |
| 19 | 19 | ||
| 20 | 20 | 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=0 | 15 | # 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/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 ./cmd/cli | 18 | + | 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 { | |||
| 12 | 12 | Use: "version", | |
| 13 | 13 | Short: "Display the version of Gordon", | |
| 14 | 14 | Run: func(cmd *cobra.Command, args []string) { | |
| 15 | - | version := a.Config.GetVersion() | |
| 15 | + | version := a.Config.Build.BuildVersion | |
| 16 | 16 | if version == "" { | |
| 17 | - | fmt.Println("Version : devel") | |
| 17 | + | fmt.Println("Version: devel") | |
| 18 | 18 | } else { | |
| 19 | - | fmt.Printf("Version : %s\n", version) | |
| 19 | + | fmt.Printf("Version: %s\n", version) | |
| 20 | 20 | } | |
| 21 | 21 | }, | |
| 22 | 22 | } | |
| @@ -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 { | |||
| 214 | 214 | 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 | 217 | // get storage dir | |
| 223 | 218 | func (config *Config) GetStorageDir() string { | |
| 224 | 219 | return config.General.StorageDir | |
| @@ -214,11 +214,6 @@ func (config *BuildConfig) GetRunEnv() string { | |||||
| 214 | return config.RunEnv | 214 | 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 dir | 217 | // get storage dir | ||
| 223 | func (config *Config) GetStorageDir() string { | 218 | func (config *Config) GetStorageDir() string { | ||
| 224 | return config.General.StorageDir | 219 | return config.General.StorageDir | ||
M internal/common/version.go +10 -2
| @@ -4,12 +4,12 @@ import ( | |||
| 4 | 4 | "encoding/json" | |
| 5 | 5 | "fmt" | |
| 6 | 6 | "io" | |
| 7 | - | "log" | |
| 8 | 7 | "net/http" | |
| 9 | 8 | "runtime" | |
| 10 | 9 | "time" | |
| 11 | 10 | ||
| 12 | 11 | "github.com/bnema/gordon/pkg/docker" | |
| 12 | + | "github.com/charmbracelet/log" | |
| 13 | 13 | ) | |
| 14 | 14 | ||
| 15 | 15 | type CurrentVersion struct { | |
| @@ -76,6 +76,14 @@ func checkAndUpdateVersion(c *Config) (string, error) { | |||
| 76 | 76 | 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 | 87 | func CheckVersionPeriodically(c *Config) (string, error) { | |
| 80 | 88 | // Check if version is "devel" | |
| 81 | 89 | if c.GetVersion() == "devel" { | |
| @@ -90,7 +98,7 @@ func CheckVersionPeriodically(c *Config) (string, error) { | |||
| 90 | 98 | } | |
| 91 | 99 | ||
| 92 | 100 | if newVersionMessage != "" { | |
| 93 | - | fmt.Println(newVersionMessage) | |
| 101 | + | log.Info(newVersionMessage) | |
| 94 | 102 | return "", nil | |
| 95 | 103 | } | |
| 96 | 104 | ||
| @@ -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, nil | 76 | 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 "", nil | 102 | return "", nil | ||
| 95 | } | 103 | } | ||
| 96 | 104 | ||||