Files
vercel__workflow/.github/workflows/benchmark-community-world.yml
Pranay Prakash 4708a77a35 CI: drop setup-command input from reusable community-world workflows (#1828)
* drop setup-command input from reusable community-world workflows

The community-world matrix is produced by running
scripts/create-community-worlds-matrix.mjs in the fork PR's checkout,
so any field on it is attacker-controlled. Forwarding
matrix.world.setup-command into the reusable workflow and eval-ing it
let a malicious fork PR execute arbitrary shell on the runner.

Replace the pass-through with a hardcoded per-world-id case in the
reusable workflows (only turso currently needs a setup step) and drop
the setup field from the matrix generator.

* rename step to "Per-world setup"

Addresses Copilot review feedback: the step no longer executes an
arbitrary command, so the old name was misleading.
2026-05-14 17:14:49 -07:00

178 lines
5.8 KiB
YAML

# Reusable workflow for running benchmarks against a community world
# Supports optional service containers (mongodb, redis) via service-type input
# Called by benchmarks.yml
name: Benchmark Community World
on:
workflow_call:
inputs:
world-id:
description: 'World identifier (turso, mongodb, etc.)'
required: true
type: string
world-name:
description: 'Display name for the world'
required: true
type: string
world-package:
description: 'NPM package name for the world'
required: true
type: string
app-name:
description: 'App to test (default: nextjs-turbopack)'
required: false
type: string
default: 'nextjs-turbopack'
env-vars:
description: 'JSON object of environment variables to set'
required: false
type: string
default: '{}'
service-type:
description: 'Service container to run (none, mongodb, redis)'
required: false
type: string
default: 'none'
full-suite:
description: 'Run full benchmark suite including long-running tests'
required: false
type: boolean
default: false
jobs:
benchmark:
name: Benchmark ${{ inputs.world-name }}
runs-on: ubuntu-latest
timeout-minutes: 60
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ vars.TURBO_TEAM }}
WORKFLOW_PUBLIC_MANIFEST: '1'
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Start MongoDB
if: ${{ inputs.service-type == 'mongodb' }}
run: |
docker run -d --name mongodb -p 27017:27017 mongo:7
echo "Waiting for MongoDB to be ready..."
for i in {1..30}; do
if docker exec mongodb mongosh --eval 'db.runCommand({ ping: 1 })' &>/dev/null; then
echo "MongoDB is ready"
break
fi
sleep 2
done
- name: Start Redis
if: ${{ inputs.service-type == 'redis' }}
run: |
docker run -d --name redis -p 6379:6379 redis:7-alpine
echo "Waiting for Redis to be ready..."
for i in {1..30}; do
if docker exec redis redis-cli ping | grep -q PONG; then
echo "Redis is ready"
break
fi
sleep 2
done
- name: Setup environment
uses: ./.github/actions/setup-workflow-dev
with:
build-packages: 'true'
- name: Validate inputs
env:
APP_NAME: ${{ inputs.app-name }}
WORLD_ID: ${{ inputs.world-id }}
WORLD_PACKAGE: ${{ inputs.world-package }}
run: |
if [[ ! "$APP_NAME" =~ ^[a-zA-Z0-9][a-zA-Z0-9_-]*$ ]]; then
echo "Invalid app-name: $APP_NAME" >&2
exit 1
fi
if [[ ! "$WORLD_ID" =~ ^[a-zA-Z0-9][a-zA-Z0-9_-]*$ ]]; then
echo "Invalid world-id: $WORLD_ID" >&2
exit 1
fi
if [[ ! "$WORLD_PACKAGE" =~ ^(@[a-zA-Z0-9][a-zA-Z0-9_.-]*/)?[a-zA-Z0-9][a-zA-Z0-9_.-]*(@[a-zA-Z0-9][a-zA-Z0-9_.+-]*)?$ ]]; then
echo "Invalid world-package: $WORLD_PACKAGE" >&2
exit 1
fi
- name: Install ${{ inputs.world-name }} World
env:
APP_NAME: ${{ inputs.app-name }}
WORLD_PACKAGE: ${{ inputs.world-package }}
run: pnpm --filter "$APP_NAME" add "$WORLD_PACKAGE"
# Per-world setup. Hardcoded (not taken from the matrix) so a malicious
# fork PR cannot smuggle arbitrary shell through matrix.world.setup-command.
- name: Per-world setup
env:
APP_NAME: ${{ inputs.app-name }}
WORLD_ID: ${{ inputs.world-id }}
run: |
cd "workbench/$APP_NAME"
case "$WORLD_ID" in
turso) pnpm exec workflow-turso-setup ;;
*) echo "No setup required for $WORLD_ID" ;;
esac
- name: Resolve symlinks
env:
APP_NAME: ${{ inputs.app-name }}
run: ./scripts/resolve-symlinks.sh "workbench/$APP_NAME"
- name: Set environment variables
env:
ENV_VARS_JSON: ${{ inputs.env-vars }}
run: |
printf '%s' "$ENV_VARS_JSON" | jq -r 'to_entries[] | "\(.key)=\(.value)"' >> "$GITHUB_ENV"
- name: Build workbench
env:
APP_NAME: ${{ inputs.app-name }}
run: pnpm turbo run build --filter="./workbench/$APP_NAME"
- name: Run benchmarks
env:
DEPLOYMENT_URL: "http://localhost:3000"
APP_NAME: ${{ inputs.app-name }}
WORLD_ID: ${{ inputs.world-id }}
WORKFLOW_BENCH_BACKEND: ${{ inputs.world-id }}
BENCHMARK_FULL_SUITE: ${{ inputs.full-suite }}
run: |
cd "workbench/$APP_NAME"
pnpm start &
echo "Waiting for server to start..."
sleep 15
cd "$GITHUB_WORKSPACE"
pnpm vitest bench packages/core/e2e/bench.bench.ts --run "--outputJson=bench-results-$APP_NAME-$WORLD_ID.json"
- name: Render benchmark results
uses: ./.github/actions/render-benchmarks
with:
benchmark-file: bench-results-${{ inputs.app-name }}-${{ inputs.world-id }}.json
app-name: ${{ inputs.app-name }}
backend: ${{ inputs.world-id }}
- name: Upload benchmark results
uses: actions/upload-artifact@v4
with:
name: bench-results-${{ inputs.app-name }}-${{ inputs.world-id }}
path: |
bench-results-${{ inputs.app-name }}-${{ inputs.world-id }}.json
bench-timings-${{ inputs.app-name }}-${{ inputs.world-id }}.json
- name: Stop services
if: always()
run: |
docker stop mongodb 2>/dev/null || true
docker stop redis 2>/dev/null || true