尝试使用GitHub-Actions自动部署Hexo

尝试使用GitHub Actions自动部署Hexo

参考链接

  • 生成ssh部署公私钥
ssh-keygen
  • 为Page仓库添加公钥:
    • Github:在仓库/Settings/Deploy keys中添加,授予写权限
    • Coding:在仓库/设置/部署公钥中添加,授予写权限
  • 为源码仓库添加私钥:
    • Github:在仓库/Settings/Secrets中添加,注意记录名称。这个功能可以放一些隐私内容,包括私钥、token、密码等等。
  • 编写workflow,文件位置.github/workflows/deploy.yml
name: Node CI

on: [push]

jobs:
  build:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [10.x]

    steps:
    - uses: actions/checkout@v1
    - name: Use Node.js 10.x
      uses: actions/setup-node@v1
      with:
        node-version: '10.x'
    - name: env prepare
      env:
        ACTIONS_PRI: ${{secrets.ACTIONS_PRI}}
      run: |
        mkdir -p ~/.ssh/
        echo "$ACTIONS_PRI" > ~/.ssh/id_rsa
        chmod 600 ~/.ssh/id_rsa
        ssh-keyscan github.com >> ~/.ssh/known_hosts
        ssh-keyscan git.coding.net >> ~/.ssh/known_hosts
        git config --global user.name 'SinLapis'
        git config --global user.email 'stradust0001@gmail.com'
        npm i -g hexo-cli
        npm install hexo-renderer-jade hexo-renderer-stylus --save
        npm i
    - name: gen
      run: |
        hexo g -d

多部署注意把域名加入~/.ssh/known_hosts,否则会部署失败。

Author: SinLapis
Link: http://sinlapis.github.io/2019/08/28/尝试使用GitHub-Actions自动部署Hexo/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.