-
Notifications
You must be signed in to change notification settings - Fork 3.2k
215 lines (184 loc) · 7.54 KB
/
performance-tests.yml
File metadata and controls
215 lines (184 loc) · 7.54 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
name: Performance tests
on:
push:
branches:
- 'develop'
paths:
- 'handsontable/src/**'
- 'performance-tests/**'
- '.github/workflows/performance-tests.yml'
pull_request:
types:
- opened
- reopened
- synchronize
paths:
- 'handsontable/**'
- 'performance-tests/**'
- '.github/workflows/performance-tests.yml'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: write
pull-requests: write
actions: read
jobs:
performance-tests:
name: Performance tests
runs-on: ubuntu-latest
timeout-minutes: 90
env:
PERF_MODE: ${{ github.event_name == 'push' && 'golden' || 'compare' }}
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # https://github.com/actions/checkout/releases/tag/v6.0.2
- name: Install pnpm
uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # https://github.com/pnpm/action-setup/releases/tag/v4.2.0
with:
version: 10.30.2
- name: Use Node.js
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # https://github.com/actions/setup-node/releases/tag/v6.2.0
with:
node-version-file: '.nvmrc'
cache: 'pnpm'
registry-url: https://registry.npmjs.org/
- name: Fetch golden snapshots from GitHub Pages
if: env.PERF_MODE == 'compare'
run: |
git fetch origin gh-pages:gh-pages 2>/dev/null || true
mkdir -p performance-tests/golden
if git show gh-pages:performance-reports/develop/latest.json > performance-tests/golden/snapshots.json 2>/dev/null; then
echo "Golden baseline restored from gh-pages"
else
echo "No golden baseline found on gh-pages -- running without baseline"
rm -f performance-tests/golden/snapshots.json
fi
- name: Compute report URL
id: report-url
if: github.event_name == 'pull_request'
run: |
BRANCH_SLUG=$(echo "${{ github.head_ref }}" | sed 's/[^a-zA-Z0-9._-]/-/g')
PAGES_URL="https://handsontable.github.io/handsontable/performance-reports/${BRANCH_SLUG}/"
echo "branch_slug=${BRANCH_SLUG}" >> "$GITHUB_OUTPUT"
echo "pages_url=${PAGES_URL}" >> "$GITHUB_OUTPUT"
- name: Run performance tests
working-directory: performance-tests
env:
CI: true
PR_NUMBER: ${{ github.event.pull_request.number || '' }}
PAGES_URL: ${{ steps.report-url.outputs.pages_url || '' }}
GITHUB_HEAD_REF: ${{ github.head_ref || '' }}
run: node scripts/run.mjs
- name: Upload performance-tests output
if: always()
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # https://github.com/actions/upload-artifact/releases/tag/v7.0.0
with:
name: performance-tests-output
path: performance-tests/output
retention-days: 14
if-no-files-found: warn
- name: Deploy golden to GitHub Pages
if: always() && env.PERF_MODE == 'golden'
run: |
if [ ! -f performance-tests/output/snapshots.json ]; then
echo "No snapshots.json to deploy"
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git fetch origin gh-pages:gh-pages 2>/dev/null || true
TIMESTAMP=$(date -u +"%Y-%m-%dT%H-%M-%SZ")
DEPLOY_DIR="performance-reports/develop/${TIMESTAMP}"
WORK_DIR=$(mktemp -d)
git worktree add "$WORK_DIR" gh-pages
# Deploy timestamped snapshot + report
mkdir -p "${WORK_DIR}/${DEPLOY_DIR}"
cp performance-tests/output/snapshots.json "${WORK_DIR}/${DEPLOY_DIR}/snapshots.json"
if [ -f performance-tests/output/report.html ]; then
cp performance-tests/output/report.html "${WORK_DIR}/${DEPLOY_DIR}/index.html"
fi
# Update latest.json pointer
cp performance-tests/output/snapshots.json "${WORK_DIR}/performance-reports/develop/latest.json"
# Build history index
node performance-tests/lib/build-history-index.mjs "${WORK_DIR}/performance-reports/develop"
cd "$WORK_DIR"
git add performance-reports/develop/
if git diff --cached --quiet; then
echo "No changes to deploy"
else
git commit -m "perf: golden baseline ${TIMESTAMP}"
pushed=false
for attempt in 1 2 3; do
if git push origin gh-pages; then
echo "Deployed golden to ${DEPLOY_DIR}/"
pushed=true
break
fi
echo "Push attempt $attempt failed, pulling and retrying..."
git pull --rebase origin gh-pages
done
if [ "$pushed" = false ]; then
echo "ERROR: all push attempts failed"
exit 1
fi
fi
cd -
git worktree remove "$WORK_DIR" --force
- name: Deploy PR report to GitHub Pages
if: always() && github.event_name == 'pull_request'
env:
BRANCH_SLUG: ${{ steps.report-url.outputs.branch_slug }}
run: |
if [ ! -f performance-tests/output/report.html ]; then
echo "No report.html to deploy"
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git fetch origin gh-pages:gh-pages 2>/dev/null || true
DEPLOY_DIR="performance-reports/${BRANCH_SLUG}"
WORK_DIR=$(mktemp -d)
git worktree add "$WORK_DIR" gh-pages
mkdir -p "${WORK_DIR}/${DEPLOY_DIR}"
cp performance-tests/output/report.html "${WORK_DIR}/${DEPLOY_DIR}/index.html"
cd "$WORK_DIR"
git add "${DEPLOY_DIR}/index.html"
if git diff --cached --quiet; then
echo "No changes to deploy"
else
git commit -m "perf: update report for ${BRANCH_SLUG}"
pushed=false
for attempt in 1 2 3; do
if git push origin gh-pages; then
echo "Deployed to ${DEPLOY_DIR}/"
pushed=true
break
fi
echo "Push attempt $attempt failed, pulling and retrying..."
git pull --rebase origin gh-pages
done
if [ "$pushed" = false ]; then
echo "ERROR: all push attempts failed"
exit 1
fi
fi
cd -
git worktree remove "$WORK_DIR" --force
- name: Ensure PR comment body exists
if: always() && github.event_name == 'pull_request'
run: |
mkdir -p performance-tests/output
if [ ! -f performance-tests/output/result.md ]; then
{
echo '## Performance tests'
echo
echo 'No result.md was generated. Check the workflow log and downloaded artifacts.'
} > performance-tests/output/result.md
fi
- name: Post performance summary to pull request
if: always() && github.event_name == 'pull_request'
uses: marocchino/sticky-pull-request-comment@773744901bac0e8cbb5a0dc842800d45e9b2b405 # https://github.com/marocchino/sticky-pull-request-comment/tree/v2.9.4
with:
header: performance-tests
path: performance-tests/output/result.md