-
Notifications
You must be signed in to change notification settings - Fork 0
83 lines (72 loc) · 2.57 KB
/
preview.yml
File metadata and controls
83 lines (72 loc) · 2.57 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
name: PR preview
on:
pull_request:
types: [opened, synchronize, reopened]
permissions:
contents: read
pull-requests: write
jobs:
preview:
name: Build & deploy preview
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- name: Install dependencies
run: npm ci
- name: Build docs
run: npm run docs:build -- --base /pr-${{ github.event.pull_request.number }}/
- name: Deploy to FTP
uses: SamKirkland/FTP-Deploy-Action@v4.3.5
with:
server: ftpupload.net
port: 21
username: ${{ secrets.FTP_USERNAME }}
password: ${{ secrets.FTP_PASSWORD }}
local-dir: .vitepress/dist/
server-dir: htdocs/pr-${{ github.event.pull_request.number }}/
- name: Comment on PR
uses: actions/github-script@v7
with:
script: |
const prNumber = context.payload.pull_request.number;
const previewUrl = `http://xmoj-docs.infinityfreeapp.com/pr-${prNumber}/`;
const runUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
const body = [
'## 📖 文档预览',
'',
`构建成功!点击下方链接在线预览文档(PR 关闭后自动删除)。`,
'',
`**[🔗 在线预览](${previewUrl})**`,
'',
`> 预览地址:\`${previewUrl}\``,
`> 构建运行:[#${context.runNumber}](${runUrl})`,
].join('\n');
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(
c => c.user.type === 'Bot' && c.body.includes('## 📖 文档预览')
);
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}