Skip to content

Commit 73cb19a

Browse files
ci(GitHub): add testing workflow
* Added .github/workflows/testing.yml w/ jobs test & benchmark.
1 parent 16cc8bc commit 73cb19a

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

.github/workflows/testing.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Test & benchmark
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: actions/checkout@v5
13+
with:
14+
fetch-depth: 0
15+
16+
- name: Setup Go environment
17+
uses: actions/setup-go@v6
18+
with:
19+
go-version: 1.25.1
20+
21+
- name: Run tests
22+
run: |
23+
go mod tidy
24+
go test -v ./...
25+
26+
benchmark:
27+
runs-on: ubuntu-latest
28+
29+
steps:
30+
- uses: actions/checkout@v5
31+
with:
32+
fetch-depth: 0
33+
34+
- name: Setup Go environment
35+
uses: actions/setup-go@v6
36+
with:
37+
go-version: 1.25.1
38+
39+
- name: Install benchstat
40+
run: go install golang.org/x/perf/cmd/benchstat@latest
41+
42+
- name: Run benchmark on base branch
43+
if: github.event_name == 'pull_request'
44+
run: |
45+
git checkout ${{ github.event.pull_request.base.sha }}
46+
go mod tidy
47+
go test -v -run ^$ -bench . -count ${{ vars.GO_BENCHMARK_COUNT }} -benchmem > base-bench.txt
48+
git checkout ${{ github.event.pull_request.head.sha }}
49+
50+
- name: Run benchmark on HEAD commit
51+
run: |
52+
go mod tidy
53+
go test -v -run ^$ -bench . -count ${{ vars.GO_BENCHMARK_COUNT }} -benchmem > head-bench.txt
54+
55+
- name: Compare benchmarks
56+
if: github.event_name == 'pull_request'
57+
run: |
58+
cat > benchmark-comment.md << EOF
59+
## Benchmark comparison w/ base branch
60+
61+
\`\`\`
62+
$(benchstat base-bench.txt head-bench.txt)
63+
\`\`\`
64+
EOF
65+
66+
- name: Comment PR w/ benchmark comparison
67+
if: github.event_name == 'pull_request'
68+
uses: actions/github-script@v8
69+
with:
70+
script: |
71+
github.rest.issues.createComment({
72+
issue_number: context.issue.number,
73+
owner: context.repo.owner,
74+
repo: context.repo.repo,
75+
body: require('fs').readFileSync('benchmark-comment.md', 'utf8')
76+
});

0 commit comments

Comments
 (0)