使用github action部署hexo

好耶,不用自己配置环境了

  1. 执行下面命令,生成密钥对,疯狂回车,不要密码

    1
    ssh-keygen -f hexo-deploy-key -t rsa
  2. 这里我是博客源码在 A 项目,静态文件在 ankikong.github.io 项目

    1. 进入 A 项目,把生成的 hexo-deploy-key 内容复制到 settings -> Secrets -> Action -> New repository secret。Name填 HEXO_DEPLOY_PRI,Value 填 私钥内容

    2. 进入 ankikong.github.io 项目,把生成的 hexo-deploy-key 内容复制到 settings -> Deploy keys -> Add deploy key。Name填随便填,Value 填 hexo-deploy-key.pub 的内容

    3. 进入 A 项目,点击 Action -> New Workflows,把下面的东西写进去,记得修改 user.nameuser.email

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      name: HEXO CI

      on:
      push:
      branches:
      - master

      jobs:
      build:
      runs-on: ubuntu-latest
      strategy:
      matrix:
      node-version: [12.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: Configuration environment
      env:
      HEXO_DEPLOY_PRI: ${{secrets.HEXO_DEPLOY_PRI}}
      run: |
      mkdir -p ~/.ssh/
      echo "$HEXO_DEPLOY_PRI" > ~/.ssh/id_rsa
      chmod 600 ~/.ssh/id_rsa
      ssh-keyscan github.com >> ~/.ssh/known_hosts
      git config --global user.name "git"
      git config --global user.email "git@git.com"
      - name: Install dependencies
      run: |
      npm i -g hexo-cli
      npm i
      - name: Deploy hexo
      run: |
      hexo clean && hexo generate && hexo deploy

公司的流水线用的语法就是GitHub Action的语法,有空整一篇文章说说。