Skip to content

Commit 21d6ea0

Browse files
committed
feat: trigger prerelease by PR label
1 parent 5ac052f commit 21d6ea0

File tree

3 files changed

+49
-7
lines changed

3 files changed

+49
-7
lines changed

.github/workflows/prerelease.yml

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

33
on:
4-
workflow_dispatch:
5-
push:
6-
branches-ignore:
7-
- main
4+
workflow_dispatch:
5+
pull_request:
6+
types:
7+
- opened
8+
- labeled
9+
- synchronize
810

911
jobs:
1012
deploy-en:
13+
if: contains(github.event.pull_request.labels.*.name, 'prerelease')
1114
uses: ./.github/workflows/vercel-deploy.yml
1215
with:
1316
environment: preview
@@ -18,6 +21,7 @@ jobs:
1821
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
1922

2023
deploy-zh-hans:
24+
if: contains(github.event.pull_request.labels.*.name, 'prerelease')
2125
uses: ./.github/workflows/vercel-deploy.yml
2226
with:
2327
environment: preview
@@ -26,3 +30,31 @@ jobs:
2630
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ZH_HANS_ID }}
2731
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
2832
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
33+
34+
comment-vercel-preview:
35+
if: contains(github.event.pull_request.labels.*.name, 'prerelease')
36+
needs: [deploy-en, deploy-zh-hans]
37+
runs-on: ubuntu-latest
38+
steps:
39+
- name: Comment PR with Vercel Preview Links
40+
uses: actions/github-script@v7
41+
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 }}

.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)