GitHub Actions 搞定Hexo自动部署

第一次尝试 GitHub Actions,很赞👍

  • 语法简单,上手容易,但又足够强大,感觉可以干任何事情
  • 复用性强,很容易通过use复用,市场里有很多常用action
  • 配额给的足够

官方文档传送门

[当前仓库部署用的workflow]

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
39
name: Deploy

on:
[push] # 触发事件

jobs:
build:
runs-on: ubuntu-latest # 运行环境为最新版 Ubuntu
name: A job to deploy blog.
steps:
- name: Checkout # 获取源码
uses: actions/checkout@v1 # 使用官方常用action
with: # 条件
submodules: true

- name: copyCfg # 更新配置
run: cp _config.theme.yml themes/icarus/_config.yml

# Caching dependencies to speed up workflows. (GitHub will remove any cache entries that have not been accessed in over 7 days.)
- name: Cache node modules
uses: actions/cache@v1
id: cache
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true' # 如果没有cache
run: npm install # 安装 node modules 相关依赖

# 发布
- name: Deploy
id: deploy
uses: sma11black/hexo-action@v1.0.0 # 使用 社区贡献的action
with:
deploy_key: ${{ secrets.DEPLOY_KEY }}
user_name: xuewuli
user_email: 26448247@qq.com