根据博客A,跑通了GitHub Actions,但未能实现GitHub Pages的自动发布。这篇博客总的步骤没有问题,但提供的hexo-deploy.yml缺少了发布到公开仓库的步骤。
参考博客B进行修改,得到可用的hexo-deploy.yml文件如下:
name: Hexo Deploy
# 只监听 main 分支的改动
on:
push:
branches:
- main
# 自定义环境变量,这个GIT_USER和GIT_EMAIL配置成你自己的,GIT_EMAIL尽量和上面的`ssh-keygen -f hexo-deploy-key -C "your email"`中的your email保持一致
env:
GIT_USER: your user name
GIT_EMAIL: your email addr
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
# 获取博客源码(即Actions所在仓库源码)
- name: Checkout
uses: actions/checkout@v2
# Node.js
- name: Set up Node.js
uses: actions/setup-node@v1
with:
node-version: '12'
# 安装依赖
- name: Install Dependencies
run: |
npm install
# 生成HTML文件
- name: Deploy
run: |
npx hexo clean && npx hexo g
# 发布到公开仓库
- name: Deploy To Blog
uses: peaceiris/actions-gh-pages@v3
with:
deploy_key: ${{ secrets.HEXO_DEPLOY_PRI }} # 按「博客A」步骤配置
external_repository: tac-kit/tac-kit.github.io # github.io公开仓库地址
publish_dir: ./public
publish_branch: pages