之前使用 Travis CI 实现了自动生成并发布 Hexo 博客,现在切换到 GitHub Actions
prepare
- 源码仓库,私有
- 发布仓库,xxx.github.io
有两种方式可以用于 GitHub Actions 发布 Blog
- ssh-key,分别提交 key 到两个仓库,参考 用 GitHub Actions 自动化发布Hexo网站到 GitHub Pages
- token,参考 Hexo 使用 Github Actions 自动更新
source仓库
打开仓库设置,在 Secrets
选项中,点击 Add a new secret
,新建 GH_TOKEN
添加 Github Actions
文件
name: Hexo Auto-Deploy
on: [push]
jobs:
build:
name: Hexo Auto-Deploy by GitHub Actions
runs-on: ubuntu-latest
steps:
- name: 1. git checkout...
uses: actions/checkout@v1
- name: 2. setup nodejs...
uses: actions/setup-node@v1
- name: 3. install hexo...
run: |
npm install hexo-cli -g
npm install
- name: 4. hexo generate public files...
run: |
hexo clean
hexo g
- name: 5. deploy 'public files' to 'xxx.github.io' repo...
env:
GH_REF: https://shenbo:${{ secrets.GH_TOKEN }}@github.com/shenbo/shenbo.github.io.git
run: |
git config --global user.name "shenbo"
git config --global user.email "shenbo@hotmail.com"
git clone ${GH_REF} hexo-public
cp -rf public/* hexo-public/
cd hexo-public
git add .
git commit -am "Deployed by GitHub Actions ..."
git push origin master