Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: publish

on:
push:
tags:
- '*'

jobs:
publish:
strategy:
matrix:
go-version: [ 1.15.x ]
os: [ ubuntu-latest ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@master
with:
fetch-depth: 1
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Make all
run: make all
- name: Upload release binaries
uses: alexellis/[email protected]
env:
GITHUB_TOKEN: ${{ github.token }}
with:
asset_paths: '["./dist/redis-benchmark-go_*"]'
19 changes: 16 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,23 @@ GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
GOFMT=$(GOCMD) fmt
DISTDIR = ./dist
OS_ARCHs = "linux/amd64 linux/arm64 windows/amd64 darwin/amd64 darwin/arm64"

# Build-time GIT variables
ifeq ($(GIT_SHA),)
GIT_SHA:=$(shell git rev-parse HEAD)
endif

ifeq ($(GIT_DIRTY),)
GIT_DIRTY:=$(shell git diff --no-ext-diff 2> /dev/null | wc -l)
endif

.PHONY: all test coverage
all: test coverage build
all: test build release

build:
$(GOBUILD) .
$(GOBUILD) \
-ldflags="-X 'main.GitSHA1=$(GIT_SHA)' -X 'main.GitDirty=$(GIT_DIRTY)'" .

checkfmt:
@echo 'Checking gofmt';\
Expand Down Expand Up @@ -42,7 +53,9 @@ coverage: get test
release:
$(GOGET) github.com/mitchellh/gox
$(GOGET) github.com/tcnksm/ghr
GO111MODULE=on gox -osarch "linux/amd64 linux/arm64 windows/amd64 darwin/amd64 darwin/arm64" -output "${DISTDIR}/redis-benchmark-go_{{.OS}}_{{.Arch}}" .
GO111MODULE=on gox -osarch ${OS_ARCHs} \
-ldflags="-X 'main.GitSHA1=$(GIT_SHA)' -X 'main.GitDirty=$(GIT_DIRTY)'" \
-output "${DISTDIR}/redis-benchmark-go_{{.OS}}_{{.Arch}}" .

publish: release
@for f in $(shell ls ${DISTDIR}); \
Expand Down
23 changes: 23 additions & 0 deletions bin_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main

import (
"strconv"
"strings"
)

// Vars only for git sha and diff handling
var GitSHA1 string = ""
var GitDirty string = "0"

func toolGitSHA1() string {
return GitSHA1
}

func toolGitDirty() (dirty bool) {
dirty = false
dirtyLines, err := strconv.Atoi(strings.TrimSpace(GitDirty))
if err == nil {
dirty = (dirtyLines != 0)
}
return
}
10 changes: 10 additions & 0 deletions redis-bechmark-go.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,17 @@ func main() {
multi := flag.Bool("multi", false, "Run each command in multi-exec.")
clusterMode := flag.Bool("oss-cluster", false, "Enable OSS cluster mode.")
loop := flag.Bool("l", false, "Loop. Run the tests forever.")
version := flag.Bool("v", false, "Output version and exit")
flag.Parse()
git_sha := toolGitSHA1()
git_dirty_str := ""
if toolGitDirty() {
git_dirty_str = "-dirty"
}
if *version {
fmt.Fprintf(os.Stdout, "redis-benchmark-go (git_sha1:%s%s)\n", git_sha, git_dirty_str)
os.Exit(0)
}
args := flag.Args()
if len(args) < 2 {
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 )")
Expand Down