name: Preview Documentation on: pull_request: merge_group: permissions: contents: read env: # Among other things, opts out of Turborepo telemetry # See https://consoledonottrack.com/ DO_NOT_TRACK: '1' NEXT_TELEMETRY_DISABLED: '1' VERCEL_TELEMETRY_DISABLED: '1' # Some tasks slow down considerably on GitHub Actions runners when concurrency is high TURBO_CONCURRENCY: 1 # Enables Turborepo Remote Caching. TURBO_REMOTE_CACHE_SIGNATURE_KEY: ${{ secrets.TURBO_REMOTE_CACHE_SIGNATURE_KEY }} TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} TURBO_TEAM: ${{ vars.TURBO_TEAM }} jobs: detect-docs-changes: permissions: contents: read pull-requests: read runs-on: ubuntu-latest name: Detect Documentation Changes outputs: docs: ${{ steps.filter.outputs.docs }} steps: - name: Checkout Merge Group if: github.event_name == 'merge_group' uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Detect Documentation Changes uses: dorny/paths-filter@ceb8a2b8f2d89434be7ff52d3de7ec3738c5cc9d # v4.0.3 id: filter with: filters: | docs: - 'docs/**' - '.github/workflows/preview-docs.yml' preview-docs: needs: detect-docs-changes if: needs.detect-docs-changes.outputs.docs == 'true' permissions: contents: read pull-requests: write runs-on: ubuntu-latest name: Build Documentation Preview steps: - name: Checkout uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Install Dependencies uses: ./.github/workflows/actions/install-dependencies - name: Install Isolated Docs Dependencies working-directory: ./docs/ shell: bash run: pnpm install --ignore-workspace - name: Build Documentation for Merge Queue if: github.event_name == 'merge_group' working-directory: ./docs/ shell: bash run: pnpm build - name: Install Vercel CLI if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]' run: pnpm install -g vercel - name: Deploy to Vercel if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]' shell: bash id: vercel_deploy env: BRANCH_NAME: ${{ github.head_ref }} PR_NUMBER: ${{ github.event.pull_request.number }} VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} VERCEL_PROJECT_ID: ${{ secrets.VERCEL_DOCS_PROJECT_ID }} VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} run: | vercel pull --token="$VERCEL_TOKEN" --yes --environment=preview vercel build --token="$VERCEL_TOKEN" --target=preview if ! DEPLOY_OUTPUT=$(vercel deploy --token="$VERCEL_TOKEN" --archive=tgz --env GITHUB_PR_NUMBER="$PR_NUMBER" --env GITHUB_PR_BRANCH="$BRANCH_NAME" --prebuilt --target=preview 2>&1); then echo "Vercel deploy failed:" echo "$DEPLOY_OUTPUT" exit 1 fi DEPLOY_URL=$(echo "$DEPLOY_OUTPUT" | grep -o 'https://[a-zA-Z0-9.-]*\.vercel\.app' | tail -1) echo "preview_url=$DEPLOY_URL" >> "$GITHUB_OUTPUT" - name: Comment on PR with Preview URL if: steps.vercel_deploy.outcome == 'success' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} PR_NUMBER: ${{ github.event.pull_request.number }} PREVIEW_URL: '${{ steps.vercel_deploy.outputs.preview_url }}' run: | gh pr comment $PR_NUMBER --body "Documentation Preview: $PREVIEW_URL" --create-if-none --edit-last preview-docs-gate: needs: - detect-docs-changes - preview-docs # We use always() to ensure this step runs even if the previous steps fail # Don't check cancelled() because then cancelling the workflow would make this pass if: always() runs-on: ubuntu-latest name: Documentation Preview Gate steps: - name: Verify Documentation Preview Result shell: bash env: DETECT_RESULT: ${{ needs.detect-docs-changes.result }} DOCS_CHANGED: ${{ needs.detect-docs-changes.outputs.docs }} PREVIEW_RESULT: ${{ needs.preview-docs.result }} run: | if [[ "$DETECT_RESULT" != 'success' ]]; then echo "Documentation change detection did not succeed: $DETECT_RESULT" exit 1 fi if [[ "$DOCS_CHANGED" == 'true' && "$PREVIEW_RESULT" != 'success' ]]; then echo "Documentation preview did not succeed: $PREVIEW_RESULT" exit 1 fi if [[ "$DOCS_CHANGED" != 'true' && "$DOCS_CHANGED" != 'false' ]]; then echo "Documentation change detection returned an invalid result: $DOCS_CHANGED" exit 1 fi