-
Notifications
You must be signed in to change notification settings - Fork 7
139 lines (116 loc) · 3.93 KB
/
Copy pathbenchmarks.yml
File metadata and controls
139 lines (116 loc) · 3.93 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
name: Benchmarks
on:
pull_request:
paths:
- "tesseract_core/**"
- "benchmarks/**"
- ".github/workflows/benchmarks.yml"
push:
branches:
- main
concurrency:
group: benchmarks-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
permissions:
contents: read
pull-requests: write
jobs:
benchmark:
runs-on: ubuntu-latest
steps:
- name: Set up Git repository
uses: actions/checkout@v7
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.13"
- name: Set up uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
- name: Restore UV environment
run: cp production.uv.lock uv.lock
- name: Install package
run: uv sync --extra dev --frozen
- name: Run benchmarks on current commit
run: |
uv run --no-sync pytest benchmarks/ \
--benchmark-json current_benchmarks.json
- name: Check out baseline branch
if: github.event_name == 'pull_request'
uses: actions/checkout@v7
with:
ref: ${{ github.event.pull_request.base.ref }}
path: baseline
- name: Install package (baseline)
if: github.event_name == 'pull_request'
working-directory: baseline
run: |
cp production.uv.lock uv.lock 2>/dev/null || true
uv sync --extra dev --frozen
- name: Use PR benchmark scripts for baseline
if: github.event_name == 'pull_request'
working-directory: baseline
run: |
cp -r ../benchmarks/* benchmarks/
- name: Run benchmarks on baseline
if: github.event_name == 'pull_request'
id: baseline
working-directory: baseline
run: |
rc=0
uv run --no-sync pytest benchmarks/ \
--benchmark-json baseline_benchmarks.json \
|| rc=$?
if [ "$rc" != "0" ]; then
echo "::warning::Baseline benchmark run failed, skipping comparison"
echo "has_baseline=false" >> $GITHUB_OUTPUT
exit 0
fi
echo "has_baseline=true" >> $GITHUB_OUTPUT
- name: Generate comparison report
if: github.event_name == 'pull_request'
id: comparison
run: |
baseline_flag=""
if [ "${{ steps.baseline.outputs.has_baseline }}" = "true" ]; then
baseline_flag="--baseline baseline/baseline_benchmarks.json"
fi
python benchmarks/compare_benchmarks.py \
$baseline_flag \
--current current_benchmarks.json \
--output benchmark_report.md
# Set output as multiline string
{
echo 'report<<BENCHMARK_REPORT_END'
cat benchmark_report.md
echo ''
echo 'BENCHMARK_REPORT_END'
} >> $GITHUB_OUTPUT
- name: Find existing comment
if: github.event_name == 'pull_request'
uses: peter-evans/find-comment@v4
id: find-comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: "PasteurBot"
body-includes: "## Benchmark Results"
- name: Create or update PR comment
if: github.event_name == 'pull_request'
uses: peter-evans/create-or-update-comment@v5
with:
token: ${{ secrets.PL_PASTEURBOT_PAT_PUBLIC }}
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: ${{ steps.comparison.outputs.report }}
edit-mode: replace
- name: Upload benchmark results
uses: actions/upload-artifact@v7
with:
name: benchmark-results
path: |
current_benchmarks.json
baseline/baseline_benchmarks.json
benchmark_report.md
if-no-files-found: ignore
retention-days: 30