-
Notifications
You must be signed in to change notification settings - Fork 9
127 lines (106 loc) · 3.43 KB
/
go.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
name: Go
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.23
- name: Build
run: go build -v ./...
- name: Test
run: go test -v ./...
cache-main-benchmark:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v3
- name: Cache Main Branch Benchmarks
id: cache-benchmark
uses: actions/cache@v3
with:
path: ./main_benchmarks.txt
key: main-benchmarks-${{ runner.os }}-${{ github.sha }}
restore-keys: |
main-benchmarks-${{ runner.os }}-
- name: Run Benchmarks on Main Branch (if no cache)
if: steps.cache-benchmark.outputs.cache-hit != 'true'
run: |
git fetch origin main
git checkout origin/main
go test -bench . -benchmem -run=^$ ./... > main_benchmarks.txt
continue-on-error: true
- name: Save Main Benchmark Results
uses: actions/upload-artifact@v3
with:
name: main_benchmarks
path: main_benchmarks.txt
run-pr-benchmark:
runs-on: ubuntu-latest
needs: cache-main-benchmark
steps:
- uses: actions/checkout@v3
- name: Run Benchmarks on PR Branch
run: |
go test -bench . -benchmem -run=^$ ./... > pr_benchmarks.txt
continue-on-error: true
- name: Save PR Benchmark Results
uses: actions/upload-artifact@v3
with:
name: pr_benchmarks
path: pr_benchmarks.txt
compare-benchmarks:
runs-on: ubuntu-latest
needs: run-pr-benchmark
steps:
- uses: actions/checkout@v3
- name: Download Main and PR Benchmark Results
uses: actions/download-artifact@v3
with:
name: main_benchmarks
- uses: actions/download-artifact@v3
with:
name: pr_benchmarks
- name: Compare Benchmarks
id: benchmark-compare
run: |
echo "Comparing benchmarks..."
diff_output=$(diff ./main_benchmarks.txt ./pr_benchmarks.txt || true)
echo "$diff_output" > ./diff_output.txt
cat ./diff_output.txt
- name: Display Benchmark Results
run: |
echo "Benchmark results for PR branch:"
cat ./pr_benchmarks.txt
echo ""
echo "Benchmark results for Main branch:"
cat ./main_benchmarks.txt
- name: Comment on PR with Benchmark Comparison
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const diff = fs.readFileSync('diff_output.txt', 'utf8');
if (diff) {
github.rest.issues.createComment({
issue_number: context.payload.pull_request.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `### Benchmark Comparison:\n\`\`\`\n${diff}\n\`\`\``
});
} else {
github.rest.issues.createComment({
issue_number: context.payload.pull_request.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `### Benchmark Comparison:\nNo differences found.`
});
}