Repository navigation
122 lines (105 loc) · 4.22 KB
/
Copy pathbenchmark.yml
File metadata and controls
122 lines (105 loc) · 4.22 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
name: 'Benchmarks'
# Perf numbers are noisy on shared runners, so benchmarks never gate PRs. They run on each
# published release (and on demand) to refresh the Benchmarks section of the README.
on:
release:
types: [published]
workflow_dispatch:
inputs:
version:
description: 'Version label to record (defaults to package.json version)'
required: false
type: string
open_pr:
description: 'Open a PR with the refreshed README'
required: false
default: true
type: boolean
permissions:
contents: write
pull-requests: write
jobs:
benchmark:
name: 'Run benchmarks (Node 20)'
runs-on: ubuntu-latest
steps:
- name: Checkout default branch
uses: actions/checkout@v4
with:
ref: ${{ github.event.repository.default_branch }}
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Resolve version label
id: ver
run: |
RAW="${{ github.event.release.tag_name || inputs.version }}"
echo "value=${RAW#v}" >> "$GITHUB_OUTPUT"
# The benchmark adapter loads lambda-api from the working tree via require('../../'),
# which resolves through the root package's "main" (./dist/cjs/index.js). That path
# only exists after a build, so the root package must be installed and built first.
- name: Install root dependencies
run: npm ci --ignore-scripts
- name: Build dist (CJS + ESM)
run: npm run build
- name: Install benchmark dependencies
working-directory: benchmarks
run: npm ci
- name: Run benchmarks and refresh README
working-directory: benchmarks
env:
LAMBDA_API_VERSION: ${{ steps.ver.outputs.value }}
run: node run.js --md results/RESULTS.md --json results/raw.json --update-readme
# Keep the committed README Prettier-clean so the PR doesn't fail main's CI.
- name: Format README
run: npx --yes prettier@2 --write README.md
- name: Upload raw results
uses: actions/upload-artifact@v4
with:
name: benchmark-results
path: benchmarks/results/
- name: Add results to job summary
run: cat benchmarks/results/RESULTS.md >> "$GITHUB_STEP_SUMMARY"
# The default branch doesn't accept direct pushes, so the refreshed README goes
# through a PR. Each run gets its own branch so concurrent or repeated runs never
# clobber one another.
- name: Open PR with refreshed README
if: ${{ github.event_name == 'release' || inputs.open_pr }}
env:
GH_TOKEN: ${{ github.token }}
BASE: ${{ github.event.repository.default_branch }}
VERSION: ${{ steps.ver.outputs.value }}
run: |
if git diff --quiet -- README.md; then
echo 'README.md unchanged — no PR needed'
exit 0
fi
LABEL="${VERSION:-manual}"
BRANCH="benchmarks/refresh-${LABEL}-${GITHUB_RUN_ID}"
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git switch -c "$BRANCH"
git add README.md
git commit -m "docs: update benchmark results for ${LABEL}"
git push origin "$BRANCH"
{
echo "Automated refresh of the Benchmarks section of the README, generated by [this run](${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID})."
echo
echo "Version label: \`${LABEL}\` · Trigger: \`${GITHUB_EVENT_NAME}\`"
echo
echo "Perf numbers come from a shared GitHub-hosted runner and are noisy between runs, so treat"
echo "movement within a few percent as noise rather than a regression."
echo
echo '<details><summary>Full results</summary>'
echo
cat benchmarks/results/RESULTS.md
echo
echo '</details>'
} > /tmp/pr-body.md
gh pr create \
--base "$BASE" \
--head "$BRANCH" \
--title "docs: refresh benchmark results for ${LABEL}" \
--body-file /tmp/pr-body.md