35
35
with :
36
36
filters : |
37
37
build: '**'
38
- bench:
38
+ bench:
39
39
- 'test/bench/**'
40
40
- 'pkg/**'
41
41
- 'server/**'
54
54
runs-on : ubuntu-latest
55
55
56
56
needs : ci-target-check
57
- if : ${{ needs.ci-target-check.outputs.build == 'true' }}
57
+ if : ${{ github.ref == 'refs/heads/main' || needs.ci-target-check.outputs.build == 'true' }}
58
58
59
59
steps :
60
60
- name : Set up Go ${{ env.GO_VERSION }}
@@ -101,7 +101,7 @@ jobs:
101
101
permissions : write-all
102
102
103
103
needs : ci-target-check
104
- if : ${{ needs.ci-target-check.outputs.bench == 'true' }}
104
+ if : ${{ github.ref == 'refs/heads/main' || needs.ci-target-check.outputs.bench == 'true' }}
105
105
106
106
steps :
107
107
- name : Set up Go ${{ env.GO_VERSION }}
@@ -116,32 +116,69 @@ jobs:
116
116
run : docker compose -f build/docker/docker-compose.yml up --build -d
117
117
118
118
- name : Bench
119
- run : make bench
119
+ id : curr-bench
120
+ run : |
121
+ make bench
122
+ content=$(cat output.txt | jq -R -s .)
123
+ echo "BENCH_RESULT=$content" >> $GITHUB_OUTPUT
120
124
121
- - name : Download previous benchmark data
125
+ - name : Set up cache
122
126
uses : actions/cache@v3
123
127
with :
124
128
path : ./cache
125
129
key : ${{ runner.os }}-benchmark
126
130
127
- - name : Store benchmark result
128
- uses : benchmark-action/github-action-benchmark@v1
129
- if : ${{ github.event.pull_request.head.repo.full_name == github.repository }}
130
- with :
131
- name : Go Benchmark
132
- tool : " go"
133
- output-file-path : output.txt
134
- external-data-json-path : ./cache/benchmark-data.json
135
- fail-on-alert : false
136
- github-token : ${{ secrets.GITHUB_TOKEN }}
137
- comment-always : true
131
+ - name : Read previous benchmark result
132
+ if : github.event_name == 'pull_request'
133
+ id : prev-bench
134
+ run : |
135
+ echo "PREV_BENCH_RESULT=null" >> $GITHUB_OUTPUT
136
+ echo "PREV_COMMIT=null" >> $GITHUB_OUTPUT
137
+
138
+ if [ -f "./cache/bench_result.txt" ]; then
139
+ content=$(cat ./cache/bench_result.txt | jq -R -s .)
140
+ echo "PREV_BENCH_RESULT=$content" >> $GITHUB_OUTPUT
141
+
142
+ if [ -f "./cache/commit_hash.txt" ]; then
143
+ prev_commit=$(cat ./cache/commit_hash.txt)
144
+ echo "PREV_COMMIT=$prev_commit" >> $GITHUB_OUTPUT
145
+ fi
146
+ fi
147
+
148
+ - name : Trigger n8n webhook
149
+ if : github.event_name == 'pull_request'
150
+ run : |
151
+ curr_bench=$(cat output.txt | jq -R -s .)
152
+
153
+ response=$(curl -f -X POST ${{ secrets.N8N_WEBHOOK_URL }} \
154
+ -H "Content-Type: application/json" \
155
+ -d '{
156
+ "repo": "${{ github.repository }}",
157
+ "pr_number": "${{ github.event.pull_request.number }}",
158
+ "commit_id": "${{ github.sha }}",
159
+ "prev_commit_id": "${{ steps.prev-bench.outputs.PREV_COMMIT }}",
160
+ "bench_result": ${{ steps.curr-bench.outputs.BENCH_RESULT }},
161
+ "prev_bench_result": ${{ steps.prev-bench.outputs.PREV_BENCH_RESULT }}
162
+ }' || echo "CURL_ERROR")
163
+
164
+ if [ "$response" = "CURL_ERROR" ]; then
165
+ echo "::error::Failed to trigger n8n webhook"
166
+ exit 1
167
+ fi
168
+
169
+ - name : Store benchmark result to cache
170
+ if : github.ref == 'refs/heads/main'
171
+ run : |
172
+ mkdir -p ./cache
173
+ cp output.txt ./cache/bench_result.txt
174
+ echo "${{ github.sha }}" > ./cache/commit_hash.txt
138
175
139
176
complex-test :
140
177
name : complex-test
141
178
runs-on : ubuntu-latest
142
179
143
180
needs : ci-target-check
144
- if : ${{ needs.ci-target-check.outputs.complex-test == 'true' }}
181
+ if : ${{ github.ref == 'refs/heads/main' || needs.ci-target-check.outputs.complex-test == 'true' }}
145
182
146
183
steps :
147
184
- name : Set up Go ${{ env.GO_VERSION }}
0 commit comments