Skip to content

Commit 804db89

Browse files
committed
chore: speed up ci jobs
1 parent a2b9c15 commit 804db89

File tree

2 files changed

+77
-8
lines changed

2 files changed

+77
-8
lines changed

.github/workflows/benchmark.yml

Lines changed: 74 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,44 @@ on:
77
paths:
88
- go.mod
99
- go.sum
10-
- '**.go'
11-
- '!**_test.go'
12-
- '!cloud/testserver/**'
13-
- '**_bench_test.go'
10+
- "**.go"
11+
- "!**_test.go"
12+
- "!cloud/testserver/**"
13+
- "**_bench_test.go"
14+
- .github/workflows/benchmark.yml
1415

1516
permissions:
1617
pull-requests: write
1718

1819
jobs:
20+
discover:
21+
runs-on: blacksmith-4vcpu-ubuntu-2404
22+
outputs:
23+
packages: ${{ steps.find-packages.outputs.packages }}
24+
steps:
25+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # pin@v4
26+
with:
27+
ref: ${{github.event.pull_request.head.ref}}
28+
repository: ${{github.event.pull_request.head.repo.full_name}}
29+
fetch-depth: 0
30+
31+
- name: Find benchmark packages
32+
id: find-packages
33+
run: |
34+
# Find all packages containing benchmark functions (not just files named *_bench_test.go)
35+
packages=$(grep -r --include='*_test.go' -l '^func Benchmark' . || true | xargs -r dirname | sed 's|^\./||' | sort -u | jq -R -s -c 'split("\n") | map(select(length > 0))')
36+
echo "packages=${packages}" >> $GITHUB_OUTPUT
37+
echo "Found packages: ${packages}"
38+
1939
benchmarks:
40+
needs: discover
2041
runs-on: blacksmith-4vcpu-ubuntu-2404
2142

43+
strategy:
44+
fail-fast: false
45+
matrix:
46+
package: ${{ fromJson(needs.discover.outputs.packages) }}
47+
2248
steps:
2349
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # pin@v4
2450
with:
@@ -28,19 +54,60 @@ jobs:
2854

2955
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # pin@v5
3056
with:
31-
go-version-file: 'go.mod'
57+
go-version-file: "go.mod"
58+
59+
- name: Set artifact name
60+
id: artifact
61+
run: |
62+
# Replace / with - for artifact name compatibility
63+
artifact_name=$(echo "${{ matrix.package }}" | tr '/' '-')
64+
echo "name=benchmark-${artifact_name}" >> $GITHUB_OUTPUT
3265
3366
- name: run benchcheck
3467
id: benchmark
68+
run: |
69+
result=$(make bench/check 'pkg=./${{ matrix.package }}' 'parallel=1' 'new=${{ github.event.pull_request.head.sha }}' 'old=${{ github.event.pull_request.base.sha }}')
70+
echo "$result"
71+
echo "## Package: ${{ matrix.package }}" > benchmark-result.txt
72+
echo "$result" >> benchmark-result.txt
73+
74+
- name: Upload benchmark result
75+
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # pin@v4
76+
with:
77+
name: ${{ steps.artifact.outputs.name }}
78+
path: benchmark-result.txt
79+
retention-days: 1
80+
81+
report:
82+
needs: [discover, benchmarks]
83+
runs-on: blacksmith-4vcpu-ubuntu-2404
84+
if: always() && needs.benchmarks.result != 'skipped'
85+
86+
steps:
87+
- name: Download all benchmark results
88+
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # pin@v4
89+
continue-on-error: true
90+
with:
91+
path: benchmark-results
92+
pattern: benchmark-*
93+
94+
- name: Combine results
95+
id: combine
3596
run: |
3697
echo "result<<EOF" >> $GITHUB_OUTPUT
37-
echo "$(make bench/check 'new=${{ github.event.pull_request.head.sha }}' 'old=${{ github.event.pull_request.base.ref }}')" >> $GITHUB_OUTPUT
98+
# Sort and combine all benchmark result files
99+
find benchmark-results -name 'benchmark-result.txt' -type f | sort | while read -r result_file; do
100+
cat "$result_file" >> $GITHUB_OUTPUT
101+
echo "" >> $GITHUB_OUTPUT
102+
echo "---" >> $GITHUB_OUTPUT
103+
echo "" >> $GITHUB_OUTPUT
104+
done
38105
echo "EOF" >> $GITHUB_OUTPUT
39106
40107
- uses: marocchino/sticky-pull-request-comment@331f8f5b4215f0445d3c07b4967662a32a2d3e31 # pin@v2
41108
with:
42109
header: benchmark
43110
message: |
44111
```
45-
${{ steps.benchmark.outputs.result }}
112+
${{ steps.combine.outputs.result }}
46113
```

makefiles/common.mk

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,14 @@ bench/all:
157157
.PHONY: bench/check
158158
bench/check: allocdelta="+20%"
159159
bench/check: timedelta="+20%"
160+
bench/check: count?=20
161+
bench/check: parallel?=1
160162
bench/check: name=github.com/terramate-io/terramate
161163
bench/check: pkg?=./...
162164
bench/check: old?=main
163165
bench/check: new?=$(shell git rev-parse HEAD)
164166
bench/check:
165-
@$(BENCH_CHECK) -mod $(name) -pkg $(pkg) -go-test-flags "-benchmem,-count=20,-run=Bench" \
167+
@$(BENCH_CHECK) -mod $(name) -pkg $(pkg) -go-test-flags "-benchmem,-count=$(count),-run=Bench,-parallel=$(parallel)" \
166168
-old $(old) -new $(new) \
167169
-check allocs/op=$(allocdelta) \
168170
-check time/op=$(timedelta)

0 commit comments

Comments
 (0)