Skip to content

Commit

Permalink
Update CI to store benchmark results in main and send to n8n from PR
Browse files Browse the repository at this point in the history
  • Loading branch information
chacha912 committed Feb 20, 2025
1 parent 900dc45 commit d7e451b
Showing 1 changed file with 46 additions and 12 deletions.
58 changes: 46 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,57 @@ jobs:
- name: Bench
run: make bench

- name: Download previous benchmark data
- name: Set up cache
uses: actions/cache@v3
with:
path: ./cache
key: ${{ runner.os }}-benchmark

- name: Store benchmark result
uses: benchmark-action/github-action-benchmark@v1
if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
with:
name: Go Benchmark
tool: "go"
output-file-path: output.txt
external-data-json-path: ./cache/benchmark-data.json
fail-on-alert: false
github-token: ${{ secrets.GITHUB_TOKEN }}
comment-always: true
- name: Read previous benchmark result
if: github.event_name == 'pull_request'
id: prev-bench
run: |
if [ -f "./cache/bench_result.txt" ]; then
content=$(cat ./cache/bench_result.txt | jq -R -s .)
echo "PREV_BENCH_RESULT=$content" >> $GITHUB_OUTPUT
if [ -f "./cache/commit_hash.txt" ]; then
prev_commit=$(cat ./cache/commit_hash.txt)
echo "PREV_COMMIT=$prev_commit" >> $GITHUB_OUTPUT
else
echo "PREV_COMMIT=null" >> $GITHUB_OUTPUT
fi
else
echo "PREV_BENCH_RESULT=null" >> $GITHUB_OUTPUT
fi
- name: Trigger n8n webhook
if: github.event_name == 'pull_request'
run: |
curr_bench=$(cat output.txt | jq -R -s .)
response=$(curl -f -X POST ${{ secrets.N8N_WEBHOOK_URL }} \
-H "Content-Type: application/json" \
-d '{
"repo": "${{ github.repository }}",
"pr_number": "${{ github.event.pull_request.number }}",
"commit_id": "${{ github.sha }}",
"prev_commit_id": "${{ steps.prev-bench.outputs.PREV_COMMIT }}",
"bench_result": curr_bench,
"prev_bench_result": ${{ steps.prev-bench.outputs.PREV_BENCH_RESULT }}
}' || echo "CURL_ERROR")
if [ "$response" = "CURL_ERROR" ]; then
echo "::error::Failed to trigger n8n webhook"
exit 1
fi
- name: Store benchmark result to cache
if: github.ref == 'refs/heads/main'
run: |
mkdir -p ./cache
cp output.txt ./cache/bench_result.txt
echo "${{ github.sha }}" > ./cache/commit_hash.txt
complex-test:
name: complex-test
Expand Down

0 comments on commit d7e451b

Please sign in to comment.