Skip to content

Commit 7e32428

Browse files
Merge pull request #6 from filipecosta90/release.gh
Kicked off release process via github actions
2 parents b8f39a3 + 3063509 commit 7e32428

File tree

4 files changed

+79
-3
lines changed

4 files changed

+79
-3
lines changed

.github/workflows/publish.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: publish
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
8+
jobs:
9+
publish:
10+
strategy:
11+
matrix:
12+
go-version: [ 1.15.x ]
13+
os: [ ubuntu-latest ]
14+
runs-on: ${{ matrix.os }}
15+
steps:
16+
- uses: actions/checkout@master
17+
with:
18+
fetch-depth: 1
19+
- name: Install Go
20+
uses: actions/setup-go@v2
21+
with:
22+
go-version: ${{ matrix.go-version }}
23+
- name: Make all
24+
run: make all
25+
- name: Upload release binaries
26+
uses: alexellis/[email protected]
27+
env:
28+
GITHUB_TOKEN: ${{ github.token }}
29+
with:
30+
asset_paths: '["./dist/redis-benchmark-go_*"]'

Makefile

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,23 @@ GOGET=$(GOCMD) get
88
GOMOD=$(GOCMD) mod
99
GOFMT=$(GOCMD) fmt
1010
DISTDIR = ./dist
11+
OS_ARCHs = "linux/amd64 linux/arm64 windows/amd64 darwin/amd64 darwin/arm64"
12+
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
1121

1222
.PHONY: all test coverage
13-
all: test coverage build
23+
all: test build release
1424

1525
build:
16-
$(GOBUILD) .
26+
$(GOBUILD) \
27+
-ldflags="-X 'main.GitSHA1=$(GIT_SHA)' -X 'main.GitDirty=$(GIT_DIRTY)'" .
1728

1829
checkfmt:
1930
@echo 'Checking gofmt';\
@@ -42,7 +53,9 @@ coverage: get test
4253
release:
4354
$(GOGET) github.com/mitchellh/gox
4455
$(GOGET) github.com/tcnksm/ghr
45-
GO111MODULE=on gox -osarch "linux/amd64 linux/arm64 windows/amd64 darwin/amd64 darwin/arm64" -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}}" .
4659

4760
publish: release
4861
@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)