website-preview.yml 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. name: Preview roocode.com
  2. on:
  3. push:
  4. branches-ignore:
  5. - main
  6. paths:
  7. - "apps/web-roo-code/**"
  8. pull_request:
  9. paths:
  10. - "apps/web-roo-code/**"
  11. workflow_dispatch:
  12. concurrency:
  13. group: preview-roocode-com-${{ github.ref }}
  14. cancel-in-progress: true
  15. env:
  16. VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
  17. VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
  18. jobs:
  19. check-secrets:
  20. runs-on: ubuntu-latest
  21. outputs:
  22. has-vercel-token: ${{ steps.check.outputs.has-vercel-token }}
  23. steps:
  24. - name: Check if VERCEL_TOKEN exists
  25. id: check
  26. run: |
  27. if [ -n "${{ secrets.VERCEL_TOKEN }}" ]; then
  28. echo "has-vercel-token=true" >> $GITHUB_OUTPUT
  29. else
  30. echo "has-vercel-token=false" >> $GITHUB_OUTPUT
  31. fi
  32. preview:
  33. runs-on: ubuntu-latest
  34. needs: check-secrets
  35. if: ${{ needs.check-secrets.outputs.has-vercel-token == 'true' }}
  36. steps:
  37. - name: Checkout code
  38. uses: actions/checkout@v4
  39. - name: Setup Node.js and pnpm
  40. uses: ./.github/actions/setup-node-pnpm
  41. - name: Run lint
  42. run: pnpm lint
  43. working-directory: apps/web-roo-code
  44. - name: Run type check
  45. run: pnpm check-types
  46. working-directory: apps/web-roo-code
  47. - name: Run build
  48. run: pnpm build
  49. working-directory: apps/web-roo-code
  50. - name: Install Vercel CLI
  51. run: npm install --global vercel@latest
  52. - name: Pull Vercel Environment Information
  53. run: npx vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}
  54. - name: Build Project Artifacts
  55. run: npx vercel build --token=${{ secrets.VERCEL_TOKEN }}
  56. - name: Deploy Project Artifacts to Vercel
  57. id: deploy
  58. run: |
  59. DEPLOYMENT_URL=$(npx vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }})
  60. echo "deployment_url=$DEPLOYMENT_URL" >> $GITHUB_OUTPUT
  61. echo "Preview deployed to: $DEPLOYMENT_URL"
  62. - name: Comment PR with preview link
  63. if: github.event_name == 'pull_request'
  64. uses: actions/github-script@v7
  65. with:
  66. script: |
  67. const deploymentUrl = '${{ steps.deploy.outputs.deployment_url }}';
  68. const commentIdentifier = '<!-- roo-preview-comment -->';
  69. const { data: comments } = await github.rest.issues.listComments({
  70. owner: context.repo.owner,
  71. repo: context.repo.repo,
  72. issue_number: context.issue.number,
  73. });
  74. const existingComment = comments.find(comment =>
  75. comment.body.includes(commentIdentifier)
  76. );
  77. const comment = commentIdentifier + '\n🚀 **Preview deployed!**\n\nYour changes have been deployed to Vercel:\n\n**Preview URL:** ' + deploymentUrl + '\n\nThis preview will be updated automatically when you push new commits to this PR.';
  78. if (existingComment) {
  79. await github.rest.issues.updateComment({
  80. owner: context.repo.owner,
  81. repo: context.repo.repo,
  82. comment_id: existingComment.id,
  83. body: comment
  84. });
  85. } else {
  86. await github.rest.issues.createComment({
  87. owner: context.repo.owner,
  88. repo: context.repo.repo,
  89. issue_number: context.issue.number,
  90. body: comment
  91. });
  92. }