preview-docs.yml 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. name: Preview Documentation
  2. on:
  3. pull_request:
  4. paths:
  5. - 'docs/**'
  6. permissions:
  7. contents: read
  8. env:
  9. # Among other things, opts out of Turborepo telemetry
  10. # See https://consoledonottrack.com/
  11. DO_NOT_TRACK: '1'
  12. NEXT_TELEMETRY_DISABLED: '1'
  13. VERCEL_TELEMETRY_DISABLED: '1'
  14. # Some tasks slow down considerably on GitHub Actions runners when concurrency is high
  15. TURBO_CONCURRENCY: 1
  16. # Enables Turborepo Remote Caching.
  17. TURBO_REMOTE_CACHE_SIGNATURE_KEY: ${{ secrets.TURBO_REMOTE_CACHE_SIGNATURE_KEY }}
  18. TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
  19. TURBO_TEAM: ${{ vars.TURBO_TEAM }}
  20. jobs:
  21. preview-docs:
  22. if: github.actor != 'dependabot[bot]'
  23. permissions:
  24. pull-requests: write
  25. runs-on: ubuntu-latest
  26. name: Build Documentation Preview
  27. steps:
  28. - name: Checkout
  29. uses: actions/checkout@v4
  30. - name: Install Dependencies
  31. uses: ./.github/workflows/actions/install-dependencies
  32. - name: Install Isolated Docs Dependencies
  33. working-directory: ./docs/
  34. shell: bash
  35. run: pnpm install --ignore-workspace
  36. - name: Install Vercel CLI
  37. run: pnpm install -g vercel
  38. - name: Deploy to Vercel
  39. shell: bash
  40. id: vercel_deploy
  41. env:
  42. BRANCH_NAME: ${{ github.head_ref }}
  43. PR_NUMBER: ${{ github.event.pull_request.number }}
  44. VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
  45. VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
  46. VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
  47. run: |
  48. vercel pull --token="$VERCEL_TOKEN" --yes --environment=preview
  49. vercel build --token="$VERCEL_TOKEN" --prod=false
  50. DEPLOY_OUTPUT=$(vercel deploy --token="$VERCEL_TOKEN" --archive=tgz --env GITHUB_PR_NUMBER="$PR_NUMBER" --env GITHUB_PR_BRANCH="$BRANCH_NAME" --prebuilt --prod=false 2>&1)
  51. DEPLOY_EXIT_CODE=$?
  52. if [ $DEPLOY_EXIT_CODE -ne 0 ]; then
  53. echo "Vercel deploy failed:"
  54. echo "$DEPLOY_OUTPUT"
  55. exit $DEPLOY_EXIT_CODE
  56. fi
  57. DEPLOY_URL=$(echo "$DEPLOY_OUTPUT" | grep -o 'https://[a-zA-Z0-9.-]*\.vercel\.app' | tail -1)
  58. echo "preview_url=$DEPLOY_URL" >> $GITHUB_OUTPUT
  59. - name: Comment on PR with Preview URL
  60. env:
  61. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  62. PR_NUMBER: ${{ github.event.pull_request.number }}
  63. PREVIEW_URL: '${{ steps.vercel_deploy.outputs.preview_url }}'
  64. run: |
  65. gh pr comment $PR_NUMBER --body "Documentation Preview: $PREVIEW_URL" --create-if-none --edit-last