-
-
Notifications
You must be signed in to change notification settings - Fork 530
92 lines (81 loc) · 2.86 KB
/
docs-preview.yml
File metadata and controls
92 lines (81 loc) · 2.86 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
name: Deploy documentation preview
on:
workflow_run:
workflows: [Tests And Linting]
types: [completed]
jobs:
deploy:
if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request' }}
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
contents: write
steps:
- name: Check out repository
uses: actions/checkout@v6
with:
persist-credentials: false
- name: Download artifact
uses: dawidd6/action-download-artifact@v19
with:
workflow_conclusion: success
run_id: ${{ github.event.workflow_run.id }}
path: docs-preview
name: docs-preview
- name: Validate and set PR number
run: |
PR_NUMBER=$(cat docs-preview/.pr_number)
if ! [[ "$PR_NUMBER" =~ ^[0-9]+$ ]]; then
echo "Invalid PR number: $PR_NUMBER"
exit 1
fi
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
- name: Generate GitHub App Token
id: generate-token
uses: actions/create-github-app-token@v3
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
owner: litestar-org
repositories: litestar-docs-preview
- name: Deploy docs preview
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: docs-preview/docs/_build/html
token: ${{ steps.generate-token.outputs.token }}
repository-name: litestar-org/litestar-docs-preview
clean: false
target-folder: ${{ env.PR_NUMBER }}
branch: gh-pages
- uses: actions/github-script@v8
env:
PR_NUMBER: ${{ env.PR_NUMBER }}
with:
script: |
const issue_number = parseInt(process.env.PR_NUMBER, 10)
const previewUrl = "https://litestar-org.github.io/litestar-docs-preview/" + issue_number
const marker = "<!-- docs-preview -->"
const section = marker + "\n\n<hr>\n📚 Documentation preview 📚: " + previewUrl + "\n"
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: issue_number,
})
let body = pr.body || ""
if (body.includes(marker)) {
// Update existing section
body = body.replace(
new RegExp(marker + "[\\s\\S]*$"),
section,
)
} else {
// Append section
body = body + "\n\n" + section
}
await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: issue_number,
body: body,
})