1+ name : Preview Deployment
2+
3+ env :
4+ VERCEL_ORG_ID : ${{ secrets.VERCEL_ORG_ID }}
5+ VERCEL_PROJECT_ID : ${{ secrets.VERCEL_PROJECT_ID }}
6+
7+ on :
8+ pull_request :
9+ types : [opened, synchronize, reopened]
10+
11+ # Add permissions section to allow commenting on issues/PRs
12+ permissions :
13+ pull-requests : write
14+ contents : read
15+
16+ jobs :
17+ Deploy-Preview :
18+ runs-on : ubuntu-latest
19+ steps :
20+ - uses : actions/checkout@v3
21+
22+ - name : Setup Node.js
23+ uses : actions/setup-node@v3
24+ with :
25+ node-version : ' 18'
26+
27+ - name : Setup PNPM
28+ uses : pnpm/action-setup@v2
29+ with :
30+ version : ' 9.15.0'
31+
32+ - name : Set up .npmrc
33+ run : echo "registry=https://registry.npmjs.org" > .npmrc
34+
35+ - name : Install dependencies
36+ run : pnpm install --no-frozen-lockfile --ignore-scripts
37+
38+ - name : Install Vercel CLI
39+ run : pnpm add --global vercel@latest
40+
41+ - name : Pull Vercel Environment Information
42+ run : vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}
43+
44+ - name : Build Project Artifacts
45+ run : vercel build --token=${{ secrets.VERCEL_TOKEN }}
46+
47+ - name : Deploy Project Artifacts to Vercel
48+ id : deploy
49+ run : echo "url=$(vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }})" >> $GITHUB_OUTPUT
50+
51+ - name : Add Preview Comment
52+ uses : actions/github-script@v6
53+ with :
54+ github-token : ${{ secrets.GITHUB_TOKEN }}
55+ script : |
56+ const url = process.env.DEPLOY_URL;
57+ github.rest.issues.createComment({
58+ issue_number: context.issue.number,
59+ owner: context.repo.owner,
60+ repo: context.repo.repo,
61+ body: `✅ Preview deployment is ready!
62+
63+ 🔗 Preview URL: ${url}`
64+ })
65+ env :
66+ DEPLOY_URL : ${{ steps.deploy.outputs.url }}
0 commit comments