Skip to content

Commit 415f4f1

Browse files
authored
ci: fix encoding benchmarks only on changes (#133)
1 parent 95be34f commit 415f4f1

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

.github/workflows/bechmark.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,15 @@ jobs:
2828
run: GO111MODULE=off go get golang.org/x/perf/cmd/benchstat
2929

3030
- name: Enable encoding benchmarks on changes
31-
run: |
32-
echo "BENCHMARK_ENCODING=$(git diff master HEAD --name-only -- encoding/)" >> $GITHUB_ENV
31+
id: encoding-changed
32+
uses: tj-actions/changed-files@v35
33+
with:
34+
files: encoding/**
3335

3436
- name: Run benchmark
3537
run: go test -bench=. -count=10 -benchmem ./... | tee bench-new.txt
38+
env:
39+
BENCHMARK_ENCODING: ${{ steps.encoding-changed.outputs.any_changed }}
3640

3741
- name: Run benchmark for base code
3842
run: |
@@ -42,6 +46,8 @@ jobs:
4246
go test -bench=. -count=10 -benchmem ./... | tee bench-master.txt
4347
benchstat bench-master.txt
4448
git reset --hard $HEAD
49+
env:
50+
BENCHMARK_ENCODING: ${{ steps.encoding-changed.outputs.any_changed }}
4551

4652
- name: Benchmark stats
4753
id: bench

internal/test/encoding.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net/http"
77
"os"
88
"reflect"
9+
"strconv"
910
"strings"
1011
"testing"
1112

@@ -99,7 +100,7 @@ func BenchmarkEncoding[T any](b *testing.B, opt EncodingOptions[T]) {
99100
}
100101

101102
func BenchmarkDecode[T any](b *testing.B, opt EncodingOptions[T]) {
102-
if os.Getenv("BENCHMARK_ENCODING") == "" {
103+
if ok, _ := strconv.ParseBool(os.Getenv("BENCHMARK_ENCODING")); !ok {
103104
b.SkipNow()
104105
}
105106

@@ -119,7 +120,7 @@ func BenchmarkDecode[T any](b *testing.B, opt EncodingOptions[T]) {
119120
}
120121

121122
func BenchmarkEncode[T any](b *testing.B, opt EncodingOptions[T]) {
122-
if os.Getenv("BENCHMARK_ENCODING") == "" {
123+
if ok, _ := strconv.ParseBool(os.Getenv("BENCHMARK_ENCODING")); !ok {
123124
b.SkipNow()
124125
}
125126

0 commit comments

Comments
 (0)