-
Notifications
You must be signed in to change notification settings - Fork 209
67 lines (57 loc) · 1.8 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
56
57
58
59
60
61
62
63
64
65
66
67
name: Preview PR Build
on:
pull_request_target:
types: [opened, synchronize, reopened, ready_for_review]
paths:
- 'content/**'
- 'config/**'
- 'static/**'
- 'themes/**'
- 'package.json'
jobs:
deploy:
runs-on: ubuntu-latest
outputs:
preview_url: ${{ steps.deploy.outputs.deployment-url }}
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: 配置 baseURL
# run: |
# sed -i 's|baseURL = "https://mtf.wiki/"|baseURL = "/"|' config/_default/config.toml
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'
- name: Install npm dependencies
run: npm install
- name: Set up Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: latest
extended: true
- name: Build site
run: hugo --minify --enableGitInfo --baseURL "/"
- name: Deploy to Cloudflare Pages
id: deploy
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_PAGES_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_PAGES_ACCOUNT }}
command: pages deploy public --project-name=mtfwiki-preview
# 获取预览链接并发送到PR
comment_on_pr:
needs: deploy
uses: project-trans/actions/.github/workflows/comment-pr-preview-link.yml@main
secrets: inherit
with:
previewUrl: ${{ needs.deploy.outputs.preview_url }}