From ddc5af94408c7fa5b48ea089ac9ddc7eb829f420 Mon Sep 17 00:00:00 2001 From: Maximilian Breithecker <72022235+mbreithecker@users.noreply.github.com> Date: Wed, 30 Oct 2024 09:21:24 +0100 Subject: [PATCH] chore: add version command (#20) --- Makefile | 17 +++++++++++------ cmd/dlt/commands/version.go | 25 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 cmd/dlt/commands/version.go diff --git a/Makefile b/Makefile index ba0a557..80121ba 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,12 @@ COMMIT := $(shell git log -1 --format='%H') -VERSION := 0.2 # $(shell echo $(shell git describe --tags) | sed 's/^v//') +VERSION := 1.0.0 # $(shell echo $(shell git describe --tags) | sed 's/^v//') -ldflags = -X main.AppName=dlt \ - -X main.Version=$(VERSION) \ - -X main.Commit=$(COMMIT) +ldflags = -X github.com/KYVENetwork/KYVE-DLT/cmd/dlt/commands.Version=$(VERSION) \ + -X github.com/KYVENetwork/KYVE-DLT/cmd/dlt/commands.Commit=$(COMMIT) \ + -s \ + -w -BUILD_FLAGS := -ldflags '$(ldflags)' -trimpath +BUILD_FLAGS := -ldflags '$(ldflags)' -trimpath -buildvcs=false .PHONY: build format lint release @@ -17,7 +18,7 @@ all: format lint build build: @echo "🤖 Building KYVE-DLT ..." - @go build $(BUILD_FLAGS) -o "$(PWD)/build/" ./cmd/dlt + @CGO_ENABLED=0 go build $(BUILD_FLAGS) -o "$(PWD)/build/" ./cmd/dlt @echo "✅ Completed build!" ############################################################################### @@ -47,5 +48,9 @@ release: @tar -czf release/dlt_linux_arm64.tar.gz dlt @shasum -a 256 release/dlt_linux_arm64.tar.gz >> release/release_checksum + @GOOS=linux GOARCH=amd64 go build $(BUILD_FLAGS) ./cmd/dlt + @tar -czf release/dlt_linux_amd64.tar.gz dlt + @shasum -a 256 release/dlt_linux_amd64.tar.gz >> release/release_checksum + @rm dlt @echo "✅ Completed release creation!" \ No newline at end of file diff --git a/cmd/dlt/commands/version.go b/cmd/dlt/commands/version.go new file mode 100644 index 0000000..24771f8 --- /dev/null +++ b/cmd/dlt/commands/version.go @@ -0,0 +1,25 @@ +package commands + +import ( + "fmt" + "github.com/spf13/cobra" +) + +var ( + Version string + Commit string +) + +func init() { + rootCmd.AddCommand(versionCmd) +} + +var versionCmd = &cobra.Command{ + Use: "version", + Short: "Show version and build information", + Run: func(cmd *cobra.Command, args []string) { + fmt.Println("KYVE Data-Load-Tool (DLT)") + fmt.Printf("Version: %s\n", Version) + fmt.Printf("Commit: %s\n", Commit) + }, +}