-
Notifications
You must be signed in to change notification settings - Fork 323
108 lines (91 loc) · 2.78 KB
/
Copy pathdocs-preview.yml
File metadata and controls
108 lines (91 loc) · 2.78 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
name: Docs Preview
on:
pull_request:
types: [opened, synchronize, reopened]
permissions:
contents: read
concurrency:
group: docs-pages
cancel-in-progress: false
jobs:
build-preview:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5
with:
fetch-depth: 0
persist-credentials: false
- name: Setup Node
uses: actions/setup-node@v6
with:
node-version: 24
cache: yarn
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Build preview
run: >-
VITEPRESS_BASE=/pr-preview/pr-${{ github.event.pull_request.number }}/ yarn docs:build
- name: Upload preview artifact
uses: actions/upload-artifact@v4
with:
name: docs-preview
path: docs/.vitepress/dist
publish-preview:
if: github.event.pull_request.head.repo.full_name == github.repository
needs: build-preview
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout trusted deploy scripts
uses: actions/checkout@v5
- name: Download preview artifact
uses: actions/download-artifact@v4
with:
name: docs-preview
path: docs/.vitepress/dist
- name: Publish preview
run: >-
bash .github/scripts/docs-pages.sh deploy-preview docs/.vitepress/dist ${{ github.event.pull_request.number }}
- name: Comment preview URL
uses: actions/github-script@v7
env:
PREVIEW_URL: >-
https://ui.frappe.io/pr-preview/pr-${{ github.event.pull_request.number }}/
with:
script: |
const marker = '<!-- docs-preview -->'
const body = [
marker,
'🚀 VitePress preview is ready:',
'',
process.env.PREVIEW_URL,
].join('\n')
const { owner, repo } = context.repo
const issue_number = context.issue.number
const comments = await github.paginate(github.rest.issues.listComments, {
owner,
repo,
issue_number,
per_page: 100,
})
const existing = comments.find((comment) =>
comment.user?.type === 'Bot' && comment.body?.includes(marker),
)
if (existing) {
await github.rest.issues.updateComment({
owner,
repo,
comment_id: existing.id,
body,
})
} else {
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body,
})
}