diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml new file mode 100644 index 0000000..2205a97 --- /dev/null +++ b/.github/workflows/preview.yml @@ -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.'); + } diff --git a/README.md b/README.md index 6b6f453..0ad49ee 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,10 @@ 3. 选择 GitHub Actions 作为部署源 4. 推送代码时将自动触发构建和部署 +### PR 预览 + +在每个 Pull Request 上,GitHub Actions 会使用 **Netlify** 自动部署预览站点,并在 PR 中评论预览链接,方便开发者快速验证功能是否正常。要启用此功能,需要在仓库的 `Secrets` 中配置 `NETLIFY_AUTH_TOKEN` 和 `NETLIFY_SITE_ID`。 + ## 📝 使用指南 ### 🎯 快速上手