name: Package Validation on: push: branches: [main] pull_request: branches: [main] # Reusable workflows cannot elevate the caller's token permissions. # detect-changes.yml reads pull-request file lists and commit comparisons. permissions: contents: read pull-requests: read concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true env: AGENT_RELAY_TELEMETRY_DISABLED: 1 jobs: changes: if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository uses: ./.github/workflows/detect-changes.yml validate: name: Build & Validate needs: changes if: >- (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) && (needs.changes.outputs.node_changed == 'true') runs-on: ubuntu-latest env: NPM_CONFIG_FUND: false steps: - name: Checkout code uses: actions/checkout@v4 - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: '22' # Restore node_modules — skip npm ci entirely if unchanged. Split # restore/save (instead of actions/cache@v4) so the cache is saved # right after `npm ci` produces a clean tree; otherwise the implicit # post-job save runs after `pack:validate`, which deletes # `packages/*/node_modules` and poisons the cache for the next run # (the CLI fails at runtime with `Cannot find package 'posthog-node'` # because the cached telemetry workspace has no nested deps). - name: Restore node_modules id: cache-modules uses: actions/cache/restore@v4 with: # Include nested workspace node_modules so unhoisted workspace deps # survive a cache hit — otherwise the cache restores only the root # tree and skipping `npm ci` can leave the bundler unable to resolve # them. path: | node_modules packages/*/node_modules key: modules-v3-${{ hashFiles('package-lock.json') }} - name: Install dependencies if: steps.cache-modules.outputs.cache-hit != 'true' run: npm ci # Save the freshly-installed node_modules immediately, before any # later step (notably `pack:validate`) mutates the tree. - name: Save node_modules if: steps.cache-modules.outputs.cache-hit != 'true' uses: actions/cache/save@v4 with: path: | node_modules packages/*/node_modules key: modules-v3-${{ hashFiles('package-lock.json') }} - name: Build packages run: | npm run build # cloud sits outside the core build chain; # build it so package validation can verify its dist output. npm --prefix packages/cloud run build - name: Validate all run: | echo "=== Validating packages ===" ERRORS=0 # Check dist files exist (skip non-Node package directories). SKIP_PACKAGES="build-plans personas" for pkg_dir in packages/*/; do pkg_name=$(basename "$pkg_dir") if [ ! -f "$pkg_dir/package.json" ]; then echo "⊘ $pkg_name - skipped (non-Node package)" continue fi if echo "$SKIP_PACKAGES" | grep -qw "$pkg_name"; then echo "⊘ $pkg_name - skipped (non-Node package)" continue fi if [ ! -f "$pkg_dir/dist/index.js" ] || [ ! -f "$pkg_dir/dist/index.d.ts" ]; then echo "✗ $pkg_name - missing dist files" ERRORS=$((ERRORS + 1)) else echo "✓ $pkg_name" fi done [ $ERRORS -gt 0 ] && exit 1 echo "" echo "=== Testing key imports ===" node --eval " const packages = [ '@agent-relay/sdk', '@agent-relay/config', '@agent-relay/utils', ]; (async () => { let errors = 0; for (const pkg of packages) { try { await import(pkg); console.log('✓', pkg); } catch (e) { console.error('✗', pkg, '-', e.message); errors++; } } if (errors) process.exit(1); })(); " echo "" echo "=== Testing main package ===" node --eval " import('./packages/cli/dist/index.js').then(m => { const required = ['AgentRelay', 'createLogger']; const missing = required.filter(r => !(r in m)); if (missing.length) { console.error('Missing exports:', missing); process.exit(1); } console.log('✓ Main package exports OK'); }); " echo "" echo "SUCCESS: All validations passed" - name: Test CLI startup run: | set -euo pipefail CLI="node packages/cli/dist/cli/index.js" $CLI --version $CLI --help > /dev/null echo "✓ CLI starts" # A removed broker verb must explain itself, not crash. if OUTPUT="$($CLI node up 2>&1)"; then echo "✗ relay node up unexpectedly succeeded" >&2 exit 1 fi echo "$OUTPUT" | grep -q "was removed together with the local broker" echo "✓ relay node up prints the removal notice" # Keep tarball validation after runtime smoke tests. The tarball # validator removes nested workspace node_modules before packing so the # package cannot accidentally include them. - name: Validate npm tarball artifact run: npm run pack:validate publish-fresh-install-build: name: Publish Fresh Install Build needs: changes if: >- (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) && (needs.changes.outputs.node_changed == 'true') runs-on: ubuntu-latest env: NPM_CONFIG_FUND: false steps: - name: Checkout code uses: actions/checkout@v4 - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: '22.14.0' - name: Upgrade npm before fresh resolution # See publish.yml's "Upgrade npm before fresh resolution" step: npm # <=10.9.x's arborist crashes re-resolving a deep optional # peer set once the lockfile is gone (npm/cli#8261). Fixed by npm # version, not Node version — confirmed via repro on npm 10.9.4/Node # 22.22.0 still crashing and npm 11.19.1/Node 22.14.0 succeeding. run: npm install -g npm@11.19.1 # The publish workflow bumps versions, removes package-lock.json, then # runs npm install. This catches range-resolved dependency breaks before merge. - name: Install dependencies with publish resolution run: | rm -rf node_modules packages/*/node_modules package-lock.json npm install - name: Ensure rollup optional dependencies are installed run: npm install --no-save rollup || true - name: Build TypeScript packages env: NODE_OPTIONS: --max-old-space-size=4096 run: | npm run build # cloud sits outside the core build chain, same as the validate job. npm --prefix packages/cloud run build standalone-macos-smoke: name: Standalone macOS Smoke needs: changes # Builds, signs and runs the Bun standalone CLI on macOS; needs no secrets. if: needs.changes.outputs.node_changed == 'true' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) runs-on: macos-latest env: NPM_CONFIG_FUND: false steps: - name: Checkout code uses: actions/checkout@v4 - name: Setup Bun uses: oven-sh/setup-bun@v2 with: bun-version: latest - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: '22' - name: Install dependencies run: npm ci - name: Build packages run: npm run build - name: Build standalone binary run: | mkdir -p release-binaries VERSION="$(node -p "require('./package.json').version")" ARCH="$(uname -m)" if [ "$ARCH" = "arm64" ]; then TARGET="bun-darwin-arm64" OUTPUT="agent-relay-darwin-arm64" EXPECTED_ARCH="arm64" elif [ "$ARCH" = "x86_64" ]; then TARGET="bun-darwin-x64" OUTPUT="agent-relay-darwin-x64" EXPECTED_ARCH="x86_64" else echo "Unsupported macOS runner architecture: $ARCH" exit 1 fi bun build \ --compile \ --minify \ --target="$TARGET" \ --external=better-sqlite3 \ --define="process.env.AGENT_RELAY_VERSION=\"${VERSION}\"" \ ./packages/cli/dist/cli/index.js \ --outfile "release-binaries/${OUTPUT}" scripts/sign-macos-binary.sh "release-binaries/${OUTPUT}" scripts/verify-macos-binary.sh "release-binaries/${OUTPUT}" "$EXPECTED_ARCH" -- --version echo "STANDALONE_CLI=$PWD/release-binaries/${OUTPUT}" >> "$GITHUB_ENV" - name: Verify standalone MCP dispatches each request once run: node scripts/verify-standalone-mcp-single-dispatch.mjs "$STANDALONE_CLI" - name: Smoke standalone CLI run: | set -euo pipefail "$STANDALONE_CLI" --version "$STANDALONE_CLI" --help > /dev/null