diff options
| -rw-r--r-- | .github/actions/spelling/allow.txt | 3 | ||||
| -rw-r--r-- | Makefile | 19 | ||||
| -rw-r--r-- | cmd/main.go | 14 | ||||
| -rw-r--r-- | pkg/version/version.go | 45 | ||||
| -rw-r--r-- | pkg/version/version_test.go | 4 |
5 files changed, 65 insertions, 20 deletions
diff --git a/.github/actions/spelling/allow.txt b/.github/actions/spelling/allow.txt index ebcbc27..dca2d8c 100644 --- a/.github/actions/spelling/allow.txt +++ b/.github/actions/spelling/allow.txt @@ -63,6 +63,7 @@ gh ghcr githash github +GOARCH goimports golang golangci @@ -98,6 +99,7 @@ kubefake kubernetes Kustomization kustomize +ldflags LDFLAGS len linted @@ -171,6 +173,7 @@ structcheck svg svi svl +SZ taglist tagsortmode TEMPFILE @@ -1,5 +1,3 @@ -LDFLAGS=-extldflags "-static" - IMAGE_NAMESPACE?=argoprojlabs IMAGE_NAME=argocd-image-updater IMAGE_TAG?=latest @@ -9,6 +7,21 @@ else IMAGE_PREFIX= endif +CURRENT_DIR=$(shell pwd) +VERSION=$(shell cat ${CURRENT_DIR}/VERSION) +GIT_COMMIT=$(shell git rev-parse HEAD) +BUILD_DATE=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ') + +LDFLAGS= + +VERSION_PACKAGE=github.com/argoproj-labs/argocd-image-updater/pkg/version + +override LDFLAGS += -extldflags "-static" +override LDFLAGS += \ + -X ${VERSION_PACKAGE}.version=${VERSION} \ + -X ${VERSION_PACKAGE}.gitCommit=${GIT_COMMIT} \ + -X ${VERSION_PACKAGE}.buildDate=${BUILD_DATE} + .PHONY: all all: prereq controller @@ -43,7 +56,7 @@ prereq: .PHONY: controller controller: - CGO_ENABLED=0 go build -o dist/argocd-image-updater cmd/main.go + CGO_ENABLED=0 go build -ldflags '${LDFLAGS}' -o dist/argocd-image-updater cmd/main.go .PHONY: image image: clean-image mod-vendor diff --git a/cmd/main.go b/cmd/main.go index f5958d9..e4bb9f7 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -170,15 +170,25 @@ func newRootCommand() error { // newVersionCommand implements "version" command func newVersionCommand() *cobra.Command { + var short bool var versionCmd = &cobra.Command{ Use: "version", Short: "Display version information", RunE: func(cmd *cobra.Command, args []string) error { - fmt.Printf("%s\n", version.Useragent()) + if !short { + fmt.Printf("%s\n", version.Useragent()) + fmt.Printf(" BuildDate: %s\n", version.BuildDate()) + fmt.Printf(" GitCommit: %s\n", version.GitCommit()) + fmt.Printf(" GoVersion: %s\n", version.GoVersion()) + fmt.Printf(" GoCompiler: %s\n", version.GoCompiler()) + fmt.Printf(" Platform: %s\n", version.GoPlatform()) + } else { + fmt.Printf("%s\n", version.Version()) + } return nil }, } - + versionCmd.Flags().BoolVar(&short, "short", false, "show only the version number") return versionCmd } diff --git a/pkg/version/version.go b/pkg/version/version.go index 140b016..d9c405a 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -1,21 +1,20 @@ package version -import "fmt" - -const ( - majorVersion = "0" - minorVersion = "7" - patchVersion = "0" - preReleaseString = "master" +import ( + "fmt" + "runtime" + "time" ) -const binaryName = "argocd-image-updater" +var ( + version = "9.9.99" + buildDate = time.Now().UTC().Format(time.RFC3339) + gitCommit = "unknown" + binaryName = "argocd-image-updater" +) func Version() string { - version := fmt.Sprintf("v%s.%s.%s", majorVersion, minorVersion, patchVersion) - if preReleaseString != "" { - version += fmt.Sprintf("-%s", preReleaseString) - } + version := fmt.Sprintf("v%s+%s", version, gitCommit[0:7]) return version } @@ -24,5 +23,25 @@ func BinaryName() string { } func Useragent() string { - return fmt.Sprintf("%s %s", BinaryName(), Version()) + return fmt.Sprintf("%s: %s", BinaryName(), Version()) +} + +func GitCommit() string { + return gitCommit +} + +func BuildDate() string { + return buildDate +} + +func GoVersion() string { + return runtime.Version() +} + +func GoPlatform() string { + return runtime.GOOS + "/" + runtime.GOARCH +} + +func GoCompiler() string { + return runtime.Compiler } diff --git a/pkg/version/version_test.go b/pkg/version/version_test.go index a68c88f..638daa4 100644 --- a/pkg/version/version_test.go +++ b/pkg/version/version_test.go @@ -12,9 +12,9 @@ func Test_BinaryName(t *testing.T) { } func Test_Version(t *testing.T) { - assert.Regexp(t, `^v[0-9]\.[0-9]\.[0-9](-[a-z]+)*$`, Version()) + assert.Regexp(t, `^v[0-9]+\.[0-9]+\.[0-9]+(\-[a-z]+)*(\+[a-z0-9]+)*$`, Version()) } func Test_Useragent(t *testing.T) { - assert.Regexp(t, `^[a-z\-]+\sv[0-9]\.[0-9]\.[0-9](-[a-z]+)*$`, Useragent()) + assert.Regexp(t, `^[a-z\-]+:\sv[0-9]+\.[0-9]+\.[0-9]+(-[a-z]+)*(\+[a-z0-9]+)*$`, Useragent()) } |
