website-preview.yml 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. env:
  13. VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
  14. VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
  15. jobs:
  16. check-secrets:
  17. runs-on: ubuntu-latest
  18. outputs:
  19. has-vercel-token: ${{ steps.check.outputs.has-vercel-token }}
  20. steps:
  21. - name: Check if VERCEL_TOKEN exists
  22. id: check
  23. run: |
  24. if [ -n "${{ secrets.VERCEL_TOKEN }}" ]; then
  25. echo "has-vercel-token=true" >> $GITHUB_OUTPUT
  26. else
  27. echo "has-vercel-token=false" >> $GITHUB_OUTPUT
  28. fi
  29. preview:
  30. runs-on: ubuntu-latest
  31. needs: check-secrets
  32. if: ${{ needs.check-secrets.outputs.has-vercel-token == 'true' }}
  33. steps:
  34. - name: Checkout code
  35. uses: actions/checkout@v4
  36. - name: Setup Node.js and pnpm
  37. uses: ./.github/actions/setup-node-pnpm
  38. - name: Install Vercel CLI
  39. run: npm install --global vercel@canary
  40. - name: Pull Vercel Environment Information
  41. run: npx vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}
  42. - name: Build Project Artifacts
  43. run: npx vercel build --token=${{ secrets.VERCEL_TOKEN }}
  44. - name: Deploy Project Artifacts to Vercel
  45. id: deploy
  46. run: |
  47. DEPLOYMENT_URL=$(npx vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }})
  48. echo "deployment_url=$DEPLOYMENT_URL" >> $GITHUB_OUTPUT
  49. echo "Preview deployed to: $DEPLOYMENT_URL"
  50. - name: Comment PR with preview link
  51. if: github.event_name == 'pull_request'
  52. uses: actions/github-script@v7
  53. with:
  54. script: |
  55. const deploymentUrl = '${{ steps.deploy.outputs.deployment_url }}';
  56. const commentIdentifier = '<!-- roo-preview-comment -->';
  57. const { data: comments } = await github.rest.issues.listComments({
  58. owner: context.repo.owner,
  59. repo: context.repo.repo,
  60. issue_number: context.issue.number,
  61. });
  62. const existingComment = comments.find(comment =>
  63. comment.body.includes(commentIdentifier)
  64. );
  65. if (existingComment) {
  66. return;
  67. }
  68. 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.';
  69. await github.rest.issues.createComment({
  70. owner: context.repo.owner,
  71. repo: context.repo.repo,
  72. issue_number: context.issue.number,
  73. body: comment
  74. });