# From https://turbo.build/repo/docs/ci/github-actions name: JS CI on: push: pull_request: types: [opened, synchronize] jobs: detect_changes: runs-on: ubuntu-latest outputs: client_did_change: ${{ fromJSON(steps.detect_changes.outputs.result).client_did_change }} docs_did_change: ${{ fromJSON(steps.detect_changes.outputs.result).docs_did_change }} mcp_did_change: ${{ fromJSON(steps.detect_changes.outputs.result).mcp_did_change }} packages_did_change: ${{ fromJSON(steps.detect_changes.outputs.result).packages_did_change }} version_did_change: ${{ fromJSON(steps.detect_changes.outputs.result).version_did_change }} steps: - name: Detect changes id: detect_changes uses: actions/github-script@v7 with: script: | const base = context.payload.before || context.payload.pull_request?.base.sha; const head = context.payload.after || context.payload.pull_request?.head.sha; const owner = context.repo.owner; const repo = context.repo.repo; const { data } = await (base === '0000000000000000000000000000000000000000' ? github.rest.repos.getCommit({ owner, repo, ref: head, }) : github.rest.repos.compareCommits({ owner, repo, base, head, })); const files = data.files.map((f) => f.filename); const output = { client_did_change: false, docs_did_change: false, mcp_did_change: false, packages_did_change: false, version_did_change: false }; for (const file of files) { const changes = { client: file.startsWith('client'), docs: /docs/.test(file), mcpPackages: /^client\/packages\/(mcp|core|platform|admin)/.test(file), mcpDockerfile: file === 'client/Dockerfile.mcp', mcpFly: file === 'client/fly.toml', workflowFile: file === '.github/workflows/js.yml', packages: file.startsWith('client/packages'), version: file === 'client/packages/version/src/version.ts', }; console.log('file', file); console.log('changes', changes); if (changes.client || changes.workflowFile) { console.log('client_did_change', true); output.client_did_change = true; } if (changes.docs) { console.log('docs_did_change', true); output.docs_did_change = true; } if ( changes.mcpPackages || changes.mcpDockerfile || changes.mcpFly || changes.workflowFile ) { console.log('mcp_did_change', true); output.mcp_did_change = true; } if (changes.packages || changes.workflowFile) { console.log('packages_did_change', true); output.packages_did_change = true; } if (changes.version) { console.log('version_did_change', true); output.version_did_change = true; } } console.log('output', output); return output; build: name: Build & Test packages timeout-minutes: 15 runs-on: ubuntu-latest container: image: mcr.microsoft.com/playwright:v1.58.2-noble env: PLAYWRIGHT_BROWSERS_PATH: /ms-playwright needs: [ detect_changes ] if: needs.detect_changes.outputs.client_did_change == 'true' steps: - name: Check out code uses: actions/checkout@v4 with: fetch-depth: 2 - name: Cache turbo build setup uses: actions/cache@v4 with: path: client/.turbo key: ${{ runner.os }}-turbo-${{ github.sha }} restore-keys: | ${{ runner.os }}-turbo- - uses: pnpm/action-setup@v4 with: version: '10.2.0' - name: Setup Node.js environment uses: actions/setup-node@v5 with: node-version: 24 package-manager-cache: false - name: Get pnpm cache directory path id: pnpm-cache-dir-path run: echo "dir=$(pnpm store path --silent)" >> $GITHUB_OUTPUT - uses: actions/cache/restore@v4 with: path: ${{ steps.pnpm-cache-dir-path.outputs.dir }} key: ${{ runner.os }}-pnpm-${{ hashFiles('client/pnpm-lock.yaml') }} restore-keys: | ${{ runner.os }}-pnpm- - name: Install dependencies working-directory: client run: pnpm i --frozen-lockfile --prefer-offline - name: Build packages working-directory: client run: pnpm run build-packages - name: Run tests working-directory: client run: pnpm run test - name: Build sandbox working-directory: client run: pnpm run build-sandbox - name: Run benchmarks working-directory: client run: pnpm run bench - name: Prune store if: github.ref == 'refs/heads/main' working-directory: client run: pnpm store prune - uses: actions/cache/save@v4 if: github.ref == 'refs/heads/main' with: path: ${{ steps.pnpm-cache-dir-path.outputs.dir }} key: ${{ runner.os }}-pnpm-${{ hashFiles('client/pnpm-lock.yaml') }} check_formatting: name: Check formatting timeout-minutes: 15 runs-on: ubuntu-latest needs: [ detect_changes ] if: needs.detect_changes.outputs.client_did_change == 'true' steps: - name: Check out code uses: actions/checkout@v4 with: fetch-depth: 2 - name: Cache turbo build setup uses: actions/cache@v4 with: path: client/.turbo key: ${{ runner.os }}-turbo-${{ github.sha }} restore-keys: | ${{ runner.os }}-turbo- - uses: pnpm/action-setup@v4 with: version: '10.2.0' - name: Setup Node.js environment uses: actions/setup-node@v5 with: node-version: 24 package-manager-cache: false - name: Get pnpm cache directory path id: pnpm-cache-dir-path run: echo "dir=$(pnpm store path --silent)" >> $GITHUB_OUTPUT - uses: actions/cache/restore@v4 with: path: ${{ steps.pnpm-cache-dir-path.outputs.dir }} key: ${{ runner.os }}-pnpm-${{ hashFiles('client/pnpm-lock.yaml') }} restore-keys: | ${{ runner.os }}-pnpm- - name: Install dependencies working-directory: client run: pnpm i --frozen-lockfile --prefer-offline - name: Check prettier formatting working-directory: client run: pnpm run check-format publish-docs: name: Publish algolia changes runs-on: ubuntu-latest needs: [ build, detect_changes ] if: needs.detect_changes.outputs.docs_did_change == 'true' steps: - name: Checkout uses: actions/checkout@v4 - name: Cache turbo build setup uses: actions/cache@v4 with: path: client/.turbo key: ${{ runner.os }}-turbo-${{ github.sha }} restore-keys: | ${{ runner.os }}-turbo- - uses: pnpm/action-setup@v4 with: version: '10.2.0' - name: Setup Node.js environment uses: actions/setup-node@v5 with: node-version: 24 package-manager-cache: false - name: Get pnpm cache directory path id: pnpm-cache-dir-path run: echo "dir=$(pnpm store path --silent)" >> $GITHUB_OUTPUT - uses: actions/cache/restore@v4 with: path: ${{ steps.pnpm-cache-dir-path.outputs.dir }} key: ${{ runner.os }}-pnpm-${{ hashFiles('client/pnpm-lock.yaml') }} restore-keys: | ${{ runner.os }}-pnpm- - name: Install dependencies working-directory: 'client' run: pnpm i --frozen-lockfile --prefer-offline - name: Reindex Algolia env: ALGOLIA_API_KEY: ${{ secrets.ALGOLIA_API_KEY }} working-directory: 'client' run: | if [ "${{ github.ref }}" = "refs/heads/main" ]; then pnpm exec tsx ./www/scripts/index-docs.ts else pnpm exec tsx ./www/scripts/index-docs.ts --dry-run fi - name: Upload algolia objects if: github.ref != 'refs/heads/main' uses: actions/upload-artifact@v4 with: name: algolia-objects path: client/www/scripts/algolia-objects.json deploy-remote-mcp: name: Deploy remote MCP runs-on: ubuntu-latest needs: [ build, detect_changes ] if: github.ref == 'refs/heads/main' && needs.detect_changes.outputs.mcp_did_change == 'true' steps: - name: Checkout uses: actions/checkout@v4 - name: Setup fly uses: superfly/flyctl-actions/setup-flyctl@1.5 - name: Deploy working-directory: 'client' run: flyctl deploy --remote-only env: FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} publish-experimental-package: name: Publish experimental packages runs-on: ubuntu-latest needs: [ detect_changes ] if: github.ref != 'refs/heads/main' && github.event_name == 'push' && needs.detect_changes.outputs.packages_did_change == 'true' permissions: contents: read id-token: write steps: - name: Checkout uses: actions/checkout@v4 - uses: pnpm/action-setup@v4 with: version: '10.2.0' - name: Setup Node.js environment uses: actions/setup-node@v5 with: node-version: 24 package-manager-cache: false registry-url: 'https://registry.npmjs.org' - name: Get pnpm cache directory path id: pnpm-cache-dir-path run: echo "dir=$(pnpm store path --silent)" >> $GITHUB_OUTPUT - uses: actions/cache/restore@v4 with: path: ${{ steps.pnpm-cache-dir-path.outputs.dir }} key: ${{ runner.os }}-pnpm-${{ hashFiles('client/pnpm-lock.yaml') }} restore-keys: | ${{ runner.os }}-pnpm- - name: Install dependencies working-directory: client run: pnpm i --frozen-lockfile --prefer-offline - name: Install babashka working-directory: client run: | curl -L https://github.com/babashka/babashka/releases/download/v1.12.206/babashka-1.12.206-linux-amd64.tar.gz | tar xvz chmod +x bb sudo mv bb /usr/local/bin/ bb --version - name: Set branch name env: HEAD_REF: ${{ github.head_ref }} REF_NAME: ${{ github.ref_name }} run: | if [ "${{ github.event_name }}" = "pull_request" ]; then BRANCH_NAME="$HEAD_REF" else BRANCH_NAME="$REF_NAME" fi # Sanitize branch name for npm version compatibility # Replace / and other invalid characters with - SAFE_BRANCH_NAME=$(echo "$BRANCH_NAME" | sed 's/[^a-zA-Z0-9-]/-/g') echo "BRANCH_NAME=$SAFE_BRANCH_NAME" >> $GITHUB_ENV - name: Update version file working-directory: client/packages/version/src run: | bb -e '(let [file "version.ts" version-js (slurp file) version (->> version-js (re-find #"const version = '"'"'(v\d+\.\d+\.\d+)'"'"'") last) new-version (format "%s-branch-%s.%s.%s" version (System/getenv "BRANCH_NAME") (System/getenv "GITHUB_RUN_ID") (System/getenv "GITHUB_RUN_ATTEMPT"))] (spit file (clojure.string/replace version-js version new-version)))' cat version.ts - name: Publish experimental working-directory: client run: ./scripts/publish_packages.clj "branch-${BRANCH_NAME}" env: NPM_CONFIG_PROVENANCE: true - name: Debug if: failure() uses: actions/upload-artifact@v4 with: name: npm-logs path: /home/runner/.npm/_logs/ publish-packages: name: Publish packages runs-on: ubuntu-latest needs: [ build, detect_changes ] if: github.ref == 'refs/heads/main' && needs.detect_changes.outputs.version_did_change == 'true' permissions: contents: write id-token: write steps: - name: Checkout uses: actions/checkout@v4 with: ref: ${{ github.head_ref }} - uses: pnpm/action-setup@v4 with: version: '10.2.0' - name: Setup Node.js environment uses: actions/setup-node@v5 with: node-version: 24 package-manager-cache: false registry-url: 'https://registry.npmjs.org' - name: Get pnpm cache directory path id: pnpm-cache-dir-path run: echo "dir=$(pnpm store path --silent)" >> $GITHUB_OUTPUT - uses: actions/cache/restore@v4 with: path: ${{ steps.pnpm-cache-dir-path.outputs.dir }} key: ${{ runner.os }}-pnpm-${{ hashFiles('client/pnpm-lock.yaml') }} restore-keys: | ${{ runner.os }}-pnpm- - name: Install dependencies working-directory: client run: pnpm i --frozen-lockfile --prefer-offline - name: Install babashka working-directory: client run: | curl -L https://github.com/babashka/babashka/releases/download/v1.12.206/babashka-1.12.206-linux-amd64.tar.gz | tar xvz chmod +x bb sudo mv bb /usr/local/bin/ bb --version - name: Publish working-directory: client run: make publish-ci env: NPM_CONFIG_PROVENANCE: true - name: Debug if: failure() uses: actions/upload-artifact@v4 with: name: npm-logs path: /home/runner/.npm/_logs/ vercel-preview: name: Deploy to vercel preview runs-on: ubuntu-latest needs: [ detect_changes ] if: github.ref != 'refs/heads/main' && needs.detect_changes.outputs.client_did_change == 'true' environment: name: Preview url: ${{ steps.deploy.outputs.url }} env: VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} steps: - name: Checkout uses: actions/checkout@v4 - name: Cache turbo build setup uses: actions/cache@v4 with: path: client/.turbo key: ${{ runner.os }}-turbo-${{ github.sha }} restore-keys: | ${{ runner.os }}-turbo- - uses: pnpm/action-setup@v4 with: version: '10.2.0' - name: Setup Node.js environment uses: actions/setup-node@v5 with: node-version: 24 package-manager-cache: false - name: Get pnpm cache directory path id: pnpm-cache-dir-path run: echo "dir=$(pnpm store path --silent)" >> $GITHUB_OUTPUT - uses: actions/cache/restore@v4 with: path: ${{ steps.pnpm-cache-dir-path.outputs.dir }} key: ${{ runner.os }}-pnpm-${{ hashFiles('client/pnpm-lock.yaml') }} restore-keys: | ${{ runner.os }}-pnpm- - name: Install Vercel CLI run: npm install --g vercel@canary - name: Pull Vercel Environment Information run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }} - name: Set branch name env: HEAD_REF: ${{ github.head_ref }} REF_NAME: ${{ github.ref_name }} run: | if [ "${{ github.event_name }}" = "pull_request" ]; then branch="$HEAD_REF" else branch="$REF_NAME" fi echo "BRANCH_NAME=$branch" >> $GITHUB_ENV safeBranch=$(echo "$branch" | sed 's/[^a-zA-Z0-9-]/-/g') echo "SAFE_BRANCH=$safeBranch" >> $GITHUB_ENV - name: Build Project Artifacts run: vercel build --token=${{ secrets.VERCEL_TOKEN }} env: NEXT_PUBLIC_VERCEL_URL: instant-www-js-${{ env.SAFE_BRANCH }}-jsv.vercel.app - name: Deploy Project Artifacts to Vercel id: deploy run: | vercel deploy --prebuilt --archive=tgz --token=${{ secrets.VERCEL_TOKEN }} >deployment-url.txt code=$? if [ $code -eq 0 ]; then deploymentUrl=`cat deployment-url.txt` aliasUrl="instant-www-js-$SAFE_BRANCH-jsv.vercel.app" echo "ALIAS_URL=$aliasUrl" >> $GITHUB_ENV echo "url=https://$aliasUrl" >> $GITHUB_OUTPUT echo "aliasing $deploymentUrl to https://$aliasUrl" vercel alias $deploymentUrl $aliasUrl --token=${{ secrets.VERCEL_TOKEN }} --scope jsv else echo "There was an error" exit 1 fi - name: Comment on PR with deploy preview url uses: actions/github-script@v7 if: github.event_name == 'pull_request' with: script: | const url = process.env.ALIAS_URL; const body = `View Vercel preview at [${url}](https://${url}).`; const { data: comments } = await github.rest.issues.listComments({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, }); // Check if the comment already exists const comment = comments.find((comment) => comment.body === body); if (!comment) { github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, body, }); } else { console.log("Already commented", comment); } vercel-prod-deploy: name: Deploy to vercel production runs-on: ubuntu-latest needs: [ detect_changes ] if: github.ref == 'refs/heads/main' && needs.detect_changes.outputs.client_did_change == 'true' environment: name: Production url: ${{ steps.deploy.outputs.url }} env: VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} steps: - name: Checkout uses: actions/checkout@v4 - name: Cache turbo build setup uses: actions/cache@v4 with: path: client/.turbo key: ${{ runner.os }}-turbo-${{ github.sha }} restore-keys: | ${{ runner.os }}-turbo- - uses: pnpm/action-setup@v4 with: version: '10.2.0' - name: Setup Node.js environment uses: actions/setup-node@v5 with: node-version: 24 package-manager-cache: false - name: Get pnpm cache directory path id: pnpm-cache-dir-path run: echo "dir=$(pnpm store path --silent)" >> $GITHUB_OUTPUT - uses: actions/cache/restore@v4 with: path: ${{ steps.pnpm-cache-dir-path.outputs.dir }} key: ${{ runner.os }}-pnpm-${{ hashFiles('client/pnpm-lock.yaml') }} restore-keys: | ${{ runner.os }}-pnpm- - name: Install Vercel CLI run: npm install --g vercel@canary - name: Pull Vercel Environment Information run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }} - name: Build Project Artifacts run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }} - name: Deploy Project Artifacts to Vercel id: deploy run: | vercel deploy --prebuilt --prod --archive=tgz --token=${{ secrets.VERCEL_TOKEN }} >deployment-url.txt code=$? if [ $code -eq 0 ]; then deploymentUrl=`cat deployment-url.txt` echo "url=$deploymentUrl" >> $GITHUB_OUTPUT else echo "There was an error" exit 1 fi vercel-staging-deploy: name: Deploy to vercel staging runs-on: ubuntu-latest if: contains(github.event.head_commit.message, '[staging]') env: VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} steps: - name: Checkout uses: actions/checkout@v4 - name: Cache turbo build setup uses: actions/cache@v4 with: path: client/.turbo key: ${{ runner.os }}-turbo-${{ github.sha }} restore-keys: | ${{ runner.os }}-turbo- - uses: pnpm/action-setup@v4 with: version: '10.2.0' - name: Setup Node.js environment uses: actions/setup-node@v5 with: node-version: 24 package-manager-cache: false - name: Get pnpm cache directory path id: pnpm-cache-dir-path run: echo "dir=$(pnpm store path --silent)" >> $GITHUB_OUTPUT - uses: actions/cache/restore@v4 with: path: ${{ steps.pnpm-cache-dir-path.outputs.dir }} key: ${{ runner.os }}-pnpm-${{ hashFiles('client/pnpm-lock.yaml') }} restore-keys: | ${{ runner.os }}-pnpm- - name: Install Vercel CLI run: npm install --g vercel@canary - name: Pull Vercel Environment Information run: vercel pull --yes --environment=staging --token=${{ secrets.VERCEL_TOKEN }} - name: Build Project Artifacts run: vercel build --target=staging --token=${{ secrets.VERCEL_TOKEN }} - name: Deploy Project Artifacts to Vercel run: vercel deploy --prebuilt --target=staging --archive=tgz --token=${{ secrets.VERCEL_TOKEN }}