使用命令行生成 SSH Key

ssh-keygen -t rsa -b 4096 -C “emal@gmail.com

添加 私钥Key 到 GitHub
博客私有仓库 –> Secrets –> Actions –> New repository secert

Name: HEXO_DEPLOY_KEY
Value: id_rsa 的值

添加 公钥Key 到 github.io 公开仓库
github.io仓库 –> Settings –> Deploy keys –> Add deploy key

Name: HEXO_DEPLOY_PUB
Value: id_rsa.pub 的值

在私有仓库新建GitHub Actions输入workflow

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
40
name: Hexo Deploy

on:
push:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
name: auto deploy

steps:
- name: Setup Node.js 12.x
uses: actions/setup-node@master
with:
node-version: "12.x"

- name: Checkout Repository source branch
uses: actions/checkout@v2
with:
ref: master

- name: Generate Public Files
run: |
npm i
npm install hexo-cli -g
hexo clean && hexo generate

- name: Deploy Hexo
uses: peaceiris/actions-gh-pages@v3
with:
deploy_key: ${{ secrets.HEXO_DEPLOY_KEY }}
external_repository: ivitan/ivitan.github.io
publish_branch: master
publish_dir: ./public
commit_message: ${{ github.event.head_commit.message }}
user_name: 'Vitan'
user_email: '[email protected]'

这时当私有仓库推送时,会自动构建推送到公开仓库