Skip to content

Commit

Permalink
Enhance Benchmark Results with n8n (#1162)
Browse files Browse the repository at this point in the history
Improves visibility of performance metrics by storing benchmark results
from main branch and forwarding PR comparisons to n8n. Added automated
unit conversion, categorized result tables, and performance difference
highlighting to facilitate data-driven development decisions.
  • Loading branch information
chacha912 authored and hackerwins committed Feb 20, 2025
1 parent 900dc45 commit 8d1f1ae
Showing 1 changed file with 54 additions and 17 deletions.
71 changes: 54 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
with:
filters: |
build: '**'
bench:
bench:
- 'test/bench/**'
- 'pkg/**'
- 'server/**'
Expand All @@ -54,7 +54,7 @@ jobs:
runs-on: ubuntu-latest

needs: ci-target-check
if: ${{ needs.ci-target-check.outputs.build == 'true' }}
if: ${{ github.ref == 'refs/heads/main' || needs.ci-target-check.outputs.build == 'true' }}

steps:
- name: Set up Go ${{ env.GO_VERSION }}
Expand Down Expand Up @@ -101,7 +101,7 @@ jobs:
permissions: write-all

needs: ci-target-check
if: ${{ needs.ci-target-check.outputs.bench == 'true' }}
if: ${{ github.ref == 'refs/heads/main' || needs.ci-target-check.outputs.bench == 'true' }}

steps:
- name: Set up Go ${{ env.GO_VERSION }}
Expand All @@ -116,32 +116,69 @@ jobs:
run: docker compose -f build/docker/docker-compose.yml up --build -d

- name: Bench
run: make bench
id: curr-bench
run: |
make bench
content=$(cat output.txt | jq -R -s .)
echo "BENCH_RESULT=$content" >> $GITHUB_OUTPUT
- 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: |
echo "PREV_BENCH_RESULT=null" >> $GITHUB_OUTPUT
echo "PREV_COMMIT=null" >> $GITHUB_OUTPUT
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
fi
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": ${{ steps.curr-bench.outputs.BENCH_RESULT }},
"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
runs-on: ubuntu-latest

needs: ci-target-check
if: ${{ needs.ci-target-check.outputs.complex-test == 'true' }}
if: ${{ github.ref == 'refs/heads/main' || needs.ci-target-check.outputs.complex-test == 'true' }}

steps:
- name: Set up Go ${{ env.GO_VERSION }}
Expand Down

0 comments on commit 8d1f1ae

Please sign in to comment.