diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 86eee797d..97b173b08 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,7 +35,7 @@ jobs: with: filters: | build: '**' - bench: + bench: - 'test/bench/**' - 'pkg/**' - 'server/**' @@ -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 }} @@ -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 }} @@ -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 }}