抱歉,您的浏览器无法访问本站
本页面需要浏览器支持(启用)JavaScript
了解详情 >

仓库环境

Hexo 源码存放在 GitHub 私有仓库:https://github.com/varm/source_hexo

GitHub Page 仓库:https://github.com/varm/hexo

CODING Page 仓库:https://e.coding.net/varm/hexo

以下简称 source_hexo 仓库、hexo 仓库和 CODING Page 仓库。

需求

本地执行 git push 命令将代码提交到源码仓库 source_hexo ,此仓库通过 GitHub Actions 自动将网站发布到 GitHub Page 仓库 hexo。

配置 CONFIG

修改 _config.yml

1
2
3
4
5
6
deploy:
type: 'git'
branch: 'master'
repo:
github: git@github.com:varm/hexo.git,master
coding: 'git@e.coding.net:varm/hexo.git'

配置执行 GitHub Actions 的 yaml 文件

hexo 根目录\\.github\\workflows\\目录下创建一个 .yml.yaml 文件,比如 deploy.yml:

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
name: CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build-and-deploy:
runs-on: ubuntu-latest
container:
image: node:13-alpine

steps:
- uses: actions/checkout@v1
with:
submodules: true

- name: Install Dependencies
run: |
npm install

- name: Deploy
id: deploy
uses: varm/hexo-action@master
with:
deploy_key: ${{ secrets.HEXO_DEPLOY_PRI }}
# user_name: your github username # (or delete this input setting to use bot account)
# user_email: your github useremail # (or delete this input setting to use bot account)
commit_msg: ${{ github.event.head_commit.message }}
- name: Get the output
run: |
echo "${{ steps.deploy.outputs.notify }}"
  1. 生成 SSH Key

    1
    ssh-keygen -t rsa -C 邮箱地址 -f id_rsa.hexo

    生成成功后有两个文件,私钥 id_rsa.hexo 和公钥 id_rsa.hexo.pub

  2. 将私钥添加到私有仓库 source_hexo,打开仓库,点击 [Settings]->[Secrets]->[New secret],上面 deploy.yml 文件中配置了一个内置参数:${{ secrets.HEXO_DEPLOY_PRI }},那么这里 New secret 的 Name 就要和 HEXO_DEPLOY_PRI保持一致,也叫:HEXO_DEPLOY_PRI,然后将 id_rsa.hexo文件内容全部复制粘贴到这里的 Value。

  3. 配置 GitHub 公钥,打开 hexo 仓库,点击 [Settings]->[Deploy keys]->[Add deploy key],Title 随便写,将 id_rsa.hexo.pub文件全部内容复制粘贴到这里的 Key,勾选 [Allow write access],最后点击 [Add key] 即可。

  4. 配置 CODING 公钥,登录 CODING Page 仓库,点击[设置]->[部署公钥]->[新建部署公钥],公钥名称随便写,id_rsa.hexo.pub文件全部内容复制粘贴到这里的[公钥内容],勾选[永久有效]和[授予推送权限],最后点击[新建]即可。

    发布项目

    直接执行 git 提交即可

    1
    2
    3
    git add .
    git commit -m "Publish."
    git push origin master

    提交成功后 GitHub Actions 开始执行部署,可以到 source_hexo 项目的 [Actions] 中查看详情,部署成功后,可以看到 GitHub Page 仓库和 CODING Page 仓库的内容已经更新。

评论