Skip to content

feat: add preview build for OSS docs PR #7

feat: add preview build for OSS docs PR

feat: add preview build for OSS docs PR #7

name: Site build preview
on:
pull_request:
types: [opened, synchronize]
branches:
- main
env:
SYNC_REPO: ${{ secrets.SYNC_REPO }}
SYNC_DIRS: "api-design docs guides mcp openapi"
BRANCH_NAME: docs-preview/pr-${{ github.event.pull_request.number }}
jobs:
preview-sync:
runs-on: ubuntu-latest
outputs:
preview-branch: ${{ env.BRANCH_NAME }}
steps:
- name: Checkout developer-docs PR
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Clone marketing-site preview branch
env:
TOKEN: ${{ secrets.SERVICE_BOT_TOKEN }}
run: |
git clone https://x-access-token:${TOKEN}@github.com/${SYNC_REPO}.git private-repo
cd private-repo
git checkout -B $BRANCH_NAME
- name: Sync content folders to preview branch
run: |
set -euo pipefail
for dir in $SYNC_DIRS; do
src_dir="$dir"
dest_dir="private-repo/src/content/$dir"
if [ -d "$src_dir" ]; then
echo "Syncing $src_dir → $dest_dir"
rsync -a --delete "$src_dir/" "$dest_dir/"
else
echo "Warning: $src_dir does not exist, skipping..."
fi
done
- name: Commit and push preview branch
run: |
set -euo pipefail
cd private-repo
git config user.name "Beezy the bot"
git config user.email "marketing@speakeasy.com"
git add .
if git diff --cached --quiet; then
echo "No changes to sync for preview"
exit 0
fi
git commit -m "🔍 Preview sync from developer-docs PR #${{ github.event.pull_request.number }}"
git push origin $BRANCH_NAME --force
deploy-to-vercel:
needs: preview-sync
runs-on: ubuntu-latest
outputs:
deployment-id: ${{ steps.vercel.outputs.deployment-id }}
steps:
- name: Clone synced preview branch
env:
TOKEN: ${{ secrets.SERVICE_BOT_TOKEN }}
run: |
git clone https://x-access-token:${TOKEN}@github.com/${{ secrets.SYNC_REPO }}.git private-repo
cd private-repo
git checkout $BRANCH_NAME
- name: Init minimal Git history (for Vercel CLI)
run: |
cd private-repo
git init
git config user.name "VercelBot"
git config user.email "vercel@bot.com"
git add .
git diff --cached --quiet || git commit -m "CI preview deploy commit"
- name: Deploy to Vercel
id: vercel
uses: amondnet/vercel-action@v25
with:
vercel-token: ${{ secrets.SERVICE_BOT_VERCEL }}
vercel-org-id: ${{ secrets.VERCEL_TEAM_ID }}
vercel-project-id: ${{ secrets.MARKETING_SITE_VERCEL_ID }}
github-token: ${{ secrets.GITHUB_TOKEN }}
working-directory: private-repo
scope: ${{ secrets.VERCEL_TEAM_ID }}
vercel-args: "--prebuilt"
wait-and-comment:
needs: preview-sync
runs-on: ubuntu-latest
steps:
- name: Install Vercel CLI
run: npm install -g vercel
- name: Post "Building..." Sticky Comment
uses: marocchino/sticky-pull-request-comment@v2
with:
number: ${{ github.event.pull_request.number }}
header: VercelPreview
message: |
🟡 **Vercel preview is building...**
- name: Clone marketing-site preview branch
env:
TOKEN: ${{ secrets.SERVICE_BOT_TOKEN }}
run: |
git clone https://x-access-token:${TOKEN}@github.com/${{ secrets.SYNC_REPO }}.git private-repo
cd private-repo
git checkout $BRANCH_NAME
- name: Deploy to Vercel via CLI
id: deploy
working-directory: private-repo
env:
VERCEL_TOKEN: ${{ secrets.SERVICE_BOT_VERCEL }}
run: |
DEPLOY_OUTPUT=$(vercel --prebuilt --yes --token $VERCEL_TOKEN --scope ${{ secrets.VERCEL_TEAM_ID }} --confirm)
echo "$DEPLOY_OUTPUT"
DEPLOYMENT_URL=$(echo "$DEPLOY_OUTPUT" | grep -o 'https://[^ ]*\.vercel\.app' | tail -n1)
DEPLOYMENT_ID=$(echo "$DEPLOY_OUTPUT" | grep -o 'deploymentId":"[^"]*' | cut -d'"' -f3)
echo "deployment-url=$DEPLOYMENT_URL" >> $GITHUB_OUTPUT
echo "deployment-id=$DEPLOYMENT_ID" >> $GITHUB_OUTPUT
- name: Wait for Vercel Deployment
id: wait
uses: vercel/wait-for-deployment@v1
with:
token: ${{ secrets.SERVICE_BOT_VERCEL }}
deployment-id: ${{ steps.deploy.outputs.deployment-id }}
timeout: 900
- name: Update Sticky Comment with Success
if: ${{ steps.wait.outputs.ready-state == 'READY' }}
uses: marocchino/sticky-pull-request-comment@v2
with:
number: ${{ github.event.pull_request.number }}
header: VercelPreview
message: |
✅ **Vercel preview is ready!**
🔗 [View deployment](${{ steps.deploy.outputs.deployment-url }})
- name: Update Sticky Comment with Failure
if: ${{ steps.wait.outputs.ready-state != 'READY' }}
uses: marocchino/sticky-pull-request-comment@v2
with:
number: ${{ github.event.pull_request.number }}
header: VercelPreview
message: |
❌ **Vercel deployment failed.**