diff --git a/.github/workflows/build-by-commit.yml b/.github/workflows/build-by-commit.yml index 1e3408b..e630fa8 100644 --- a/.github/workflows/build-by-commit.yml +++ b/.github/workflows/build-by-commit.yml @@ -6,6 +6,9 @@ on: pull_request: branches: [ master ] +env: + ARTIFACT_VERSION: ${{ github.ref }} + jobs: build: diff --git a/.github/workflows/build-by-tag.yml b/.github/workflows/build-by-tag.yml index 2c90144..b261d73 100644 --- a/.github/workflows/build-by-tag.yml +++ b/.github/workflows/build-by-tag.yml @@ -5,6 +5,9 @@ on: tags: - 'v[0-9]+.[0-9]+.[0-9]+' +env: + ARTIFACT_VERSION: ${{ github.ref }} + jobs: build: diff --git a/CHANGELOG.md b/CHANGELOG.md index 52d33c3..1a0946f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Release history +## v0.2.2 + +- Automate binary version + ## v0.2.1 - Improve help tips diff --git a/Makefile b/Makefile index 52f66cb..b523236 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,7 @@ COMMIT := $(shell git rev-parse HEAD) VERSION ?= $(shell git describe --always --tags) GOOS ?= $(shell go env GOOS) GOPATH ?= $(shell go env GOPATH) +ARTIFACT_VERSION ?= local BUILDDIR := $(shell pwd)/out PLATFORMS ?= darwin/amd64 darwin/arm64 linux/amd64 @@ -66,12 +67,12 @@ all: lint build deploy .PHONY: dev dev: CGO_ENABLED := 1 dev: - go build -race -o $(PROJECT) cmd/$(PROJECT)/main.go + go build -race -o $(PROJECT) -ldflags="-X main.Version=$(ARTIFACT_VERSION)" cmd/$(PROJECT)/main.go .PHONY: build build: $(BUILDDIR) cd cmd/$(PROJECT) && \ - GOFLAGS="-trimpath" gox -osarch="$(PLATFORMS)" -output="$(BUILDDIR)/$(PROJECT)-{{.OS}}-{{.Arch}}" && \ + GOFLAGS="-trimpath" gox -ldflags="-X main.Version=$(ARTIFACT_VERSION)" -osarch="$(PLATFORMS)" -output="$(BUILDDIR)/$(PROJECT)-{{.OS}}-{{.Arch}}" && \ cd ../.. .PHONY: lint diff --git a/cmd/kubectl-nsenter/main.go b/cmd/kubectl-nsenter/main.go index dd2bb31..ac48eb3 100644 --- a/cmd/kubectl-nsenter/main.go +++ b/cmd/kubectl-nsenter/main.go @@ -10,10 +10,12 @@ import ( "time" ) +var Version = "local" + func main() { app := &cli.App{ Name: "kubectl-nsenter", - Version: "v0.2.1", + Version: Version, Compiled: time.Now(), Authors: []*cli.Author{ {