diff --git a/.goreleaser.yaml b/.goreleaser.yaml index a184e406..60599324 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -4,7 +4,10 @@ builds: - binary: csctl goos: - linux + - darwin goarch: - amd64 + - arm64 env: - CGO_ENABLED=0 + ldflags: -w -s -X github.com/SovereignCloudStack/csmctl/pkg/cmd.Version={{.Version}} -X github.com/SovereignCloudStack/csmctl/pkg/cmd.Commit={{.Commit}} \ No newline at end of file diff --git a/Makefile b/Makefile index 08abf7a6..c04a4d4e 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,9 @@ ARCH ?= amd64 IMAGE_PREFIX ?= ghcr.io/sovereigncloudstack BUILDER_IMAGE = $(IMAGE_PREFIX)/csctl-builder BUILDER_IMAGE_VERSION = $(shell cat .builder-image-version.txt) +Version := $(shell git describe --tags --always --dirty) +Commit := $(shell git rev-parse HEAD) +LDFLAGS := -X github.com/SovereignCloudStack/csmctl/pkg/cmd.Version=$(Version) -X github.com/SovereignCloudStack/csmctl/pkg/cmd.Commit=$(Commit) # Certain aspects of the build are done in containers for consistency (e.g. protobuf generation) # If you have the correct tools installed and you want to speed up development you can run @@ -39,13 +42,23 @@ TOOLS_BIN_DIR := $(TOOLS_DIR)/$(BIN_DIR) export PATH := $(abspath $(TOOLS_BIN_DIR)):$(PATH) export GOBIN := $(abspath $(TOOLS_BIN_DIR)) +##@ Clean +######### +# Clean # +######### + +.PHONY: clean +clean: ## cleans the csmctl binary + @if [ -f csmctl ]; then rm csmctl; fi + + ##@ Common ########## # Common # ########## .PHONY: build -build: ## build the csctl binary - go build -o csctl main.go +build: # build the csmctl binary + go build -ldflags "$(LDFLAGS)" -o csmctl main.go .PHONY: lint-golang lint-golang: ## Lint Golang codebase diff --git a/pkg/clusterstack/mode.go b/pkg/clusterstack/mode.go index c0a1fdf9..84c27156 100644 --- a/pkg/clusterstack/mode.go +++ b/pkg/clusterstack/mode.go @@ -1,3 +1,19 @@ +/* +Copyright 2024 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + package clusterstack import ( diff --git a/pkg/cmd/root.go b/pkg/cmd/root.go index 95503df4..998d72ff 100644 --- a/pkg/cmd/root.go +++ b/pkg/cmd/root.go @@ -42,4 +42,5 @@ func Execute() { func init() { rootCmd.AddCommand(createCmd) + rootCmd.AddCommand(versionCmd) } diff --git a/pkg/cmd/version.go b/pkg/cmd/version.go new file mode 100644 index 00000000..3fd03f59 --- /dev/null +++ b/pkg/cmd/version.go @@ -0,0 +1,42 @@ +/* +Copyright 2024 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +var ( + // Version of csctl. + Version = "dev" + // Commit against which csctl version is cut. + Commit = "unknown" +) + +var versionCmd = &cobra.Command{ + Use: "version", + Short: "prints the latest version of csmctl", + Run: printVersion, + SilenceUsage: true, +} + +func printVersion(_ *cobra.Command, _ []string) { + fmt.Println("csmctl version:", Version) + fmt.Println("commit:", Commit) +} diff --git a/pkg/template/template.go b/pkg/template/template.go index b185bd89..3471b98b 100644 --- a/pkg/template/template.go +++ b/pkg/template/template.go @@ -31,7 +31,7 @@ type CustomWalkFunc func(src, dst, path string, info os.FileInfo, meta *csctlclu // MyWalk is the custom walking function to walk in the cluster stacks. func MyWalk(src, dst string, walkFn CustomWalkFunc, meta *csctlclusterstack.MetaData) error { - if err := filepath.Walk(src, func(path string, info os.FileInfo, err error) error { + if err := filepath.Walk(src, func(path string, info os.FileInfo, _ error) error { return walkFn(src, dst, path, info, meta) }); err != nil { return fmt.Errorf("failed to walk files: %w", err)