Use github action to auto deploy hexo

在 git 文件夹中使用 hexo 是一件麻烦的事情,每次 commit 完之后都要手动 generate 然后 deploy 一下,可以使用 github action 来简化这一操作

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
35
36
37
38
name: Deploy Hexo Site

on:
push:
branches:
- source

jobs:
build-and-deploy:
runs-on: ubuntu-latest
environment:
name: production
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "20"

- name: Install Dependencies
run: npm install

- name: Configure Git
run: |
git config --global user.name github-actions[bot]
git config --global user.email 41898282+github-actions[bot]@users.noreply.github.com

- name: Build and Deploy
run: |
npm install hexo-cli -g
hexo generate
hexo deploy
env:
GITHUB_TOKEN: ${{ secrets.MY_TOKEN }}