From 8e408c081d55ca22d599c8822504647d5b37323f Mon Sep 17 00:00:00 2001 From: jimchen Date: Thu, 22 Aug 2024 22:52:35 +0800 Subject: [PATCH] fix bench ci --- .github/workflows/benchmark.yaml | 6 +----- Makefile | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/.github/workflows/benchmark.yaml b/.github/workflows/benchmark.yaml index bbaa8a3..ffe9afa 100644 --- a/.github/workflows/benchmark.yaml +++ b/.github/workflows/benchmark.yaml @@ -17,8 +17,6 @@ jobs: matrix: os: [ubuntu-latest] go: ["1.22"] - test-tags: ["-benchmem -bench ."] - test-floder: ["go list ./... | grep benchmarks"] include: - os: ubuntu-latest go-build: ~/.cache/go-build @@ -26,8 +24,6 @@ jobs: runs-on: ${{ matrix.os }} env: GO111MODULE: on - TESTTAGS: ${{ matrix.test-tags }} - TESTFOLDER: ${{ matrix.test-floder }} GOPROXY: https://proxy.golang.org steps: - name: Set up Go ${{ matrix.go }} @@ -51,4 +47,4 @@ jobs: ${{ runner.os }}-go- - name: Benchmark - run: make test + run: make bench diff --git a/Makefile b/Makefile index 93a6298..84a3e53 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,8 @@ GO_VERSION=$(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2) PACKAGES ?= $(shell $(GO) list ./...) VETPACKAGES ?= $(shell $(GO) list ./... | grep -v /examples/) GOFILES := $(shell find . -name "*.go") -TESTFOLDER ?= $(shell $(GO) list ./... | grep -v examples) +TESTFOLDER := $(shell $(GO) list ./... | grep -v examples | grep -v benchmarks) +BENCHFOLDER := $(shell $(GO) list ./... | grep benchmarks) TESTTAGS ?= "" .PHONY: test @@ -30,6 +31,28 @@ test: fi; \ done +.PHONY: bench +# runs benchmarks. +bench: + for d in $(BENCHFOLDER); do \ + $(GO) test -benchmem -bench . -v -covermode=count -coverprofile=profile.out $$d > benchmark.out; \ + cat benchmark.out; \ + if grep -q "^--- FAIL" benchmark.out; then \ + rm tmp.out; \ + exit 1; \ + elif grep -q "build failed" benchmark.out; then \ + rm tmp.out; \ + exit 1; \ + elif grep -q "setup failed" benchmark.out; then \ + rm tmp.out; \ + exit 1; \ + fi; \ + if [ -f profile.out ]; then \ + cat profile.out | grep -v "mode:" >> coverage.out; \ + rm profile.out; \ + fi; \ + done + .PHONY: fmt # Ensure consistent code formatting. fmt: