vuepress 文档部署到 github-pages

必须作的

在 docs/.vuepress/config.js 中设置正确的 base。vue

若是你打算发布到 https://<USERNAME>.github.io/,则能够省略这一步,由于 base 默认便是 "/"。node

若是你打算发布到 https://<USERNAME>.github.io/<REPO>/(也就是说你的仓库在 https://github.com/<USERNAME>/<REPO>),则将 base 设置为 /<REPO>/git

发布方案

sh 脚本

#!/usr/bin/env sh 
# 确保脚本抛出遇到的错误
set -e

# 生成静态文件
npm run docs:build

# 进入生成的文件夹
cd docs/.vuepress/dist

# 若是是发布到自定义域名
# echo 'www.example.com' > CNAME

git init
git add -A
git commit -m 'deploy'

# 若是发布到 https://<USERNAME>.github.io
# git push -f git@github.com:<USERNAME>/<USERNAME>.github.io.git master

# 若是发布到 https://<USERNAME>.github.io/<REPO>
# git push -f git@github.com:<USERNAME>/<REPO>.git master:gh-pages

cd -
复制代码

Travis CI

language: node_js
node_js:
 - lts/*
install:
 - yarn install # npm ci
script:
 - yarn docs:build # npm run docs:build
deploy:
 provider: pages
 skip_cleanup: true
 local_dir: docs/.vuepress/dist
 github_token: $GITHUB_TOKEN # 在 GitHub 中生成,用于容许 Travis 向你的仓库推送代码。在 Travis 的项目设置页面进行配置,设置为 secure variable
 keep_history: true
 on:
 branch: master
复制代码

Github Actions

.github/workflow/下新建 deploy.ymlgithub

name: Publish docs to github actions
on:
 push:
 branches:
 - master
 pull_request:
 branches:
 - master
jobs:
 build-and-deploy:
 runs-on: ubuntu-latest
 steps:
 - name: Checkout
 uses: actions/checkout@v2 # If you're using actions/checkout@v2 you must set persist-credentials to false in most cases for the deployment to work correctly.
 with:
 persist-credentials: false
 - name: Install
 run: npm ci && npm run-script docs:build
 - name: Install SSH Client
 uses: webfactory/ssh-agent@v0.2.0 # This step installs the ssh client into the workflow run. There's many options available for this on the action marketplace.
 with:
 ssh-private-key: ${{ secrets.DEPLOY_KEY }}

 - name: Build and Deploy Repo
 uses: JamesIves/github-pages-deploy-action@releases/v3-test
 with:
 BASE_BRANCH: master
 BRANCH: gh-pages
 FOLDER: docs/.vuepress/dist
 SSH: true # SSH must be set to true so the deploy action knows which protocol to deploy with.
复制代码

接下来生成 key ,首先web

ssh-keygen -t rsa -b 4096 -C "$(git config user.email)" -f gh-pages -N ""
# You will get 2 files:
# gh-pages.pub (public key)
# gh-pages (private key)
复制代码

而后打开仓库的settings,再点击Secrets,而后添加我们刚刚生成的私钥(gh-pages的内容),name 为 DEPLOY_KEYnpm

而后点击Deploy keys,添加公钥(gh-pages.pub的内容),Allow write access必定要勾上ubuntu

而后提交便可,接着就会自动发布了ssh

相关文章
相关标签/搜索