Skip to content

Commit f707935

Browse files
committed
feat: add pr comment with preview url
1 parent 393bd40 commit f707935

File tree

3 files changed

+74
-37
lines changed

3 files changed

+74
-37
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: 'Comment Vercel Preview'
2+
description: 'Comment Vercel deploy preview links on a PR.'
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).'
12+
required: true
13+
runs:
14+
using: 'composite'
15+
steps:
16+
- name: Comment PR with Vercel Preview Links
17+
uses: actions/github-script@v7
18+
with:
19+
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({
25+
issue_number: context.issue.number,
26+
owner: context.repo.owner,
27+
repo: context.repo.repo,
28+
body
29+
});
30+
env:
31+
INSPECT_URL: ${{ inputs.inspect_url }}
32+
PREVIEW_URL: ${{ inputs.preview_url }}
33+
LABEL: ${{ inputs.label }}

.github/workflows/prerelease.yml

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,35 @@ on:
88
- labeled
99
- synchronize
1010

11+
permissions:
12+
pull-requests: write
13+
issues: write
14+
1115
jobs:
12-
deploy-en:
13-
if: contains(github.event.pull_request.labels.*.name, 'prerelease')
14-
uses: ./.github/workflows/vercel-deploy.yml
15-
with:
16-
environment: preview
17-
prodFlag: ''
18-
secrets:
19-
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_EN_ID }}
20-
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
21-
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
16+
# deploy-en:
17+
# if: contains(github.event.pull_request.labels.*.name, 'prerelease')
18+
# uses: ./.github/workflows/vercel-deploy.yml
19+
# with:
20+
# environment: preview
21+
# prodFlag: ''
22+
# secrets:
23+
# VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_EN_ID }}
24+
# VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
25+
# VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
26+
27+
# comment-vercel-preview-en:
28+
# if: contains(github.event.pull_request.labels.*.name, 'prerelease')
29+
# needs: deploy-en
30+
# runs-on: ubuntu-latest
31+
# steps:
32+
# - name: Checkout repo for local action
33+
# uses: actions/checkout@v4
34+
# - name: Comment PR with Vercel Preview Links (EN)
35+
# uses: ./.github/actions/comment-vercel-preview
36+
# with:
37+
# inspect_url: ${{ needs.deploy-en.outputs.inspect_url }}
38+
# preview_url: ${{ needs.deploy-en.outputs.prod_url }}
39+
# label: EN
2240

2341
deploy-zh-hans:
2442
if: contains(github.event.pull_request.labels.*.name, 'prerelease')
@@ -31,30 +49,17 @@ jobs:
3149
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
3250
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
3351

34-
comment-vercel-preview:
52+
comment-vercel-preview-zh-hans:
3553
if: contains(github.event.pull_request.labels.*.name, 'prerelease')
36-
needs: [deploy-en, deploy-zh-hans]
54+
needs: deploy-zh-hans
3755
runs-on: ubuntu-latest
3856
steps:
39-
- name: Comment PR with Vercel Preview Links
40-
uses: actions/github-script@v7
57+
- name: Checkout repo for local action
58+
uses: actions/checkout@v4
59+
- run: echo '${{ toJSON(needs.deploy-zh-hans.outputs) }}'
60+
- name: Comment PR with Vercel Preview Links (ZH-HANS)
61+
uses: ./.github/actions/comment-vercel-preview
4162
with:
42-
script: |
43-
const en_inspect = process.env.EN_INSPECT_URL;
44-
const en_prod = process.env.EN_PROD_URL;
45-
const zh_inspect = process.env.ZH_INSPECT_URL;
46-
const zh_prod = process.env.ZH_PROD_URL;
47-
let body = `**Vercel Deploy Preview**\n\n`;
48-
body += `- 🇺🇸 EN: [Inspect](${en_inspect}) | [Preview](${en_prod})\n`;
49-
body += `- 🇨🇳 ZH-HANS: [Inspect](${zh_inspect}) | [Preview](${zh_prod})`;
50-
github.rest.issues.createComment({
51-
issue_number: context.issue.number,
52-
owner: context.repo.owner,
53-
repo: context.repo.repo,
54-
body
55-
});
56-
env:
57-
EN_INSPECT_URL: ${{ needs.deploy-en.outputs.inspect_url }}
58-
EN_PROD_URL: ${{ needs.deploy-en.outputs.prod_url }}
59-
ZH_INSPECT_URL: ${{ needs.deploy-zh-hans.outputs.inspect_url }}
60-
ZH_PROD_URL: ${{ needs.deploy-zh-hans.outputs.prod_url }}
63+
inspect_url: ${{ needs.deploy-zh-hans.outputs.inspect_url }}
64+
preview_url: ${{ needs.deploy-zh-hans.outputs.prod_url }}
65+
label: ZH-HANS

.github/workflows/vercel-deploy.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,9 @@ jobs:
5858
- name: Deploy Project Artifacts
5959
id: vercel_deploy
6060
run: |
61-
vercel deploy --prebuilt ${{ inputs.prodFlag }} --archive=tgz --token=${{ secrets.VERCEL_TOKEN }} > vercel_output.txt 2>&1
62-
inspect_url=$(grep -o 'Inspect: https://[^ ]*' vercel_output.txt | head -n1 | cut -d' ' -f2)
63-
# Preview/Production URL: match both 'Preview:' and 'Production:'
64-
preview_url=$(grep -oE '(Preview|Production): https://[^ ]*' vercel_output.txt | head -n1 | cut -d' ' -f2)
61+
vercel deploy --prebuilt ${{ inputs.prodFlag }} --archive=tgz --token=${{ secrets.VERCEL_TOKEN }} 2>&1 | tee vercel_output.txt
62+
inspect_url=$(awk '/^Inspect:/ {print $2}' vercel_output.txt | head -n1)
63+
preview_url=$(awk '/^(Preview|Production):/ {print $2}' vercel_output.txt | head -n1)
6564
echo "inspect_url=$inspect_url" >> $GITHUB_OUTPUT
6665
echo "prod_url=$preview_url" >> $GITHUB_OUTPUT
6766
env:

0 commit comments

Comments
 (0)