name: Node SDK benchmarks on: [pull_request] permissions: {} concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number }} cancel-in-progress: true jobs: benchmark: runs-on: ubuntu-24.04 timeout-minutes: 15 strategy: fail-fast: false matrix: shard: [flags-single, flags-scaling, flags-memory, capture] permissions: contents: read env: CI: 'true' TURBO_TELEMETRY_DISABLED: '1' steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: ref: ${{ github.event.pull_request.head.sha }} fetch-depth: 0 persist-credentials: false - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: '24.13.0' package-manager-cache: false - uses: pnpm/setup@fa36a5ef7dcdefc3a7cb25655c122e00cf6e636e # v3.1.2 with: cache: false install: false - name: Prepare pinned baseline env: TARGET_SHA: ${{ github.event.pull_request.base.sha }} HEAD_SHA: ${{ github.event.pull_request.head.sha }} run: | set -euo pipefail BASE_WORKTREE="$RUNNER_TEMP/node-benchmark-base" export RESULTS="$RUNNER_TEMP/node-benchmark-results" printf 'BASE_WORKTREE=%s\nRESULTS=%s\n' "$BASE_WORKTREE" "$RESULTS" >> "$GITHUB_ENV" BASE_SHA=$(git merge-base "$TARGET_SHA" "$HEAD_SHA") git worktree add --detach "$BASE_WORKTREE" "$BASE_SHA" mkdir -p "$RESULTS" node -e 'require("fs").writeFileSync(process.env.RESULTS + "/revisions.json", JSON.stringify({target: process.env.TARGET_SHA, head: process.env.HEAD_SHA, base: process.argv[1]}, null, 2))' "$BASE_SHA" - name: Build head run: | pnpm install --frozen-lockfile --filter posthog-node... pnpm turbo run build --filter=posthog-node - name: Build baseline run: | cd "$BASE_WORKTREE" pnpm install --frozen-lockfile --filter posthog-node... pnpm turbo run build --filter=posthog-node - name: Test measurement controls and fixtures run: pnpm --filter posthog-node test:benchmarks - name: Measure paired base and head id: measure timeout-minutes: 12 run: | node packages/node/benchmarks/run.mjs \ --base "$BASE_WORKTREE/packages/node" \ --head "$GITHUB_WORKSPACE/packages/node" \ --output "$RESULTS" \ --repetitions 6 \ --shard "${{ matrix.shard }}" - name: Upload raw shard results if: always() uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: benchmark-shard-${{ matrix.shard }} path: | ${{ runner.temp }}/node-benchmark-results/base.json ${{ runner.temp }}/node-benchmark-results/head.json ${{ runner.temp }}/node-benchmark-results/revisions.json if-no-files-found: warn retention-days: 14 aggregate: needs: benchmark if: ${{ !cancelled() }} runs-on: ubuntu-24.04 timeout-minutes: 5 permissions: contents: read steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: ref: ${{ github.event.pull_request.head.sha }} persist-credentials: false - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: pattern: benchmark-shard-* path: ${{ runner.temp }}/node-benchmark-shards merge-multiple: false - name: Collect and render benchmark comparison uses: PostHog/.github/.github/actions/benchmark-report@3322f26f21f088ad5e5960d65a916971e309ac0b # SDK benchmark reporting (PostHog/.github PR #84) with: mode: collect source-status: ${{ needs.benchmark.result }} shard-manifest: packages/node/benchmarks/shards.json shard-directory: ${{ runner.temp }}/node-benchmark-shards output-directory: ${{ runner.temp }}/node-benchmark-report - name: Upload rendered comparison if: always() uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: node-benchmark-report path: | ${{ runner.temp }}/node-benchmark-report/report.md ${{ runner.temp }}/node-benchmark-report/comparison.json if-no-files-found: ignore retention-days: 14 - name: Upload raw benchmark results if: always() id: results uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: node-benchmark-results path: | ${{ runner.temp }}/node-benchmark-report/bundle.json ${{ runner.temp }}/node-benchmark-report/revisions.json if-no-files-found: warn retention-days: 14 - name: Link results if: always() env: ARTIFACT_URL: ${{ steps.results.outputs.artifact-url }} run: | printf '## Node SDK benchmark data\n\n' >> "$GITHUB_STEP_SUMMARY" if [[ -n "$ARTIFACT_URL" ]]; then printf '[Download paired measurements and execution metadata](%s)\n\n' "$ARTIFACT_URL" >> "$GITHUB_STEP_SUMMARY" fi printf 'Measurements are informational. Check workload statuses before comparing values.\n' >> "$GITHUB_STEP_SUMMARY"