|
| 1 | +name: Deploy website |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + paths: |
| 7 | + - "js/website/**" |
| 8 | + - "js/core/**" |
| 9 | + - "js/react/**" |
| 10 | + - "crates/browser/**" |
| 11 | + pull_request: |
| 12 | + paths: |
| 13 | + - "js/website/**" |
| 14 | + - "js/core/**" |
| 15 | + - "js/react/**" |
| 16 | + - "crates/browser/**" |
| 17 | + |
| 18 | +jobs: |
| 19 | + deploy: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + permissions: |
| 22 | + pull-requests: write |
| 23 | + steps: |
| 24 | + - uses: actions/checkout@v4 |
| 25 | + - uses: DeterminateSystems/nix-installer-action@main |
| 26 | + - uses: DeterminateSystems/magic-nix-cache-action@main |
| 27 | + - name: Deploy to Vercel |
| 28 | + id: deploy |
| 29 | + run: | |
| 30 | + args=() |
| 31 | + if [ "${{ github.event_name }}" = "push" ] && [ "${{ github.ref }}" = "refs/heads/main" ]; then |
| 32 | + args+=(--prod) |
| 33 | + fi |
| 34 | + output=$(./bin/deploy-website "${args[@]}" 2>&1 | tee /dev/stderr) || exit $? |
| 35 | + url=$(echo "$output" | grep -o 'https://[^ ]*\.vercel\.app' | tail -1) |
| 36 | + echo "url=$url" >> "$GITHUB_OUTPUT" |
| 37 | + env: |
| 38 | + VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} |
| 39 | + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} |
| 40 | + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} |
| 41 | + - name: Comment preview URL on PR |
| 42 | + if: github.event_name == 'pull_request' && steps.deploy.outputs.url |
| 43 | + uses: actions/github-script@v7 |
| 44 | + with: |
| 45 | + script: | |
| 46 | + const body = `🔗 **Preview:** ${{ steps.deploy.outputs.url }}`; |
| 47 | + const { data: comments } = await github.rest.issues.listComments({ |
| 48 | + owner: context.repo.owner, |
| 49 | + repo: context.repo.repo, |
| 50 | + issue_number: context.issue.number, |
| 51 | + }); |
| 52 | + const existing = comments.find(c => c.body.startsWith('🔗 **Preview:**')); |
| 53 | + if (existing) { |
| 54 | + await github.rest.issues.updateComment({ |
| 55 | + owner: context.repo.owner, |
| 56 | + repo: context.repo.repo, |
| 57 | + comment_id: existing.id, |
| 58 | + body, |
| 59 | + }); |
| 60 | + } else { |
| 61 | + await github.rest.issues.createComment({ |
| 62 | + owner: context.repo.owner, |
| 63 | + repo: context.repo.repo, |
| 64 | + issue_number: context.issue.number, |
| 65 | + body, |
| 66 | + }); |
| 67 | + } |
0 commit comments