87 lines (75 loc) · 2.44 KB
/
hexo.yaml
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
name: Blog CI/CD
# 触发条件:在 push 到 hexo-blog-backup 分支后触发
on:
repository_dispatch:
workflow_dispatch:
push:
branches:
- master
paths:
- '2020/**.md'
- '2021/**.md'
- '2022/**.md'
- '2023/**.md'
- 'hexo/*'
env:
TZ: Asia/Shanghai
jobs:
blog-cicd:
name: Hexo blog build & deploy
runs-on: ubuntu-latest # 使用最新的 Ubuntu 系统作为编译部署的环境
steps:
- name: Checkout codes
uses: actions/checkout@v3
- name: Setup node
# 设置 node.js 环境
uses: actions/setup-node@v3
with:
node-version: 16
- name: Cache node modules
# 设置包缓存目录,避免每次下载
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
- name: Install hexo dependencies
# 下载 hexo-cli 脚手架及相关安装包
run: |
npm install hexo-cli gulp -g
mkdir hexo-blog
cd hexo-blog
hexo init
npm install hexo-deployer-git --save
npm install hexo-generator-feed --save
npm install hexo-generator-sitemap --save
# - name: SSH connection to Actions
# uses: P3TERX/ssh2actions@v1.0.0
- name: next theme
run: |
cd hexo-blog
git clone https://github.com/theme-next/hexo-theme-next themes/next
cp ../hexo/_next_theme_config.yml themes/next/_config.yml
echo '${{ secrets.VALINE}}' >> themes/next/_config.yml
- name: copy source and config
# 下载 hexo-cli 脚手架及相关安装包
run: |
cd hexo-blog
rm -rf source/_posts/*
cp ../hexo/* . -r
cp ../2020/ source/_posts/ -r
cp ../2021/ source/_posts/ -r
cp ../2022/ source/_posts/ -r
cp ../2023/ source/_posts/ -r
# - name: SSH connection to Actions
# uses: P3TERX/ssh2actions@v1.0.0
- name: Generate files and deploy
# 编译 markdown 文件
run: |
cd hexo-blog
hexo clean
hexo g
cd ./public && git init && git add .
git config --global user.name "zhangolve.automation"
git config --global user.email "zhangolve@gmail.com"
git commit -m "GitHub Actions Auto Builder at $(date +'%Y-%m-%d %H:%M:%S')"
git push --force --quiet "https://${{ secrets.ACCESS_TOKEN }}@github.com/zhangolve/zhangolve.github.io" master:master