|
1 | 1 | name: 'Comment Vercel Preview' |
2 | 2 | description: 'Comment Vercel deploy preview links on a PR.' |
3 | 3 | inputs: |
4 | | - inspect_url: |
5 | | - description: 'Inspect URL from Vercel deploy output.' |
6 | | - required: true |
7 | | - preview_url: |
8 | | - description: 'Preview/Production URL from Vercel deploy output.' |
9 | | - required: true |
10 | | - label: |
11 | | - description: 'Label for the deployment (e.g., EN, ZH-HANS).' |
| 4 | + deploy_results_path: |
| 5 | + description: 'Path to the JSON file containing all deploy results.' |
12 | 6 | required: true |
13 | 7 | runs: |
14 | 8 | using: 'composite' |
15 | 9 | steps: |
16 | | - - name: Comment PR with Vercel Preview Links |
| 10 | + - name: Comment PR with all Vercel Preview Links |
17 | 11 | uses: actions/github-script@v7 |
18 | 12 | with: |
19 | 13 | script: | |
20 | | - const inspect = process.env.INSPECT_URL; |
21 | | - const preview = process.env.PREVIEW_URL; |
22 | | - let body = `**Vercel Deploy Preview (${process.env.LABEL})**\n\n`; |
23 | | - body += `- [Inspect](${inspect}) | [Preview](${preview})`; |
24 | | - github.rest.issues.createComment({ |
| 14 | + const fs = require('fs'); |
| 15 | + const path = process.env.DEPLOY_RESULTS_PATH; |
| 16 | + const marker = '<!-- vercel-preview-links -->'; |
| 17 | + const results = JSON.parse(fs.readFileSync(path, 'utf8')); |
| 18 | + let body = `${marker}\n`; |
| 19 | + body += `## Vercel Deploy Previews\n`; |
| 20 | + console.log('Deploy results:', results); |
| 21 | + // Handle array of deploy results |
| 22 | + for (const job of results) { |
| 23 | + if (job && job.label) { |
| 24 | + body += `- **${job.label}**: [Inspect](${job.inspect_url}) | [Preview](${job.preview_url})\n`; |
| 25 | + } |
| 26 | + } |
| 27 | + // Find existing comment |
| 28 | + const { data: comments } = await github.rest.issues.listComments({ |
25 | 29 | issue_number: context.issue.number, |
26 | 30 | owner: context.repo.owner, |
27 | 31 | repo: context.repo.repo, |
28 | | - body |
29 | 32 | }); |
| 33 | + const existing = comments.find(c => c.body && c.body.includes(marker)); |
| 34 | + if (existing) { |
| 35 | + await github.rest.issues.updateComment({ |
| 36 | + comment_id: existing.id, |
| 37 | + owner: context.repo.owner, |
| 38 | + repo: context.repo.repo, |
| 39 | + body |
| 40 | + }); |
| 41 | + } else { |
| 42 | + await github.rest.issues.createComment({ |
| 43 | + issue_number: context.issue.number, |
| 44 | + owner: context.repo.owner, |
| 45 | + repo: context.repo.repo, |
| 46 | + body |
| 47 | + }); |
| 48 | + } |
30 | 49 | env: |
31 | | - INSPECT_URL: ${{ inputs.inspect_url }} |
32 | | - PREVIEW_URL: ${{ inputs.preview_url }} |
33 | | - LABEL: ${{ inputs.label }} |
| 50 | + DEPLOY_RESULTS_PATH: ${{ inputs.deploy_results_path }} |
0 commit comments