Skip to content

Commit 8f003cd

Browse files
authored
feat: support docs preview (#2278)
Signed-off-by: bitliu <[email protected]>
1 parent 7139dc0 commit 8f003cd

File tree

1 file changed

+43
-6
lines changed

1 file changed

+43
-6
lines changed

.github/workflows/docs.yaml

+43-6
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,17 @@ on:
66
- "release/v*"
77
paths-ignore:
88
- "**/*.png"
9-
pull_request:
10-
branches:
11-
- "main"
12-
- "release/v*"
13-
paths-ignore:
14-
- "**/*.png"
9+
pull_request_target:
10+
types: [opened, synchronize, reopened]
1511

1612
jobs:
1713
docs-lint:
1814
runs-on: ubuntu-22.04
1915
steps:
2016
- name: Check out code
2117
uses: actions/checkout@v4
18+
with:
19+
ref: ${{ github.event.pull_request.head.sha }}
2220

2321
- name: Run markdown linter
2422
uses: nosborn/[email protected]
@@ -36,6 +34,7 @@ jobs:
3634
uses: actions/checkout@v4
3735
with:
3836
submodules: true
37+
ref: ${{ github.event.pull_request.head.sha }}
3938

4039
- name: Setup Hugo
4140
uses: peaceiris/actions-hugo@v2
@@ -60,6 +59,44 @@ jobs:
6059
# Duration after which artifact will expire in days.
6160
# retention-days: # optional, default is 1
6261

62+
docs-preview:
63+
if: "github.event_name == 'pull_request_target'"
64+
needs: docs-build
65+
runs-on: ubuntu-22.04
66+
steps:
67+
- name: Git checkout
68+
uses: actions/checkout@v4
69+
with:
70+
ref: ${{ github.event.pull_request.head.sha }}
71+
- name: Setup Hugo
72+
uses: peaceiris/actions-hugo@v2
73+
with:
74+
hugo-version: 'latest'
75+
extended: true
76+
- name: Setup Node
77+
uses: actions/setup-node@v4
78+
with:
79+
node-version: '18'
80+
- name: Install Site Dependencies and Build Site
81+
run: make docs
82+
- name: Deploy to Netlify
83+
uses: nwtgck/[email protected]
84+
with:
85+
publish-dir: 'site/public'
86+
production-deploy: false
87+
github-token: ${{ secrets.GITHUB_TOKEN }}
88+
deploy-message: "Deploy from GitHub Actions"
89+
alias: "${{ github.event.repository.name }}-pr-${{ github.event.pull_request.number }}-preview"
90+
# these all default to 'true'
91+
enable-pull-request-comment: true
92+
enable-commit-comment: false
93+
enable-commit-status: true
94+
overwrites-pull-request-comment: true
95+
env:
96+
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
97+
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
98+
timeout-minutes: 1
99+
63100
# This workflow contains a single job called "build"
64101
docs-publish:
65102
if: github.event_name == 'push'

0 commit comments

Comments
 (0)