diff --git a/.github/workflows/pr-testbox-windows.yml b/.github/workflows/pr-testbox-windows.yml new file mode 100644 index 00000000000..5706db45c24 --- /dev/null +++ b/.github/workflows/pr-testbox-windows.yml @@ -0,0 +1,58 @@ +name: Blacksmith PR Testbox Windows + +on: + workflow_dispatch: + inputs: + testbox_id: + type: string + description: "Testbox session ID" + required: true + +permissions: + contents: read + +jobs: + pr-testbox-windows: + runs-on: blacksmith-4vcpu-windows-2025 + + steps: + - name: Begin Testbox + if: ${{ github.event_name == 'workflow_dispatch' }} + uses: useblacksmith/begin-testbox@233448af4bfdc6fca509a7f0974411ac6d8a8043 # v2 + with: + testbox_id: ${{ inputs.testbox_id }} + + - name: ⬇️ Checkout repo + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + fetch-depth: 0 + persist-credentials: false + + - name: ⎔ Setup pnpm + uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v5.0.0 + with: + version: 10.33.2 + + - name: ⎔ Setup node + uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 + with: + node-version: 20.20.2 + + - name: 📥 Download CLI deps + run: pnpm install --frozen-lockfile --filter trigger.dev... + + - name: 📀 Generate Prisma Client + run: pnpm run generate + + - name: 🔧 Build v3 cli monorepo dependencies + run: pnpm run build --filter trigger.dev^... + + - name: 🔧 Build worker template files + run: pnpm --filter trigger.dev run --if-present build:workers + + - name: Enable corepack + run: corepack enable + + - name: Run Testbox + uses: useblacksmith/run-testbox@5ca05834db1d3813554d1dd109e5f2087a8d7cbc # v2 + if: ${{ always() && github.event_name == 'workflow_dispatch' }} diff --git a/.github/workflows/pr-testbox.yml b/.github/workflows/pr-testbox.yml new file mode 100644 index 00000000000..32b0d6a28be --- /dev/null +++ b/.github/workflows/pr-testbox.yml @@ -0,0 +1,127 @@ +name: Blacksmith PR Testbox + +on: + workflow_dispatch: + inputs: + testbox_id: + type: string + description: "Testbox session ID" + required: true + +permissions: + contents: read + +jobs: + pr-testbox: + runs-on: blacksmith-8vcpu-ubuntu-2404 + env: + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + + steps: + - name: Begin Testbox + if: ${{ github.event_name == 'workflow_dispatch' }} + uses: useblacksmith/begin-testbox@233448af4bfdc6fca509a7f0974411ac6d8a8043 # v2 + with: + testbox_id: ${{ inputs.testbox_id }} + + - name: 🔧 Disable IPv6 + run: | + sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1 + sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1 + sudo sysctl -w net.ipv6.conf.lo.disable_ipv6=1 + + - name: 🔧 Configure docker address pool + run: | + CONFIG='{ + "default-address-pools" : [ + { + "base" : "172.17.0.0/12", + "size" : 20 + }, + { + "base" : "192.168.0.0/16", + "size" : 24 + } + ] + }' + sudo mkdir -p /etc/docker + echo "$CONFIG" | sudo tee /etc/docker/daemon.json + + - name: 🔧 Restart docker daemon + run: sudo systemctl restart docker + + - name: ⬇️ Checkout repo + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + fetch-depth: 0 + persist-credentials: false + + - name: ⎔ Setup pnpm + uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v5.0.0 + with: + version: 10.33.2 + + - name: ⎔ Setup Node 22 for SDK compatibility checks + uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 + with: + node-version: 22.12 + + - name: ⎔ Setup active Node 20 + uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 + with: + node-version: 20.20.2 + cache: "pnpm" + + - name: 🥟 Setup Bun + uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0 + with: + bun-version: latest + + - name: 🦕 Setup Deno + uses: denoland/setup-deno@667a34cdef165d8d2b2e98dde39547c9daac7282 # v2.0.4 + with: + deno-version: v2.x + + - name: 🐳 Login to DockerHub + if: ${{ env.DOCKERHUB_USERNAME }} + uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4.2.0 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: 🐳 Skipping DockerHub login (no secrets available) + if: ${{ !env.DOCKERHUB_USERNAME }} + run: echo "DockerHub login skipped because secrets are not available." + + - name: 🐳 Pre-pull testcontainer images + if: ${{ env.DOCKERHUB_USERNAME }} + run: | + pull() { + for attempt in 1 2 3; do + docker pull "$1" && return 0 + echo "::warning::docker pull $1 failed (attempt ${attempt}/3); retrying in 10s" + sleep 10 + done + echo "::error::docker pull $1 failed after 3 attempts" + return 1 + } + + echo "Pre-pulling Docker images with authenticated session..." + pull postgres:14 + pull clickhouse/clickhouse-server:26.2.19.43-alpine@sha256:c6ad6a7eb2fb5999df3adfb8b69a0c7222c68fa9b8f6b04a088564ebbc959251 + pull redis:7.2 + pull testcontainers/ryuk:0.11.0 + pull testcontainers/ryuk:0.14.0 + pull electricsql/electric:1.2.4 + pull minio/minio:latest + echo "Image pre-pull complete" + + - name: 📥 Download deps + run: pnpm install --frozen-lockfile + + - name: 📀 Generate Prisma Client + run: pnpm run generate + + - name: Run Testbox + uses: useblacksmith/run-testbox@5ca05834db1d3813554d1dd109e5f2087a8d7cbc # v2 + if: ${{ always() && github.event_name == 'workflow_dispatch' }} diff --git a/scripts/blacksmith.md b/scripts/blacksmith.md new file mode 100644 index 00000000000..691e930edba --- /dev/null +++ b/scripts/blacksmith.md @@ -0,0 +1,63 @@ +# Blacksmith Testboxes + +Use Testboxes to validate changes in CI-like runners instead of running tests locally. + +Always run `blacksmith testbox` commands from the repository root: + +```bash +cd "$(git rev-parse --show-toplevel)" +``` + +## PR checks Testbox + +The Linux PR Testbox covers the normal Linux PR checks: format, lint, typecheck, exports, unit test shards, webapp e2e, Linux CLI e2e, and SDK compatibility checks. + +Warm it up: + +```bash +blacksmith testbox warmup pr-testbox.yml --idle-timeout 60 +``` + +Run the PR checks against your current working tree: + +```bash +blacksmith testbox run --id "scripts/test-pr-check.sh" +``` + +## Windows PR checks Testbox + +The Windows PR Testbox covers the Windows CLI v3 e2e matrix row. + +Warm it up: + +```bash +blacksmith testbox warmup pr-testbox-windows.yml --idle-timeout 60 +``` + +Run the Windows checks against your current working tree: + +```bash +blacksmith testbox run --id "pwsh -NoProfile -ExecutionPolicy Bypass -File scripts/test-pr-check-windows.ps1" +``` + +## Running both + +```bash +linux_id= +windows_id= + +blacksmith testbox run --id "$linux_id" "scripts/test-pr-check.sh" +blacksmith testbox run --id "$windows_id" "pwsh -NoProfile -ExecutionPolicy Bypass -File scripts/test-pr-check-windows.ps1" +``` + +## Notes + +- The workflow files must be merged before GitHub can dispatch them via `workflow_dispatch`. +- `blacksmith testbox run` syncs your local tracked and unignored files before running the command. +- If you change dependency manifests, the scripts run `pnpm install` again inside the Testbox. +- The Linux Testbox intentionally does not cover the Windows CLI row; use the Windows Testbox for that. +- Stop Testboxes when you are finished: + +```bash +blacksmith testbox stop --id +``` diff --git a/scripts/test-pr-check-windows.ps1 b/scripts/test-pr-check-windows.ps1 new file mode 100644 index 00000000000..79948177815 --- /dev/null +++ b/scripts/test-pr-check-windows.ps1 @@ -0,0 +1,74 @@ +$ErrorActionPreference = "Stop" + +Set-Location (git rev-parse --show-toplevel) + +function Start-Section { + param([Parameter(Mandatory = $true)][string]$Title) + + Write-Host "" + Write-Host "::group::$Title" +} + +function Stop-Section { + Write-Host "::endgroup::" +} + +function Invoke-Native { + param( + [Parameter(Mandatory = $true)][string]$Command, + [Parameter(ValueFromRemainingArguments = $true)][string[]]$Arguments + ) + + & $Command @Arguments + if ($LASTEXITCODE -ne 0) { + throw "Command failed with exit code ${LASTEXITCODE}: $Command $($Arguments -join ' ')" + } +} + +function Invoke-Section { + param( + [Parameter(Mandatory = $true)][string]$Title, + [Parameter(Mandatory = $true)][scriptblock]$ScriptBlock + ) + + Start-Section $Title + try { + & $ScriptBlock + } finally { + Stop-Section + } +} + +Invoke-Section "Install CLI dependencies" { + Invoke-Native pnpm install --frozen-lockfile --filter trigger.dev... +} + +Invoke-Section "Generate Prisma client" { + Invoke-Native pnpm run generate +} + +Invoke-Section "Build CLI monorepo dependencies" { + Invoke-Native pnpm run build --filter trigger.dev^... +} + +Invoke-Section "Build worker template files" { + Invoke-Native pnpm --filter trigger.dev run --if-present build:workers +} + +Invoke-Section "Enable corepack" { + Invoke-Native corepack enable +} + +Invoke-Section "CLI v3 E2E tests (npm)" { + $env:LOG = "debug" + $env:PM = "npm" + Invoke-Native pnpm --filter trigger.dev run test:e2e +} + +Invoke-Section "CLI v3 E2E tests (pnpm)" { + $env:LOG = "debug" + $env:PM = "pnpm" + Invoke-Native pnpm --filter trigger.dev run test:e2e +} + +Write-Host "Windows PR checks completed." diff --git a/scripts/test-pr-check.sh b/scripts/test-pr-check.sh new file mode 100755 index 00000000000..7ea105e2f92 --- /dev/null +++ b/scripts/test-pr-check.sh @@ -0,0 +1,171 @@ +#!/usr/bin/env bash +set -euo pipefail + +cd "$(git rev-parse --show-toplevel)" + +section() { + local title="$1" + echo "" + echo "::group::${title}" +} + +end_section() { + echo "::endgroup::" +} + +run_section() { + local title="$1" + shift + section "$title" + + local status=0 + if bash -euo pipefail -c '"$@"' bash "$@"; then + status=0 + else + status=$? + fi + + end_section + return "${status}" +} + +find_node_bin() { + local version_prefix="$1" + + if [[ ! -d /opt/hostedtoolcache/node ]]; then + return 0 + fi + + find /opt/hostedtoolcache/node -maxdepth 3 -type d -path "*/${version_prefix}*/x64/bin" 2>/dev/null | sort -V | tail -n 1 +} + +with_node() { + local node_bin="$1" + shift + + if [[ -n "${node_bin}" ]]; then + PATH="${node_bin}:${PATH}" "$@" + else + "$@" + fi +} + +run_webapp_unit_tests() { + for shard in {1..10}; do + echo "Running webapp unit test shard ${shard}/10" + SHARD_INDEX="${shard}" SHARD_TOTAL="10" pnpm run test:webapp --reporter=default --shard="${shard}/10" --passWithNoTests + done +} + +run_package_unit_tests() { + for shard in {1..3}; do + echo "Running package unit test shard ${shard}/3" + SHARD_INDEX="${shard}" SHARD_TOTAL="3" pnpm run test:packages --reporter=default --shard="${shard}/3" --passWithNoTests + done +} + +run_internal_unit_tests() { + for shard in {1..12}; do + echo "Running internal unit test shard ${shard}/12" + SHARD_INDEX="${shard}" SHARD_TOTAL="12" pnpm run test:internal --reporter=default --shard="${shard}/12" --passWithNoTests + done +} + +run_webapp_e2e_tests() { + pnpm run build --filter webapp + (cd apps/webapp && WEBAPP_TEST_VERBOSE="1" pnpm exec vitest run --config vitest.e2e.config.ts --reporter=default) +} + +run_cli_e2e_tests() { + pnpm run build --filter trigger.dev^... + pnpm --filter trigger.dev run --if-present build:workers + corepack enable + + LOG=debug PM=npm pnpm --filter trigger.dev run test:e2e + LOG=debug PM=pnpm pnpm --filter trigger.dev run test:e2e + + echo "Skipped the PR workflow's Windows CLI matrix row; this Testbox is Linux only." +} + +run_sdk_node_compat_tests() { + local node_bin="$1" + local label="$2" + + with_node "${node_bin}" node --version + with_node "${node_bin}" pnpm install --frozen-lockfile + with_node "${node_bin}" pnpm run generate + with_node "${node_bin}" pnpm run build --filter '@trigger.dev/sdk^...' + with_node "${node_bin}" pnpm run build --filter '@trigger.dev/sdk' + with_node "${node_bin}" pnpm --filter @internal/sdk-compat-tests test + + echo "Completed SDK Node compatibility checks for ${label}." +} + +run_sdk_runtime_compat_tests() { + local node20_bin="$1" + + with_node "${node20_bin}" pnpm run build --filter '@trigger.dev/sdk^...' + with_node "${node20_bin}" pnpm run build --filter '@trigger.dev/sdk' + + (cd internal-packages/sdk-compat-tests/src/fixtures/bun && bun run test.ts) + + ( + cd internal-packages/sdk-compat-tests/src/fixtures/deno + if [[ ! -e node_modules && ! -L node_modules ]]; then + ln -s ../../../../../node_modules node_modules + fi + deno run --allow-read --allow-env --allow-sys test.ts + ) + + ( + cd internal-packages/sdk-compat-tests/src/fixtures/cloudflare-worker + pnpm install + npx wrangler deploy --dry-run --outdir dist + ) +} + +export -f find_node_bin +export -f with_node +export -f run_webapp_unit_tests +export -f run_package_unit_tests +export -f run_internal_unit_tests +export -f run_webapp_e2e_tests +export -f run_cli_e2e_tests +export -f run_sdk_node_compat_tests +export -f run_sdk_runtime_compat_tests + +export DATABASE_URL="${DATABASE_URL:-postgresql://postgres:postgres@localhost:5432/postgres}" +export DIRECT_URL="${DIRECT_URL:-postgresql://postgres:postgres@localhost:5432/postgres}" +export SESSION_SECRET="${SESSION_SECRET:-secret}" +export MAGIC_LINK_SECRET="${MAGIC_LINK_SECRET:-secret}" +export ENCRYPTION_KEY="${ENCRYPTION_KEY:-dummy-encryption-keeeey-32-bytes}" +export DEPLOY_REGISTRY_HOST="${DEPLOY_REGISTRY_HOST:-docker.io}" +export CLICKHOUSE_URL="${CLICKHOUSE_URL:-http://default:password@localhost:8123}" +export NODE_OPTIONS="${NODE_OPTIONS:---max-old-space-size=8192}" + +NODE20_BIN="${NODE20_BIN:-$(find_node_bin 20.20)}" +NODE22_BIN="${NODE22_BIN:-$(find_node_bin 22.12)}" + +run_section "Install dependencies" pnpm install --frozen-lockfile +run_section "Generate Prisma client" pnpm run generate + +run_section "Format check" pnpm exec oxfmt --check . +run_section "Lint" pnpm exec oxlint . +run_section "Typecheck" pnpm run typecheck +run_section "Check exports" pnpm run check-exports + +run_section "Webapp unit tests" run_webapp_unit_tests +run_section "Package unit tests" run_package_unit_tests +run_section "Internal unit tests" run_internal_unit_tests +run_section "Webapp E2E tests" run_webapp_e2e_tests +run_section "CLI v3 E2E tests" run_cli_e2e_tests + +run_section "SDK Node 20 compatibility tests" run_sdk_node_compat_tests "${NODE20_BIN}" "Node 20.20" +if [[ -n "${NODE22_BIN}" ]]; then + run_section "SDK Node 22 compatibility tests" run_sdk_node_compat_tests "${NODE22_BIN}" "Node 22.12" +else + echo "::warning::Node 22.12 was not found in /opt/hostedtoolcache; skipping SDK Node 22 compatibility tests." +fi +run_section "SDK Bun/Deno/Cloudflare compatibility tests" run_sdk_runtime_compat_tests "${NODE20_BIN}" + +echo "All Linux PR checks completed."