forked from Karanjot786/TermUI
-
Notifications
You must be signed in to change notification settings - Fork 0
118 lines (103 loc) · 4.53 KB
/
Copy pathbench.yml
File metadata and controls
118 lines (103 loc) · 4.53 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
name: Bench
on:
pull_request:
branches: [main]
# Skip on docs-only PRs to avoid slowing them down.
permissions:
contents: read
pull-requests: write
jobs:
bench:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout PR
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: 1.3.14
- name: Cache Bun dependencies
uses: actions/cache@v4
with:
path: |
~/.bun/install/cache
**/node_modules
key: ${{ runner.os }}-bun-${{ hashFiles('bun.lock') }}
restore-keys: |
${{ runner.os }}-bun-
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Bench HEAD
run: |
bun run bench | tee bench-head.txt
grep '^BENCH_RESULT_JSON: ' bench-head.txt | sed 's/^BENCH_RESULT_JSON: //' > bench-head.json
- name: Checkout main into worktree
run: git worktree add ../main-worktree origin/main
- name: Install dependencies (main)
working-directory: ../main-worktree
run: bun install --frozen-lockfile
- name: Bench main
working-directory: ../main-worktree
run: |
if [ -f packages/core/src/benchmark/run-all.ts ]; then
bun run bench | tee ../bench-main.txt
grep '^BENCH_RESULT_JSON: ' ../bench-main.txt | sed 's/^BENCH_RESULT_JSON: //' > $GITHUB_WORKSPACE/bench-main.json
elif [ -f packages/core/src/benchmark/render-loop.ts ]; then
bun packages/core/src/benchmark/render-loop.ts | tee ../bench-main.txt
grep '^BENCH_RESULT_JSON: ' ../bench-main.txt | sed 's/^BENCH_RESULT_JSON: //' > $GITHUB_WORKSPACE/bench-main.json
else
echo "No benchmark on main yet — using HEAD as baseline (no regression possible)."
cp $GITHUB_WORKSPACE/bench-head.json $GITHUB_WORKSPACE/bench-main.json
fi
- name: Check if this is benchmark system upgrade
id: check-upgrade
run: |
# Check if run-all.ts exists in PR but not in main, or if they differ
if [ -f packages/core/src/benchmark/run-all.ts ] && [ ! -f ../main-worktree/packages/core/src/benchmark/run-all.ts ]; then
echo "is_upgrade=true" >> $GITHUB_OUTPUT
echo "This PR adds the benchmark system - skipping regression checks"
elif [ -f packages/core/src/benchmark/run-all.ts ] && [ -f ../main-worktree/packages/core/src/benchmark/run-all.ts ]; then
# Compare the files directly
if ! diff -q packages/core/src/benchmark/run-all.ts ../main-worktree/packages/core/src/benchmark/run-all.ts > /dev/null 2>&1; then
echo "is_upgrade=true" >> $GITHUB_OUTPUT
echo "This PR upgrades the benchmark system - skipping regression checks"
else
echo "is_upgrade=false" >> $GITHUB_OUTPUT
fi
else
echo "is_upgrade=false" >> $GITHUB_OUTPUT
fi
- name: Compare results
id: compare
continue-on-error: true
if: steps.check-upgrade.outputs.is_upgrade != 'true'
run: |
node scripts/compare-bench.mjs bench-head.json bench-main.json --threshold 0.20
echo "Compare exit code: $?"
- name: Skip comparison for upgrade
if: steps.check-upgrade.outputs.is_upgrade == 'true'
run: |
echo '<!-- termui-bench-comment -->' > bench-comment.md
echo '## Performance benchmarks' >> bench-comment.md
echo '' >> bench-comment.md
echo 'ℹ️ **Benchmark system upgrade** - This PR adds or upgrades the benchmark infrastructure.' >> bench-comment.md
echo '' >> bench-comment.md
echo 'Regression checks are skipped for this upgrade PR. Future PRs will compare against the new baseline.' >> bench-comment.md
echo '' >> bench-comment.md
echo 'Benchmark results:' >> bench-comment.md
cat bench-head.json >> bench-comment.md
- name: Post or update PR comment
continue-on-error: true
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
body-path: bench-comment.md
edit-mode: replace
- name: Fail on regression
if: steps.compare.outcome == 'failure'
run: |
echo "::error::Performance benchmark regressed by ≥20% on at least one metric."
exit 1