Skip to content

Commit 26f4250

Browse files
committed
feat: trigger prerelease by PR label
1 parent 5ac052f commit 26f4250

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-5
lines changed

.github/workflows/prerelease.yml

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
name: Vercel Preview Deployment
1+
name: Pre-release
22

33
on:
4-
workflow_dispatch:
5-
push:
4+
workflow_dispatch:
5+
pull_request:
6+
types: [labeled]
67
branches-ignore:
78
- main
89

910
jobs:
1011
deploy-en:
12+
if: github.event.label.name == 'prerelease'
1113
uses: ./.github/workflows/vercel-deploy.yml
1214
with:
1315
environment: preview
@@ -18,6 +20,7 @@ jobs:
1820
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
1921

2022
deploy-zh-hans:
23+
if: github.event.label.name == 'prerelease'
2124
uses: ./.github/workflows/vercel-deploy.yml
2225
with:
2326
environment: preview
@@ -26,3 +29,31 @@ jobs:
2629
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ZH_HANS_ID }}
2730
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
2831
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
32+
33+
comment-vercel-preview:
34+
if: github.event.label.name == 'prerelease'
35+
needs: [deploy-en, deploy-zh-hans]
36+
runs-on: ubuntu-latest
37+
steps:
38+
- name: Comment PR with Vercel Preview Links
39+
uses: actions/github-script@v7
40+
with:
41+
script: |
42+
const en_inspect = process.env.EN_INSPECT_URL;
43+
const en_prod = process.env.EN_PROD_URL;
44+
const zh_inspect = process.env.ZH_INSPECT_URL;
45+
const zh_prod = process.env.ZH_PROD_URL;
46+
let body = `**Vercel Deploy Preview**\n\n`;
47+
body += `- 🇺🇸 EN: [Inspect](${en_inspect}) | [Preview](${en_prod})\n`;
48+
body += `- 🇨🇳 ZH-HANS: [Inspect](${zh_inspect}) | [Preview](${zh_prod})`;
49+
github.rest.issues.createComment({
50+
issue_number: context.issue.number,
51+
owner: context.repo.owner,
52+
repo: context.repo.repo,
53+
body
54+
});
55+
env:
56+
EN_INSPECT_URL: ${{ needs.deploy-en.outputs.inspect_url }}
57+
EN_PROD_URL: ${{ needs.deploy-en.outputs.prod_url }}
58+
ZH_INSPECT_URL: ${{ needs.deploy-zh-hans.outputs.inspect_url }}
59+
ZH_PROD_URL: ${{ needs.deploy-zh-hans.outputs.prod_url }}

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Vercel Production Deployment
1+
name: Release
22

33
on:
44
workflow_dispatch:

.github/workflows/vercel-deploy.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ on:
2323
jobs:
2424
deploy:
2525
runs-on: ubuntu-latest
26+
outputs:
27+
inspect_url: ${{ steps.vercel_deploy.outputs.inspect_url }}
28+
prod_url: ${{ steps.vercel_deploy.outputs.prod_url }}
2629
steps:
2730
- name: Checkout code
2831
uses: actions/checkout@v3
@@ -53,7 +56,14 @@ jobs:
5356
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
5457

5558
- name: Deploy Project Artifacts
56-
run: vercel deploy --prebuilt ${{ inputs.prodFlag }} --archive=tgz --token=${{ secrets.VERCEL_TOKEN }}
59+
id: vercel_deploy
60+
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
5767
env:
5868
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
5969
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}

0 commit comments

Comments
 (0)