Skip to content

Commit 73a740d

Browse files
committed
feat: add PR preview deployment
1 parent 4beca85 commit 73a740d

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ jobs:
1313
contents: read
1414
pages: write
1515
id-token: write
16+
pull-requests: write
1617

1718
steps:
1819
- name: Checkout
@@ -50,3 +51,20 @@ jobs:
5051
- name: Deploy to GitHub Pages
5152
id: deployment
5253
uses: actions/deploy-pages@v4
54+
- name: Comment PR with preview URL
55+
if: github.event_name == 'pull_request'
56+
uses: actions/github-script@v7
57+
with:
58+
github-token: ${{ secrets.GITHUB_TOKEN }}
59+
script: |
60+
const pr = context.payload.pull_request.number;
61+
const url = process.env.PREVIEW_URL;
62+
await github.rest.issues.createComment({
63+
owner: context.repo.owner,
64+
repo: context.repo.repo,
65+
issue_number: pr,
66+
body: `Preview this PR: ${url}`
67+
});
68+
env:
69+
PREVIEW_URL: ${{ steps.deployment.outputs.page_url }}
70+

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
## 🚀 部署说明
7171

7272
本项目采用 GitHub Actions 自动化部署到 GitHub Pages,每次推送到主分支时自动构建和部署。
73+
在每个 Pull Request 上也会自动构建预览,并在 PR 评论中提供访问链接。
7374

7475
如需 fork 此项目进行自定义开发:
7576

0 commit comments

Comments
 (0)