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

相關文章
相關標籤/搜索