github actions 自动部署 hexo
2026-09-13 20:12:59 # 博客搭建

github actions 自动部署 hexo,感觉还是有点问题。有很多方法可以解决,但是我这里就不折腾了。

我自己的提问:https://github.com/JamesIves/github-pages-deploy-action/issues/389

问题

hexo 安装 需要全局,但是没有权限无法安装。可以利用docker安装 ,解决权限问题。

但是新版本的 action,作者去掉了docker,鼓励本地直接构建,然后直接同步。

而且同步到其他仓库的功能在新的版本里才可以使用

最后我已使用了本地构建这个方案。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
name: buildAndDeploy
on: [push]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2
with:
persist-credentials: false
- name: Deploy
uses: JamesIves/[email protected]
with:
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
REPOSITORY_NAME: libaibuaidufu/libaibuaidufu.github.io
BRANCH: master
BASE_BRANCH: master
FOLDER: public

骚操作

中途我也想了骚操作,例如用以前的版本,来构建,再用新的版本来部署。最后出现了权限问题。就没有继续了。

因为同步到其他仓库的功能在新的版本里才可以使用

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
name: buildAndDeploy
on: [push]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2
with:
persist-credentials: false
- name: build
uses: JamesIves/github-pages-deploy-action@releases/v2
env:
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
REPOSITORY_NAME: libaibuaidufu/libaibuaidufu/private-blog-deploy-actions
BASE_BRANCH: master
BRANCH: gh-pages
FOLDER: public
BUILD_SCRIPT: npm install hexo-cli -g && npm install && hexo clean && hexo g
- name: Deploy
uses: JamesIves/[email protected]
with:
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
REPOSITORY_NAME: libaibuaidufu/libaibuaidufu.github.io
BRANCH: master
BASE_BRANCH: master
FOLDER: public

windows bat 命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
cls
@echo off
echo 清理中。。。
call hexo clean
echo 重新构建。。。
call hexo g
echo 添加新的修改。。。
call git add .
set /p commit_message=提交内容:
echo 提交新的修改
call git commit -m %commit_message%
echo 推送新的修改
call git push -u origin master
echo 已完成
pause