Skip to content

Commit 2f447f6

Browse files
committed
feat: comment pr with all vercel preview links
1 parent 5f5afff commit 2f447f6

File tree

2 files changed

+53
-22
lines changed

2 files changed

+53
-22
lines changed
Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,49 @@
11
name: 'Comment Vercel Preview'
22
description: 'Comment Vercel deploy preview links on a PR.'
33
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.'
126
required: true
137
runs:
148
using: 'composite'
159
steps:
16-
- name: Comment PR with Vercel Preview Links
10+
- name: Comment PR with all Vercel Preview Links
1711
uses: actions/github-script@v7
1812
with:
1913
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+
for (const key in results) {
21+
const job = results[key];
22+
if (job.result === 'success' && job.outputs && job.outputs.label) {
23+
body += `- **${job.outputs.label}**: [Inspect](${job.outputs.inspect_url}) | [Preview](${job.outputs.preview_url})\n`;
24+
}
25+
}
26+
// Find existing comment
27+
const { data: comments } = await github.rest.issues.listComments({
2528
issue_number: context.issue.number,
2629
owner: context.repo.owner,
2730
repo: context.repo.repo,
28-
body
2931
});
32+
const existing = comments.find(c => c.body && c.body.includes(marker));
33+
if (existing) {
34+
await github.rest.issues.updateComment({
35+
comment_id: existing.id,
36+
owner: context.repo.owner,
37+
repo: context.repo.repo,
38+
body
39+
});
40+
} else {
41+
await github.rest.issues.createComment({
42+
issue_number: context.issue.number,
43+
owner: context.repo.owner,
44+
repo: context.repo.repo,
45+
body
46+
});
47+
}
3048
env:
31-
INSPECT_URL: ${{ inputs.inspect_url }}
32-
PREVIEW_URL: ${{ inputs.preview_url }}
33-
LABEL: ${{ inputs.label }}
49+
DEPLOY_RESULTS_PATH: ${{ inputs.deploy_results_path }}

.github/workflows/prerelease.yml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,25 @@ jobs:
6868
vercel_project_id: ${{ secrets[matrix.secret_project_id] }}
6969
vercel_org_id: ${{ secrets.VERCEL_ORG_ID }}
7070
vercel_token: ${{ secrets.VERCEL_TOKEN }}
71-
- name: Comment PR with Vercel Preview Links (${{ matrix.locale }})
71+
- name: Set deploy outputs
7272
if: steps.should_deploy.outputs.should_deploy == 'true'
73+
run: |
74+
echo "preview_url=${{ steps.deploy.outputs.prod_url }}" >> $GITHUB_OUTPUT
75+
echo "inspect_url=${{ steps.deploy.outputs.inspect_url }}" >> $GITHUB_OUTPUT
76+
echo "label=${{ matrix.locale }}" >> $GITHUB_OUTPUT
77+
78+
comment-vercel-previews:
79+
needs: deploy
80+
runs-on: ubuntu-latest
81+
if: always()
82+
steps:
83+
- name: Checkout repo
84+
uses: actions/checkout@v3
85+
- name: Aggregate deploy results
86+
id: aggregate
87+
run: |
88+
echo '${{ toJson(needs.deploy) }}' > deploy-results.json
89+
- name: Comment PR with all Vercel Preview Links
7390
uses: ./.github/actions/comment-vercel-preview
7491
with:
75-
inspect_url: ${{ steps.deploy.outputs.inspect_url }}
76-
preview_url: ${{ steps.deploy.outputs.prod_url }}
77-
label: ${{ matrix.locale }}
92+
deploy_results_path: deploy-results.json

0 commit comments

Comments
 (0)