File: performance-pr.yml

package info (click to toggle)
golang-github-casbin-casbin 3.10.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,756 kB
  • sloc: makefile: 14
file content (93 lines) | stat: -rw-r--r-- 2,882 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
name: Performance Comparison for Pull Requests

on:
  pull_request:
    branches: [master]

jobs:
  benchmark-pr:
    name: Performance benchmark comparison
    runs-on: ubuntu-latest
    steps:
      - name: Checkout PR branch
        uses: actions/checkout@v4
        with:
          ref: ${{ github.event.pull_request.head.sha }}

      - name: Set up Go
        uses: actions/setup-go@v5
        with:
          go-version: 'stable'

      # Save commit SHAs for display
      - name: Save commit info
        id: commits
        run: |
          BASE_SHA="${{ github.event.pull_request.base.sha }}"
          HEAD_SHA="${{ github.event.pull_request.head.sha }}"
          echo "base_short=${BASE_SHA:0:7}" >> $GITHUB_OUTPUT
          echo "head_short=${HEAD_SHA:0:7}" >> $GITHUB_OUTPUT

      # Run benchmark on PR branch
      - name: Run benchmark on PR branch
        run: |
          go test -bench '.' -benchtime=2s -benchmem ./... | tee pr-bench.txt

      # Checkout base branch and run benchmark
      - name: Checkout base branch
        uses: actions/checkout@v4
        with:
          ref: ${{ github.event.pull_request.base.sha }}
          clean: false
          path: base

      - name: Run benchmark on base branch
        working-directory: base
        run: |
          go test -bench '.' -benchtime=2s -benchmem ./... | \
            tee ../base-bench.txt

      # Install benchstat for comparison
      - name: Install benchstat
        run: go install golang.org/x/perf/cmd/benchstat@latest

      # Compare benchmarks using benchstat
      - name: Compare benchmarks with benchstat
        id: benchstat
        run: |
          cat > comparison.md << 'EOF'
          ## Benchmark Comparison

          Comparing base branch (`${{ steps.commits.outputs.base_short }}`)
          vs PR branch (`${{ steps.commits.outputs.head_short }}`)

          ```
          EOF
          benchstat base-bench.txt pr-bench.txt >> comparison.md || true
          echo '```' >> comparison.md

          # Post-process to append percentage + emoji column (🚀 faster < -10%, 🐌 slower > +10%, otherwise ➡️)
          if [ ! -f comparison.md ]; then
            echo "comparison.md not found after benchstat." >&2
            exit 1
          fi
          python3 .github/scripts/benchmark_formatter.py

      # Save PR number
      - name: Save PR number
        run: |
          PR_NUMBER="${{ github.event.pull_request.number }}"
          if [ -z "$PR_NUMBER" ]; then
            echo "Error: Pull request number is not available in event payload." >&2
            exit 1
          fi
          echo "$PR_NUMBER" > pr_number.txt

      # Upload benchmark results
      - name: Upload benchmark results
        uses: actions/upload-artifact@v4
        with:
          name: benchmark-results
          path: |
            comparison.md
            pr_number.txt