diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 731d3fd..d09a907 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -194,8 +194,6 @@ jobs: with: go-version: '1.22.7' cache: false - - name: Set CLI version number - run: bash ./scripts/set-cli-version.sh test - name: Run build script run: make build @@ -220,8 +218,6 @@ jobs: with: go-version: '1.22.7' cache: false - - name: Set CLI version number - run: bash ./scripts/set-cli-version.sh test - name: Run build script run: make build @@ -246,8 +242,6 @@ jobs: with: go-version: '1.22.7' cache: false - - name: Set CLI version number - run: bash ./scripts/set-cli-version.sh test - name: Run build script run: make build @@ -272,8 +266,6 @@ jobs: with: go-version: '1.22.7' cache: false - - name: Set CLI version number - run: bash ./scripts/set-cli-version.sh test - name: Run build script run: make build @@ -298,8 +290,6 @@ jobs: with: go-version: '1.22.7' cache: false - - name: Set CLI version number - run: bash ./scripts/set-cli-version.sh test - name: Run build script run: make build @@ -324,7 +314,5 @@ jobs: with: go-version: '1.22.7' cache: false - - name: Set CLI version number - run: bash ./scripts/set-cli-version.sh test - name: Run build script run: make build diff --git a/.github/workflows/release-cli.yml b/.github/workflows/release-cli.yml index 958e996..91c18f4 100644 --- a/.github/workflows/release-cli.yml +++ b/.github/workflows/release-cli.yml @@ -45,10 +45,8 @@ jobs: with: go-version: '1.22.7' cache: false - - name: Set CLI version number - run: bash ./scripts/set-cli-version.sh ${{ steps.tagName.outputs.tag }} - name: Run build script - run: make build + run: make build VERSION=${{ steps.tagName.outputs.tag }} - name: Append os/arch to binary file name run: mv bin/kubetail bin/kubetail-${{ matrix.GOOS }}-${{ matrix.GOARCH }} - name: Calculate sha256 checksum diff --git a/Makefile b/Makefile index 8d8e386..337583a 100644 --- a/Makefile +++ b/Makefile @@ -26,6 +26,12 @@ else GOARCH := $(ARCH) endif +# Allow version override via CLI argument (default to "dev") +VERSION ?= dev + +# Define ldflags +LDFLAGS := -ldflags="-s -w -X 'github.com/kubetail-org/kubetail/modules/cli/cmd.version=$(VERSION)'" + # Default target all: build @@ -46,20 +52,20 @@ build-dashboard-ui: # Build CLI binary for host platform build-cli: build-dashboard-ui @echo "Building kubetail CLI binary..." - @cd $(CLI_DIR) && GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=0 go build -ldflags="-s -w" -o ../../$(OUTPUT_DIR)/$(CLI_BINARY) ./main.go + @cd $(CLI_DIR) && GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=0 go build $(LDFLAGS) -o ../../$(OUTPUT_DIR)/$(CLI_BINARY) ./main.go # Build all the CLI binaries build-cli-all: build-dashboard-ui @echo "Building kubetail CLI binaries..." - @cd $(CLI_DIR) && GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-s -w" -o ../../$(OUTPUT_DIR)/$(CLI_BINARY)-darwin-amd64 ./main.go + @cd $(CLI_DIR) && GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build $(LDFLAGS) -o ../../$(OUTPUT_DIR)/$(CLI_BINARY)-darwin-amd64 ./main.go @echo "Built kubetail for darwin-amd64." - @cd $(CLI_DIR) && GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 go build -ldflags="-s -w" -o ../../$(OUTPUT_DIR)/$(CLI_BINARY)-darwin-arm64 ./main.go + @cd $(CLI_DIR) && GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 go build $(LDFLAGS) -o ../../$(OUTPUT_DIR)/$(CLI_BINARY)-darwin-arm64 ./main.go @echo "Built kubetail for darwin-arm64." - @cd $(CLI_DIR) && GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-s -w" -o ../../$(OUTPUT_DIR)/$(CLI_BINARY)-linux-amd64 ./main.go + @cd $(CLI_DIR) && GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build $(LDFLAGS) -o ../../$(OUTPUT_DIR)/$(CLI_BINARY)-linux-amd64 ./main.go @echo "Built kubetail for linux-amd64." - @cd $(CLI_DIR) && GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -ldflags="-s -w" -o ../../$(OUTPUT_DIR)/$(CLI_BINARY)-linux-arm64 ./main.go + @cd $(CLI_DIR) && GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build $(LDFLAGS) -o ../../$(OUTPUT_DIR)/$(CLI_BINARY)-linux-arm64 ./main.go @echo "Built kubetail for linux-arm64." - @cd $(CLI_DIR) && GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-s -w" -o ../../$(OUTPUT_DIR)/$(CLI_BINARY)-windows-adm64 ./main.go + @cd $(CLI_DIR) && GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build $(LDFLAGS) -o ../../$(OUTPUT_DIR)/$(CLI_BINARY)-windows-adm64 ./main.go @echo "Built kubetail for windows-amd64." @echo "Kubetail CLI binaries built successfully." diff --git a/modules/cli/cmd/root.go b/modules/cli/cmd/root.go index 76afb22..b5b1003 100644 --- a/modules/cli/cmd/root.go +++ b/modules/cli/cmd/root.go @@ -20,10 +20,12 @@ import ( "github.com/spf13/cobra" ) +var version = "dev" // default version for local builds + // rootCmd represents the base command when called without any subcommands var rootCmd = &cobra.Command{ Use: "kubetail", - Version: "dev", + Version: version, Short: "Kubetail - Kubernetes logging utility", } diff --git a/scripts/set-cli-version.sh b/scripts/set-cli-version.sh deleted file mode 100644 index 1c0e65c..0000000 --- a/scripts/set-cli-version.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -# Check if a version number was provided as an argument -if [ "$#" -ne 1 ]; then - echo "Usage: $0 " - exit 1 -fi - -# Assign the new version number from command line arguments -NEW_VERSION=$1 -CLI_ROOT_GO_FILE="./modules/cli/cmd/root.go" - -# Check if the file exists -if [ ! -f "$CLI_ROOT_GO_FILE" ]; then - echo "Error: File $CLI_ROOT_GO_FILE not found." - exit 1 -fi - -# Update the Version field in the root.go file -sed -i.bak -E "s/(Version: )\"[^\"]*\"/\1\"$NEW_VERSION\"/" "$CLI_ROOT_GO_FILE" && rm "$CLI_ROOT_GO_FILE.bak" - -echo "Version in $CLI_ROOT_GO_FILE updated to '$NEW_VERSION'."