From b44f0ef22214237f288894d0cb9605978689b84b Mon Sep 17 00:00:00 2001 From: filipecosta90 Date: Sat, 15 May 2021 10:55:15 +0100 Subject: [PATCH 1/2] [add] Kicked off release process via github actions --- .github/workflows/publish.yml | 30 ++++++++++++++++++++++++++++++ Makefile | 5 +++-- 2 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..d93f8ed --- /dev/null +++ b/.github/workflows/publish.yml @@ -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/upload-assets@0.3.0 + env: + GITHUB_TOKEN: ${{ github.token }} + with: + asset_paths: '["./bin/k3sup*"]' diff --git a/Makefile b/Makefile index 4771889..ff5021a 100644 --- a/Makefile +++ b/Makefile @@ -8,9 +8,10 @@ GOGET=$(GOCMD) get GOMOD=$(GOCMD) mod GOFMT=$(GOCMD) fmt DISTDIR = ./dist +OS_ARCHs = "linux/amd64 linux/arm64 windows/amd64 darwin/amd64 darwin/arm64" .PHONY: all test coverage -all: test coverage build +all: test build release build: $(GOBUILD) . @@ -42,7 +43,7 @@ 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} -output "${DISTDIR}/redis-benchmark-go_{{.OS}}_{{.Arch}}" . publish: release @for f in $(shell ls ${DISTDIR}); \ From 30635094d161a16f181d261fe8411e9ef2e02ff7 Mon Sep 17 00:00:00 2001 From: filipecosta90 Date: Sat, 15 May 2021 11:10:21 +0100 Subject: [PATCH 2/2] [add] added git info to the tool and automatic release to gh bins on publish --- .github/workflows/publish.yml | 2 +- Makefile | 16 ++++++++++++++-- bin_info.go | 23 +++++++++++++++++++++++ redis-bechmark-go.go | 10 ++++++++++ 4 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 bin_info.go diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index d93f8ed..b3888d8 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -27,4 +27,4 @@ jobs: env: GITHUB_TOKEN: ${{ github.token }} with: - asset_paths: '["./bin/k3sup*"]' + asset_paths: '["./dist/redis-benchmark-go_*"]' diff --git a/Makefile b/Makefile index ff5021a..554913c 100644 --- a/Makefile +++ b/Makefile @@ -10,11 +10,21 @@ 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 build release build: - $(GOBUILD) . + $(GOBUILD) \ + -ldflags="-X 'main.GitSHA1=$(GIT_SHA)' -X 'main.GitDirty=$(GIT_DIRTY)'" . checkfmt: @echo 'Checking gofmt';\ @@ -43,7 +53,9 @@ coverage: get test release: $(GOGET) github.com/mitchellh/gox $(GOGET) github.com/tcnksm/ghr - GO111MODULE=on gox -osarch ${OS_ARCHs} -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}); \ diff --git a/bin_info.go b/bin_info.go new file mode 100644 index 0000000..c1afb79 --- /dev/null +++ b/bin_info.go @@ -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 +} diff --git a/redis-bechmark-go.go b/redis-bechmark-go.go index e04a6ec..2553c65 100644 --- a/redis-bechmark-go.go +++ b/redis-bechmark-go.go @@ -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 )")