github工作流自动完成hexo部署

github工作流自动完成hexo部署

你应该先确保本地可以正常生成hexo,并且可以正常部署!

1. 在hexo项目\.github\workflows\目录下创建任意名称的.yml文件

2. 将下列yml内容复制到你的文件中,并修改env中的内容为你的配置

官网给出的yml文件,好像并没有考虑到使用主题的情况。我用的fluid主题,在checkout时无法正常签出,导致后续hexo g命令报错no layout。这里给出的解决方案是使用子模块,即git中的submodule。将资源文件全部整合到hexo的source文件目录中,配置文件放在hexo项目根目录中。 不要直接修改主题中的任何文件!!

3. 配置GitHub项目密钥

密钥存放位置
secrets存放位置
比如我存放的名称就叫`HEXO_DEPLOY_KEY`,于是下方就填写`$`。

4. 尝试push,并查看GitHub-Action中的日志。如果成功则会显示绿色,如果是红色就要查看日志慢慢排查咯~

源代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# PATH:`网站目录\.github\workflows\autogen.yml`
name: deploying Hexo project to GitHub pages
on:
push:
branches:
- master # master 分支有 push 行为时就触发这个 action

jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
submodules: 'true'
- name: Build and Deploy
uses: theme-keep/hexo-deploy-github-pages-action@master # 使用专门部署 Hexo 到 GitHub pages 的 action
env:
PERSONAL_TOKEN: ${{ secrets.HEXO_DEPLOY_KEY }} # secret 名
PUBLISH_REPOSITORY: Destiny-End/Destiny-End.github.io # 公共仓库,格式:GitHub 用户名/仓库名
BRANCH: main # 分支,我使用的是main分支
PUBLISH_DIR: ./public # 部署 public 目录下的文件

env填写方式:

Key Value Information Type Default Required
PERSONAL_TOKEN Depending on the repository permissions you may need to provide the action with a GitHub Personal Access Token in order to deploy. You can learn more about how to generate one here. This should be stored as a secret. secrets Yes
PUBLISH_REPOSITORY The repository the action should deploy to. for example theme-keep/site env Yes
BRANCH The branch the action should deploy to. for example master env gh-pages Yes
PUBLISH_DIR The folder the action should deploy. for example ./public env ./public No
CNAME The domain name of your GitHub Pages specified in a CNAME env No

github工作流自动完成hexo部署
http://blog.jiuge.host/post/20230723115242.html
作者
Pigeon
发布于
2023年7月23日
许可协议
CC BY-NC-SA 3.0