# 文档库workflow搭建过程

# 添加 ACCESS_TOKEN

image-20220114104325713

# 创建workflows

创建 .github/workflows/doc.yml

name: deploy gh-pages
on:
  push:
    branches:
      - main
jobs:
  build:
    name: Build and deploy gh-pages
    env:
      MY_SECRET: ${{secrets.ACCESS_TOKEN}}
      USER_NAME: winljm001
      USER_EMAIL: 819648983@qq.com
      PUBLISH_DIR: ./docs-dist
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [14.x]
    steps:
      - uses: actions/checkout@v1
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node-version }}
      - name: install
        run: |
          yarn
      - name: run build
        run: |
          yarn doc:build
      - name: Commit files
        run: |
          cd $PUBLISH_DIR
          git init
          git config --local user.name $USER_NAME
          git config --local user.email $USER_EMAIL
          git status
          git remote add origin https://$MY_SECRET@github.com/hjfruit/远端地址-doc.git
          git checkout -b main
          git add --all
          git commit -m "deploy to Github pages"
          git push origin main -f
          echo 🤘 deploy doc-pages complete.

# 创建文档仓库

way1> 新建一个仓库

way2> 也可以就在当前仓库,以另一个分支作为文档也可以

开启github page

image-20220114105300014

开启过后,如果你当前仓库是github.io,那么你访问地址为组织或个人name.github.io,如果你新建的仓库叫xxx,那么你访问组织或个人name.github.io/xxx此时需要在设置下静态资源的baseurl,否则资源加载失败

完成~

lastUpdate: 1/14/2022, 3:03:20 AM