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 '
Full results' echo cat benchmarks/results/RESULTS.md echo echo '
' } > /tmp/pr-body.md gh pr create \ --base "$BASE" \ --head "$BRANCH" \ --title "docs: refresh benchmark results for ${LABEL}" \ --body-file /tmp/pr-body.md