Skip to content

Commit debb4ac

Browse files
committed
Embed git tag as version for version command
1 parent 4624aee commit debb4ac

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22

33
OUTPUT = ecs-task
44
OUTDIR = bin
5-
BUILD_CMD = go build -a -tags netgo -installsuffix netgo --ldflags '-extldflags "-static"'
5+
BUILD_CMD = go build -a -tags netgo -installsuffix netgo -ldflags \
6+
" \
7+
-extldflags '-static' \
8+
-X github.com/h3poteto/ecs-task/cmd.version=$(shell git describe --tag --abbrev=0) \
9+
-X github.com/h3poteto/ecs-task/cmd.revision=$(shell git rev-list -1 HEAD) \
10+
-X github.com/h3poteto/ecs-task/cmd.build=$(shell git describe --tags) \
11+
"
612
ARCHITECTURE = amd64 arm64
7-
VERSION = v1.0.0
13+
VERSION = $(shell git describe --tag --abbrev=0)
814

915
all: mac linux windows
1016

cmd/version.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,20 @@ import (
66
"github.com/spf13/cobra"
77
)
88

9+
var (
10+
version string
11+
revision string
12+
build string
13+
)
14+
915
func versionCmd() *cobra.Command {
1016
cmd := &cobra.Command{
1117
Use: "version",
1218
Short: "Print the version number",
1319
Run: func(cmd *cobra.Command, args []string) {
14-
fmt.Println("ecs-task v0.2.7")
20+
fmt.Printf("Version : %s\n", version)
21+
fmt.Printf("Revision: %s\n", revision)
22+
fmt.Printf("Build : %s\n", build)
1523
},
1624
}
1725

0 commit comments

Comments
 (0)