Files
vercel__workflow/.github/workflows/e2e-community-world.yml
Sepcnt c22abcd5f1 Add SurrealDB as a community world (#1579)
Squashed and rebased onto main to resolve conflicts with the generic
docker community-world CI: the dedicated surrealdb service steps from
the original commits are replaced by the manifest-driven docker service
type, with a new optional `args` field so the service definition can
pass the `start` subcommand (and credentials) to the SurrealDB image.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-03 17:43:11 -07:00

259 lines
9.9 KiB
YAML

# Reusable workflow for running E2E tests against a community world
# Supports optional service containers (mongodb, redis) via service-type input
# Called by tests.yml with specific world configuration
name: E2E Community World
# Temporarily disabled: V2 combined handler removed legacy stream world
# normalization (LegacyStreamWorld). Community world adapters need to
# implement the world.streams.* interface before these tests pass again.
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
package-version:
description: 'Optional npm version/dist-tag to pin the world package to (empty = latest)'
required: false
type: string
default: ''
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, docker)'
required: false
type: string
default: 'none'
services:
description: 'JSON array of service definitions from the manifest (used when service-type is docker)'
required: false
type: string
default: '[]'
jobs:
e2e:
# Skip until community world adapters implement world.streams.* interface
if: false
name: E2E ${{ inputs.world-name }}
runs-on: ubuntu-latest
continue-on-error: true
timeout-minutes: 30
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: Start Docker services
if: ${{ inputs.service-type == 'docker' }}
# Services start serially in manifest order. Each service's health check
# must pass before the next one starts, so any service that depends on
# another (e.g. a workflow service that needs postgres) must be listed
# AFTER its dependency in the manifest's `services` array.
#
# `healthCheck.cmd` is executed via `sh -c` below, which means the
# manifest is a shell-execution surface. Safe here because
# `worlds-manifest.json` is in-repo and PR-reviewed.
run: |
set -euo pipefail
SERVICES='${{ inputs.services }}'
count=$(echo "$SERVICES" | jq '. | length')
for idx in $(seq 0 $((count - 1))); do
svc=$(echo "$SERVICES" | jq -c ".[$idx]")
name=$(echo "$svc" | jq -r '.name')
image=$(echo "$svc" | jq -r '.image')
health_cmd=$(echo "$svc" | jq -r '.healthCheck.cmd // empty')
retries=$(echo "$svc" | jq -r '.healthCheck.retries // 10')
# Build docker run as an array so env values with spaces/quotes
# survive intact (no shell re-interpretation via eval).
args=(docker run -d --name "$name" --network host)
env_lines=$(echo "$svc" | jq -r '.env // {} | to_entries[] | "\(.key)=\(.value)"')
if [ -n "$env_lines" ]; then
while IFS= read -r line; do
args+=(-e "$line")
done <<< "$env_lines"
fi
args+=("$image")
# Optional command args passed to the image entrypoint (e.g. a
# `start` subcommand for images whose entrypoint is the bare binary).
cmd_args=$(echo "$svc" | jq -r '.args // [] | .[]')
if [ -n "$cmd_args" ]; then
while IFS= read -r line; do
args+=("$line")
done <<< "$cmd_args"
fi
echo "Starting $name ($image)..."
"${args[@]}"
# Health check runs on the host (--network host shares the network).
if [ -n "$health_cmd" ]; then
echo "Waiting for $name to be ready..."
for i in $(seq 1 "$retries"); do
if sh -c "$health_cmd" &>/dev/null; then
echo "$name is ready"
break
fi
if [ "$i" -eq "$retries" ]; then
echo "ERROR: $name health check did not pass after $retries retries"
exit 1
fi
sleep 2
done
fi
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 }}
WORLD_PACKAGE_VERSION: ${{ inputs.package-version }}
run: |
SPEC="${WORLD_PACKAGE}${WORLD_PACKAGE_VERSION:+@$WORLD_PACKAGE_VERSION}"
pnpm --filter "$APP_NAME" add "$SPEC"
# 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: Run E2E Tests
env:
NODE_OPTIONS: "--enable-source-maps"
APP_NAME: ${{ inputs.app-name }}
WORLD_ID: ${{ inputs.world-id }}
DEPLOYMENT_URL: "http://localhost:3000"
WORKFLOW_DEV_HMR_LOGS: "1"
run: |
DEV_TEST_CONFIG="$(jq -nc --arg name "$APP_NAME" '{name:$name,project:"workbench-\($name)-workflow",generatedStepRegistrationPath:"app/.well-known/workflow/v1/flow/__step_registrations.js",generatedWorkflowPath:"app/.well-known/workflow/v1/flow/route.js",apiFilePath:"app/api/chat/route.ts",apiFileImportPath:"../../.."}')"
export DEV_TEST_CONFIG
export DEV_SERVER_LOG_PATH="$GITHUB_WORKSPACE/dev-server-$APP_NAME-$WORLD_ID.log"
rm -f "$DEV_SERVER_LOG_PATH"
(cd "workbench/$APP_NAME" && pnpm dev 2>&1 | tee "$DEV_SERVER_LOG_PATH") &
cd "$GITHUB_WORKSPACE"
echo "Waiting for dev server to start..." && sleep 15
pnpm vitest run packages/core/e2e/dev.test.ts --reporter=default --reporter=json --reporter=./packages/core/e2e/github-reporter.ts "--outputFile=e2e-community-$WORLD_ID-dev.json" || true
sleep 10
pnpm vitest run packages/core/e2e/e2e.test.ts --reporter=default --reporter=json --reporter=./packages/core/e2e/github-reporter.ts "--outputFile=e2e-community-$WORLD_ID.json" || true
- name: Generate E2E summary
if: always()
env:
WORLD_NAME: ${{ inputs.world-name }}
run: node .github/scripts/aggregate-e2e-results.js . --job-name "E2E Tests ($WORLD_NAME)" >> $GITHUB_STEP_SUMMARY || true
- name: Upload E2E results
uses: actions/upload-artifact@v4
if: always()
with:
name: e2e-results-community-${{ inputs.world-id }}
path: |
e2e-community-${{ inputs.world-id }}-dev.json
e2e-community-${{ inputs.world-id }}.json
retention-days: 7
if-no-files-found: ignore
- name: Stop services
if: always()
run: |
docker stop mongodb 2>/dev/null || true
docker stop redis 2>/dev/null || true
if [ '${{ inputs.service-type }}' = 'docker' ]; then
echo '${{ inputs.services }}' | jq -r '.[].name' 2>/dev/null | while read -r name; do
docker stop "$name" 2>/dev/null || true
done
fi