-
Notifications
You must be signed in to change notification settings - Fork 24
178 lines (150 loc) · 6.23 KB
/
benchmark.yml
File metadata and controls
178 lines (150 loc) · 6.23 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
name: Benchmarks
on:
pull_request:
types: [opened, synchronize, reopened]
repository_dispatch:
types: [release-published]
workflow_dispatch:
permissions:
contents: write
deployments: write
pull-requests: write
concurrency:
group: benchmark-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress: true
env:
CI: true
jobs:
benchmark:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
# --- Change detection ---
- name: Check if benchmarks should run (PR)
id: pr-check
if: github.event_name == 'pull_request'
run: |
CHANGED=$(git diff --name-only origin/${{ github.base_ref }}...HEAD)
if echo "$CHANGED" | grep -qE "^(packages/next/|tests/apps/next/middleware/)"; then
echo "run=true" >> $GITHUB_OUTPUT
else
echo "run=false" >> $GITHUB_OUTPUT
fi
- name: Check if gt-next was published (dispatch)
id: dispatch-check
if: github.event_name == 'repository_dispatch'
run: |
PACKAGES='${{ toJSON(github.event.client_payload.publishedPackages) }}'
if echo "$PACKAGES" | jq -e '.[] | select(.name == "gt-next")' > /dev/null 2>&1; then
echo "run=true" >> $GITHUB_OUTPUT
VERSION=$(echo "$PACKAGES" | jq -r '.[] | select(.name == "gt-next") | .version')
echo "version=$VERSION" >> $GITHUB_OUTPUT
else
echo "run=false" >> $GITHUB_OUTPUT
fi
- name: Determine if benchmarks should run
id: should-run
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "run=true" >> $GITHUB_OUTPUT
elif [ "${{ github.event_name }}" = "pull_request" ]; then
echo "run=${{ steps.pr-check.outputs.run }}" >> $GITHUB_OUTPUT
elif [ "${{ github.event_name }}" = "repository_dispatch" ]; then
echo "run=${{ steps.dispatch-check.outputs.run }}" >> $GITHUB_OUTPUT
fi
# --- Setup ---
- uses: pnpm/action-setup@v4
if: steps.should-run.outputs.run == 'true'
name: Install pnpm
- name: Setup Node.js
if: steps.should-run.outputs.run == 'true'
uses: actions/setup-node@v4
with:
node-version: 24
cache: 'pnpm'
- name: Setup Rust
if: steps.should-run.outputs.run == 'true'
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-wasip1
- name: Install dependencies
if: steps.should-run.outputs.run == 'true'
run: pnpm install
- name: Install Playwright browsers
if: steps.should-run.outputs.run == 'true'
working-directory: tests/apps/next/middleware
run: npx playwright install chromium
# --- Resolve version ---
- name: Read gt-next version
id: read-version
if: steps.should-run.outputs.run == 'true' && github.event_name != 'repository_dispatch'
run: |
VERSION=$(node -p "require('./packages/next/package.json').version")
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Set version output
id: version
if: steps.should-run.outputs.run == 'true'
run: |
if [ "${{ github.event_name }}" = "repository_dispatch" ]; then
echo "value=${{ steps.dispatch-check.outputs.version }}" >> $GITHUB_OUTPUT
else
echo "value=${{ steps.read-version.outputs.version }}" >> $GITHUB_OUTPUT
fi
# --- Build packages (required for unit benchmarks to resolve gt-next/middleware) ---
- name: Build packages
if: steps.should-run.outputs.run == 'true'
run: pnpm build
# --- Run benchmarks ---
# Out of scope of current PR
# TODO: this should be more generalizable done with a single pnpm call triggering everything
# you pass in a list/object of changed packages and their versions, then it executes only the associated benchmarks
# explore having a "gt:package" field in the package.json for the test apps so we know which package each app is associated with
- name: Run unit benchmarks
if: steps.should-run.outputs.run == 'true'
working-directory: packages/next
run: pnpm bench:unit:json
- name: Run E2E benchmarks
if: steps.should-run.outputs.run == 'true'
working-directory: tests/apps/next/middleware
env:
BENCH_OUTPUT_NAME: e2e-latest
run: node runBenchE2E.mjs
# --- Transform results ---
# Out of scope of current PR
# TODO: standardize this so it is one call and all of the package/version/etc mapping searching for output files etc is automatic
- name: Transform benchmark results
if: steps.should-run.outputs.run == 'true'
run: |
node scripts/transform-bench-results.mjs \
--unit packages/next/benchmarks/results/unit-latest.json \
--e2e tests/apps/next/middleware/benchmarks/results/e2e-latest.json \
--output benchmark-results.json \
--package gt-next \
--version ${{ steps.version.outputs.value }}
# --- Store & compare ---
# Clean working tree, but leave benchmarks results in place
- name: Clean working tree
if: steps.should-run.outputs.run == 'true'
run: git checkout -- .
- name: Store benchmark results
if: steps.should-run.outputs.run == 'true'
uses: benchmark-action/github-action-benchmark@v1
with:
name: 'Middleware Benchmarks'
tool: 'customSmallerIsBetter'
output-file-path: benchmark-results.json
gh-pages-branch: gh-pages
benchmark-data-dir-path: dev/bench
github-token: ${{ secrets.GITHUB_TOKEN }}
# Comparison & alerting
alert-threshold: '150%'
comment-on-alert: true
fail-on-alert: false
alert-comment-cc-users: '@generaltranslation/core'
summary-always: true
# Data persistence — only save/push on release dispatches
save-data-file: ${{ github.event_name == 'repository_dispatch' }}
auto-push: ${{ github.event_name == 'repository_dispatch' }}