Skip to content

Commit

Permalink
Make CLI tool version configurable via Makefile (#146)
Browse files Browse the repository at this point in the history
* Uses variable for version in cli `cmd` package
* Makes variable configurable at compile-time via ldflags in Makefile
* Switches GitHub workflows to using Makefile argument
* Removes unnecessary set-cli-version.sh script
  • Loading branch information
amorey authored Nov 24, 2024
1 parent 786594a commit 2b031d8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 44 deletions.
12 changes: 0 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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
4 changes: 1 addition & 3 deletions .github/workflows/release-cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 12 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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."

Expand Down
4 changes: 3 additions & 1 deletion modules/cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}

Expand Down
22 changes: 0 additions & 22 deletions scripts/set-cli-version.sh

This file was deleted.

0 comments on commit 2b031d8

Please sign in to comment.