首先建立一个能够生成文档的项目,这里以 vitepress 为例。

创建 Github Actions 用于部署 Github Pages:

  • checkout code
  • setup pnpm
  • install dependencies
  • build
  • publish to github pages
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
name: GitHub Pages

on:
push:
branches:
- main # Set a branch name to trigger deployment
pull_request:

jobs:
deploy:
runs-on: ubuntu-20.04
permissions:
contents: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
steps:
- uses: actions/checkout@v3

- name: Setup pnpm
uses: pnpm/action-setup@v2.2.2
with:
version: 6.0.2

- name: Install Dependences
run: pnpm install --frozen-lockfile

- name: Build
run: pnpm docs:build

- name: Deploy
uses: peaceiris/actions-gh-pages@v3
# If you're changing the branch from main,
# also change the `main` in `refs/heads/main`
# below accordingly.
if: ${{ github.ref == 'refs/heads/main' }}
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/.vitepress/dist