简单记录,步骤潦草

示例

1. .gitignore

根路径 .gitignore 内容

1
2
3
4
5
6
7
8
9
10
11
.DS_Store
#/Thumbs.db
/db.json
*.log
node_modules/
public/
.deploy*/
.deploy_git/
.deploy_git*/
.idea
themes/butterfly/.git

2. workflows

根路径 .github/workflows/autodeploy.yml 内容

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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
name: Auto deploy
# 当有改动推送到master分支时,启动Action
on:
workflow_dispatch:
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: 检查分支
uses: actions/checkout@v2
with:
ref: main

- uses: szenius/set-timezone@v1.0 # 设置执行环境的时区
with:
timezoneLinux: "Asia/Shanghai"

- name: 安装 Node
uses: actions/setup-node@v1
with:
node-version: "18.x"

- name: 安装 Hexo
run: |
export TZ='Asia/Shanghai'
npm install hexo-cli -g

- name: 缓存 Hexo
uses: actions/cache@v1
id: cache
with:
path: node_modules
key: ${{runner.OS}}-${{hashFiles('**/package-lock.json')}}

- name: 安装依赖
if: steps.cache.outputs.cache-hit != 'true'
run: |
npm install gulp-cli -g #全局安装gulp
npm install --save

- name: Generate static file
run: |
hexo clean ; hexo generate ; gulp

- name: 推送百度 url
run: |
hexo deploy

- name: Deploy static file
run: |
cd ./public
git init
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git config --global user.name 'github-actions[bot]'
git add .
git commit -m "$(date +'%Y/%m/%d')"
git push --force --quiet "https://mycpen:${{ secrets.GH_TOKEN }}@github.com/mycpen/blog.git" master:main

- name: Delete workflow runs
uses: Mattraks/delete-workflow-runs@v2
with:
token: ${{ secrets.GH_TOKEN }}
repository: ${{ github.repository }}
retain_days: 30
keep_minimum_runs: 6

Actions Secrets 变量含义

Secrets 变量释义
GH_TOKENGitHub Token

3. 插件

hexo-baidu-url-submit:https://github.com/huiwang/hexo-baidu-url-submit

根路径 _config.yml 配置文件

1
2
3
4
5
6
7
8
9
10
11
12
# Deployment
## Docs: https://hexo.io/docs/one-command-deployment
deploy:
- type: baidu_url_submitter # 这是新加的百度主动推送

# 百度主动推送
# https://github.com/huiwang/hexo-baidu-url-submit
baidu_url_submit:
count: 1000 # 提交最新的多少个链接
host: blog.xxx.com # 在百度站长平台中添加的域名
token: xxxxxx # 秘钥
path: baidu_urls.txt # 文本文档的地址, 新链接会保存在此文本文档里

参考

  1. Akilar | 使用Github Action实现全自动部署

  2. 安知鱼 | hexo博客工作流CI(一键部署的快乐)

  3. CCKNBC | 工作流示例

  4. https://github.com/Mattraks/delete-workflow-runs

  5. https://github.com/dmego/home.github.io/blob/gh-pages/.github/workflows/auto-bing.yml