GitHub action 自动部署 Hexo

GitHub action 自动部署 Hexo

首先贴上我的 yaml 代码,这可能是目前最简洁的了,因为加上了缓存,所以执行起来也较快,使用的是 https://github.com/yrpang/github-actions-hexo。

执行耗时

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
name: Deploy blog
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Cache node modules # 缓存 node_modules
uses: actions/cache@v1
with:
path: node_modules
key: ${{runner.OS}}-${{hashFiles('**/package-lock.json')}}
- uses: yrpang/github-actions-hexo@master
env:
TZ: Asia/Shanghai # 设置时区
with:
deploykey: ${{secrets.DEPLOY_KEY}} # 这里注意对应自己配置的KEY的名称
username: github-action
email: action@github

使用 GitHub action 还是老生常谈的那一套secret keydeploy key就不多说了,参考:

与其它不太一样的是:

  1. 源码的package.json文件中必须包含hexo-deployer-git

  2. 源码的_config.yml文件中必须包含deploy块,且 repo 必须为 ssh 形式,如:

    1
    2
    3
    4
    5
    6
    7
    # ...
    # 部署
    ## Docs: https://hexo.io/docs/deployment.html
    deploy:
    type: git
    # 这里填写博客 repo 地址,非源码地址
    repo: git@github.com:YOU_USERNAME/blog.git

如果上面的条件确定满足了,直接复制上面的 action 代码使用即可。

本篇文章由 GitHub action 自动生成。