05.VitePress部署到gitHub Pages
本篇介绍下如何将vitepress部署到gitHub pages,利用action实现自动部署
部署到同一个仓库
创建文件 .github\workflows\deploy.yml ,推送到github就OK了。
yaml
name: Deploy
on:
push:
branches:
- master
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: 检出代码
uses: actions/checkout@v2
- name: 安装node环境
uses: actions/setup-node@v3
with:
node-version: 20
# cache: yarn
- run: yarn install --frozen-lockfile
- name: Build代码
run: yarn docs:build
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
# 不需要设置 GITHUB_TOKEN,默认有
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: docs/.vitepress/dist
部署到不同的仓库
yaml
name: Deploy
on:
push:
branches:
- master
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: 检出代码
uses: actions/checkout@v2
- name: 安装node环境
uses: actions/setup-node@v3
with:
node-version: 20
# cache: yarn
- run: yarn install --frozen-lockfile
- name: Build代码
run: yarn docs:build
- name: publish分支
uses: s0/git-publish-subdir-action@master
env:
# 目标仓库
REPO: git@github.com:coder-lzh/vitepressDemo2.git
# 目标分支
BRANCH: gh-pages
FOLDER: docs/.vitepress/dist
# DEPLOY_PRIVATE_KEY 为 ssh的私钥,需要在 secrets 中设置这个变量
SSH_PRIVATE_KEY: ${{ secrets.DEPLOY_PRIVATE_KEY }}