3535 with :
3636 filters : |
3737 build: '**'
38- bench:
38+ bench:
3939 - 'test/bench/**'
4040 - 'pkg/**'
4141 - 'server/**'
5454 runs-on : ubuntu-latest
5555
5656 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' }}
5858
5959 steps :
6060 - name : Set up Go ${{ env.GO_VERSION }}
@@ -101,7 +101,7 @@ jobs:
101101 permissions : write-all
102102
103103 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' }}
105105
106106 steps :
107107 - name : Set up Go ${{ env.GO_VERSION }}
@@ -116,32 +116,69 @@ jobs:
116116 run : docker compose -f build/docker/docker-compose.yml up --build -d
117117
118118 - 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
120124
121- - name : Download previous benchmark data
125+ - name : Set up cache
122126 uses : actions/cache@v3
123127 with :
124128 path : ./cache
125129 key : ${{ runner.os }}-benchmark
126130
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
138175
139176 complex-test :
140177 name : complex-test
141178 runs-on : ubuntu-latest
142179
143180 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' }}
145182
146183 steps :
147184 - name : Set up Go ${{ env.GO_VERSION }}
0 commit comments