feat: add preview build for OSS docs PR #2
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| 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 | |
| comment-vercel-preview: | |
| needs: preview-sync | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Install jq | |
| run: sudo apt-get update && sudo apt-get install -y jq | |
| - name: Wait for Vercel Deployment | |
| id: wait-for-vercel | |
| env: | |
| VERCEL_TOKEN: ${{ secrets.SERVICE_BOT_VERCEL }} | |
| VERCEL_PROJECT_ID: ${{ secrets.MARKETING_SITE_VERCEL_ID }} | |
| VERCEL_TEAM_ID: ${{ secrets.VERCEL_TEAM_ID }} | |
| run: | | |
| sleep 10 | |
| for i in {1..20}; do | |
| echo "Polling for Vercel deployment for $BRANCH_NAME... (attempt $i)" | |
| response=$(curl -s -H "Authorization: Bearer $VERCEL_TOKEN" \ | |
| "https://api.vercel.com/v6/deployments?projectId=$VERCEL_PROJECT_ID&target=preview&teamId=$VERCEL_TEAM_ID&limit=5") | |
| deploy=$(echo "$response" | jq -r --arg branch "$BRANCH_NAME" '.deployments[] | select(.meta.githubBranch == $branch) | .url' | head -n 1) | |
| if [ -n "$deploy" ]; then | |
| echo "Found deployment: $deploy" | |
| echo "url=https://$deploy" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| sleep 5 | |
| done | |
| echo "Timed out waiting for Vercel deployment." | |
| exit 1 | |
| - name: Comment with Vercel Preview | |
| uses: marocchino/sticky-pull-request-comment@v2 | |
| with: | |
| message: | | |
| 🚀 **Preview your content changes here**: | |
| 🔗 [View on Vercel](${{ steps.wait-for-vercel.outputs.url }}) |