thumbnail
Github Action+Hexo 在线写作

本地配置

1、关联源文件仓库

git remote add origin git@github.com:<你的用户名>/<存放源文件的仓库名>.git

2、仓库同步

git pull --rebase origin master

3、依次输入

git add .
git commit -m "init repo"
git push -u origin master

注意:如theme文件夹中主题文件中有.git文件,请将其删除在上传

仓库配置

在C:\Users\用户名.ssh可找到id_rsa文件

VScode打开

复制全部

  • 私钥的配置,点击 https://github.com/<你的用户名>/<存放源文件的仓库名>/settings/secrets,新建私钥,注意,这里的名称要填HEXO_DEPLOY_PRIVATE_KEY

回到仓库的Action

点击set up a workflow yourself→

用以下代码替换全部

# workflow name
name: Hexo Blog CI

# master branch on push, auto run
on: 
  push:
    branches:
      - master
      
jobs:
  build: 
    runs-on: ubuntu-latest 
        
    steps:
    # check it to your workflow can access it
    # from: https://github.com/actions/checkout
    - name: Checkout Repository master branch
      uses: actions/checkout@master 
      
    # from: https://github.com/actions/setup-node  
    - name: Setup Node.js 12.x 
      uses: actions/setup-node@master
      with:
        node-version: "12.x"
    
    - name: Setup Hexo Dependencies
      run: |
        npm install hexo-cli -g
        npm install        
    
    - name: Setup Deploy Private Key
      env:
        HEXO_DEPLOY_PRIVATE_KEY: ${{ secrets.HEXO_DEPLOY_PRIVATE_KEY }}
      run: |
        mkdir -p ~/.ssh/
        echo "$HEXO_DEPLOY_PRIVATE_KEY" > ~/.ssh/id_rsa 
        chmod 600 ~/.ssh/id_rsa
        ssh-keyscan github.com >> ~/.ssh/known_hosts
                
    - name: Setup Git Infomation
      run: | 
        git config --global user.name '<你的用户名>' 
        git config --global user.email '<你登录的email>'
    - name: Deploy Hexo 
      run: |
        hexo clean
        hexo generate 
        hexo deploy        

然后保存,运行

Have a Nice Day
上一篇
下一篇