Skip to content

Commit 7cc1e98

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

File tree

963 files changed

+1453
-132205
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

963 files changed

+1453
-132205
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 }}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: "Vercel Deploy"
2+
description: "Deploy to Vercel and output preview/inspect URLs"
3+
inputs:
4+
environment:
5+
description: "Vercel environment (production or preview)"
6+
required: true
7+
prodFlag:
8+
description: "Set to --prod for production deploys, empty for preview"
9+
required: false
10+
default: ""
11+
vercel_project_id:
12+
required: true
13+
vercel_org_id:
14+
required: true
15+
vercel_token:
16+
required: true
17+
outputs:
18+
inspect_url:
19+
description: "Vercel inspect URL"
20+
value: ${{ steps.vercel_deploy.outputs.inspect_url }}
21+
prod_url:
22+
description: "Vercel preview/production URL"
23+
value: ${{ steps.vercel_deploy.outputs.prod_url }}
24+
runs:
25+
using: "composite"
26+
steps:
27+
- name: Pull Vercel Environment Information
28+
run: npx vercel pull --yes --environment=${{ inputs.environment }} --token=${{ inputs.vercel_token }}
29+
env:
30+
VERCEL_PROJECT_ID: ${{ inputs.vercel_project_id }}
31+
VERCEL_ORG_ID: ${{ inputs.vercel_org_id }}
32+
shell: bash
33+
- name: Build Project Artifacts
34+
run: npx vercel build ${{ inputs.prodFlag }} --token=${{ inputs.vercel_token }}
35+
env:
36+
VERCEL_PROJECT_ID: ${{ inputs.vercel_project_id }}
37+
VERCEL_ORG_ID: ${{ inputs.vercel_org_id }}
38+
shell: bash
39+
- name: Deploy Project Artifacts
40+
id: vercel_deploy
41+
run: |
42+
npx vercel deploy --prebuilt ${{ inputs.prodFlag }} --archive=tgz --token=${{ inputs.vercel_token }} 2>&1 | tee vercel_output.txt
43+
inspect_url=$(awk '/^Inspect:/ {print $2}' vercel_output.txt | head -n1)
44+
preview_url=$(awk '/^(Preview|Production):/ {print $2}' vercel_output.txt | head -n1)
45+
echo "inspect_url=$inspect_url" >> $GITHUB_OUTPUT
46+
echo "prod_url=$preview_url" >> $GITHUB_OUTPUT
47+
env:
48+
VERCEL_PROJECT_ID: ${{ inputs.vercel_project_id }}
49+
VERCEL_ORG_ID: ${{ inputs.vercel_org_id }}
50+
shell: bash

.github/workflows/prerelease.yml

Lines changed: 32 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,53 +8,40 @@ on:
88
- labeled
99
- synchronize
1010

11-
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 }}
22-
23-
deploy-zh-hans:
24-
if: contains(github.event.pull_request.labels.*.name, 'prerelease')
25-
uses: ./.github/workflows/vercel-deploy.yml
26-
with:
27-
environment: preview
28-
prodFlag: ''
29-
secrets:
30-
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ZH_HANS_ID }}
31-
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
32-
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
11+
permissions:
12+
pull-requests: write
13+
issues: write
3314

34-
comment-vercel-preview:
15+
jobs:
16+
deploy-and-comment:
3517
if: contains(github.event.pull_request.labels.*.name, 'prerelease')
36-
needs: [deploy-en, deploy-zh-hans]
3718
runs-on: ubuntu-latest
19+
strategy:
20+
matrix:
21+
include:
22+
- locale: EN
23+
secret_project_id: VERCEL_PROJECT_EN_ID
24+
- locale: ZH-HANS
25+
secret_project_id: VERCEL_PROJECT_ZH_HANS_ID
3826
steps:
39-
- name: Comment PR with Vercel Preview Links
40-
uses: actions/github-script@v7
27+
- name: Checkout code
28+
uses: actions/checkout@v3
29+
with:
30+
fetch-depth: 1
31+
- name: Setup Tools
32+
uses: ./.github/actions/setup
33+
- name: Deploy to Vercel (${{ matrix.locale }})
34+
id: deploy
35+
uses: ./.github/actions/vercel-deploy
36+
with:
37+
environment: preview
38+
prodFlag: ""
39+
vercel_project_id: ${{ secrets[matrix.secret_project_id] }}
40+
vercel_org_id: ${{ secrets.VERCEL_ORG_ID }}
41+
vercel_token: ${{ secrets.VERCEL_TOKEN }}
42+
- name: Comment PR with Vercel Preview Links (${{ matrix.locale }})
43+
uses: ./.github/actions/comment-vercel-preview
4144
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 }}
45+
inspect_url: ${{ steps.deploy.outputs.inspect_url }}
46+
preview_url: ${{ steps.deploy.outputs.prod_url }}
47+
label: ${{ matrix.locale }}

.github/workflows/vercel-deploy.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,11 @@ 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)
65-
echo "inspect_url=$inspect_url" >> $GITHUB_OUTPUT
66-
echo "prod_url=$preview_url" >> $GITHUB_OUTPUT
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)
64+
echo "inspect_url=$inspect_url" >> "$GITHUB_OUTPUT"
65+
echo "prod_url=$preview_url" >> "$GITHUB_OUTPUT"
6766
env:
6867
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
6968
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}

0 commit comments

Comments
 (0)