Skip to content
On this page

VitePress Github Deploy

yml
name: Deploy VitePress Docs
on:
    workflow_dispatch: {}

    # master 发生 push 时触发部署
    push:
        branches:
            - vitepress

jobs:
    build-and-deploy:
        name: Deploy VitePress Docs

        # 指定运行机器
        runs-on: ubuntu-latest

        # 执行步骤
        steps:
            # 检出仓库
            - name: git checkout & git pull
              uses: actions/checkout@v3 #https://github.com/actions/checkout
              with:
                  fetch-depth: 0

            # 安装 Node.js
            - name: Install Node.js
              uses: actions/setup-node@v3 #https://github.com/actions/setup-node
              with:
                  node-version: '16.19.0'
                  cache: npm
                  cache-dependency-path: ./vitepress

            # 安装依赖
            - name: Install dependencies
              run: cd ./vitepress && npm ci

            # 构建文档
            - name: Build
              run: cd ./vitepress && npm run docs:build

            # 部署到 GitHub Pages
            - name: Deploy to GitHub Pages
              uses: peaceiris/actions-gh-pages@v3 # https://github.com/peaceiris/actions-gh-pages
              with:
                  personal_token: ${{ secrets.GITHUB_TOKEN }}
                  publish_branch: gh-pages
                  publish_dir: ./vitepress/docs/.vitepress/dist
                  destination_dir: ./vitepress
                  keep_files: true

Deploy to GitHub Pages 时出现 Permission to XXX.git denied to github-actions[bot]. 的错误

deploy-error

解决方法

在 github 当前项目的仓库中,进入 Settings > Actions > General 目录下

  1. Workflow permissions 下的 default permissions granted 设置为 Read and write permissions
  2. 勾选 Allow GitHub Actions to create and approve pull requestsSettings > Actions > General

Released under the MIT License.