Skip to content

Commit 3063509

Browse files
committed
[add] added git info to the tool and automatic release to gh bins on publish
1 parent b44f0ef commit 3063509

File tree

4 files changed

+48
-3
lines changed

4 files changed

+48
-3
lines changed

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ jobs:
2727
env:
2828
GITHUB_TOKEN: ${{ github.token }}
2929
with:
30-
asset_paths: '["./bin/k3sup*"]'
30+
asset_paths: '["./dist/redis-benchmark-go_*"]'

Makefile

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,21 @@ GOFMT=$(GOCMD) fmt
1010
DISTDIR = ./dist
1111
OS_ARCHs = "linux/amd64 linux/arm64 windows/amd64 darwin/amd64 darwin/arm64"
1212

13+
# Build-time GIT variables
14+
ifeq ($(GIT_SHA),)
15+
GIT_SHA:=$(shell git rev-parse HEAD)
16+
endif
17+
18+
ifeq ($(GIT_DIRTY),)
19+
GIT_DIRTY:=$(shell git diff --no-ext-diff 2> /dev/null | wc -l)
20+
endif
21+
1322
.PHONY: all test coverage
1423
all: test build release
1524

1625
build:
17-
$(GOBUILD) .
26+
$(GOBUILD) \
27+
-ldflags="-X 'main.GitSHA1=$(GIT_SHA)' -X 'main.GitDirty=$(GIT_DIRTY)'" .
1828

1929
checkfmt:
2030
@echo 'Checking gofmt';\
@@ -43,7 +53,9 @@ coverage: get test
4353
release:
4454
$(GOGET) github.com/mitchellh/gox
4555
$(GOGET) github.com/tcnksm/ghr
46-
GO111MODULE=on gox -osarch ${OS_ARCHs} -output "${DISTDIR}/redis-benchmark-go_{{.OS}}_{{.Arch}}" .
56+
GO111MODULE=on gox -osarch ${OS_ARCHs} \
57+
-ldflags="-X 'main.GitSHA1=$(GIT_SHA)' -X 'main.GitDirty=$(GIT_DIRTY)'" \
58+
-output "${DISTDIR}/redis-benchmark-go_{{.OS}}_{{.Arch}}" .
4759

4860
publish: release
4961
@for f in $(shell ls ${DISTDIR}); \

bin_info.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package main
2+
3+
import (
4+
"strconv"
5+
"strings"
6+
)
7+
8+
// Vars only for git sha and diff handling
9+
var GitSHA1 string = ""
10+
var GitDirty string = "0"
11+
12+
func toolGitSHA1() string {
13+
return GitSHA1
14+
}
15+
16+
func toolGitDirty() (dirty bool) {
17+
dirty = false
18+
dirtyLines, err := strconv.Atoi(strings.TrimSpace(GitDirty))
19+
if err == nil {
20+
dirty = (dirtyLines != 0)
21+
}
22+
return
23+
}

redis-bechmark-go.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,17 @@ func main() {
128128
multi := flag.Bool("multi", false, "Run each command in multi-exec.")
129129
clusterMode := flag.Bool("oss-cluster", false, "Enable OSS cluster mode.")
130130
loop := flag.Bool("l", false, "Loop. Run the tests forever.")
131+
version := flag.Bool("v", false, "Output version and exit")
131132
flag.Parse()
133+
git_sha := toolGitSHA1()
134+
git_dirty_str := ""
135+
if toolGitDirty() {
136+
git_dirty_str = "-dirty"
137+
}
138+
if *version {
139+
fmt.Fprintf(os.Stdout, "redis-benchmark-go (git_sha1:%s%s)\n", git_sha, git_dirty_str)
140+
os.Exit(0)
141+
}
132142
args := flag.Args()
133143
if len(args) < 2 {
134144
log.Fatalf("You need to specify a command after the flag command arguments. The commands requires a minimum size of 2 ( command name and key )")

0 commit comments

Comments
 (0)