Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Deploy Preview

on:
pull_request:

jobs:
preview:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- run: npm install
- run: npm run build
- name: Deploy to Netlify
id: netlify
uses: netlify/actions/cli@master
with:
args: deploy --dir=dist --json
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
- name: Comment preview URL
uses: actions/github-script@v7
with:
script: |
const url = process.env.NETLIFY_URL || '${{ steps.netlify.outputs.NETLIFY_URL }}';
if (url) {
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `🧪 Preview deployed: ${url}`
});
} else {
core.warning('No preview URL found.');
}
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@
3. 选择 GitHub Actions 作为部署源
4. 推送代码时将自动触发构建和部署

### PR 预览

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

## 📝 使用指南

### 🎯 快速上手
Expand Down
Loading