-
Notifications
You must be signed in to change notification settings - Fork 209
55 lines (48 loc) · 1.59 KB
/
preview-pr-build.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
name: Preview PR Build
on:
pull_request_target:
types: [opened, synchronize, reopened, ready_for_review]
paths:
- 'content/**'
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: 检出主仓库代码
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.ref }}
fetch-depth: 0
submodules: true
- name: 检出 PR 修改的部分
run: |
git fetch origin +refs/pull/${{ github.event.pull_request.number }}/merge
git checkout -qf FETCH_HEAD
- name: Set up Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: latest
extended: true
- name: Build site
run: hugo --minify --enableGitInfo
- name: Deploy to Cloudflare Pages
uses: cloudflare/pages-action@v1
id: deploy
with:
apiToken: ${{ secrets.CLOUDFLARE_PAGES_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_PAGES_ACCOUNT }}
projectName: mtfwiki-preview
directory: public
- name: 评论 PR 部署链接
uses: actions/github-script@v6
with:
script: |
const prNumber = context.payload.pull_request.number;
const previewUrl = `${{ steps.deploy.outputs.url }}`;
const comment = `🚀 预览部署完成! 访问链接: ${previewUrl}/zh-cn/`;
github.rest.issues.createComment({
issue_number: prNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment,
});