git action 配置密钥定时任务node环境

46 min read
name: Deploy Blog

on: [push] # 当有新push时运行

env:
  TZ: Asia/Shanghai

jobs:
  build: # 一项叫做build的任务

    runs-on: ubuntu-latest # 在最新版的Ubuntu系统下运行
    
    steps:
    - name: Checkout # 将仓库内master分支的内容下载到工作目录
      uses: actions/checkout@v1 # 脚本来自 https://github.com/actions/checkout
      
    - name: Use Node.js 10.x # 配置Node环境
      uses: actions/setup-node@v1 # 配置脚本来自 https://github.com/actions/setup-node
      with:
        node-version: "10.x"
    
    - name: Setup Hexo env
      env:
        ACTION_DEPLOY_KEY: ${{ secrets.HEXO_DEPLOY_KEY }} # 这里是上面WinterChenS.github.io新增的公钥HEXO_DEPLOY_KEY
      run: |
        # set up private key for deploy
        mkdir -p ~/.ssh/
        echo "$ACTION_DEPLOY_KEY" | tr -d '\r' > ~/.ssh/id_rsa # 配置秘钥
        chmod 600 ~/.ssh/id_rsa
        ssh-keyscan github.com >> ~/.ssh/known_hosts
        # set git infomation
        git config --global user.name 'winterchens' # 换成你自己的邮箱和名字
        git config --global user.email '[email protected]'
        # install dependencies
        npm i -g hexo-cli # 安装hexo
        npm i
        # 拉取主题代码
        rm -rf themes/*
        git clone https://github.com/WinterChenS/hexo-theme-diaspora.git themes/diaspora
        
  
    - name: Deploy
      run: |
        # publish
        hexo generate && hexo deploy # 执行部署程序