Skip to content

Commit 82ad05d

Browse files
committed
feat: add Netlify preview for PRs
1 parent 4beca85 commit 82ad05d

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

.github/workflows/preview.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Deploy Preview
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
preview:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v4
11+
- uses: actions/setup-node@v4
12+
with:
13+
node-version: '20'
14+
cache: 'npm'
15+
- run: npm install
16+
- run: npm run build
17+
- name: Deploy to Netlify
18+
id: netlify
19+
uses: netlify/actions/cli@master
20+
with:
21+
args: deploy --dir=dist --json
22+
env:
23+
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
24+
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
25+
- name: Comment preview URL
26+
uses: actions/github-script@v7
27+
with:
28+
script: |
29+
const url = process.env.NETLIFY_URL || '${{ steps.netlify.outputs.NETLIFY_URL }}';
30+
if (url) {
31+
github.rest.issues.createComment({
32+
owner: context.repo.owner,
33+
repo: context.repo.repo,
34+
issue_number: context.issue.number,
35+
body: `🧪 Preview deployed: ${url}`
36+
});
37+
} else {
38+
core.warning('No preview URL found.');
39+
}

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@
7878
3. 选择 GitHub Actions 作为部署源
7979
4. 推送代码时将自动触发构建和部署
8080

81+
### PR 预览
82+
83+
在每个 Pull Request 上,GitHub Actions 会使用 **Netlify** 自动部署预览站点,并在 PR 中评论预览链接,方便开发者快速验证功能是否正常。要启用此功能,需要在仓库的 `Secrets` 中配置 `NETLIFY_AUTH_TOKEN``NETLIFY_SITE_ID`
84+
8185
## 📝 使用指南
8286

8387
### 🎯 快速上手

0 commit comments

Comments
 (0)