Last active 1732983125

github action构建hexo源码,yml文件分享

deploy.yml Raw
1name: 自动部署
2
3on:
4 push:
5 branches:
6 - main
7
8 release:
9 types:
10 - published
11
12 workflow_dispatch:
13
14env:
15 TZ: Asia/Shanghai
16
17jobs:
18 deploy:
19 runs-on: ubuntu-latest
20 steps:
21 - name: 检查分支
22 uses: actions/checkout@main
23 with:
24 ref: main
25
26 - name: 缓存项目 npm 包
27 id: cache-node-modules
28 uses: actions/cache@v2
29 with:
30 path: node_modules
31 key: ${{ runner.os }}-${{ matrix.node-version }}-nodeModules-${{ hashFiles('package-lock.json') }}-${{ hashFiles('package.json') }}
32 restore-keys: |
33 ${{ runner.os }}-${{ matrix.node-version }}-nodeModules-
34
35 - name: 安装 Node
36 uses: actions/setup-node@main
37 with:
38 node-version: "20.x"
39
40 - name: 安装 Hexo 及 压缩插件
41 run: |
42 npm install hexo-cli --global
43
44 - name: 安装依赖
45 if: steps.cache-node-modules.outputs.cache-hit != 'true'
46 run: |
47 npm install --save
48
49 - name: 清理文件树
50 run: |
51 npm run clean
52
53 - name: 生成静态文件并压缩
54 run: |
55 npm run build
56
57 - name: 部署
58 run: |
59 cd ./public
60 git init
61 git config --global user.name '${{ secrets.GITHUBUSERNAME }}'
62 git config --global user.email '${{ secrets.GITHUBEMAIL }}'
63 git add .
64 git commit -m "${{ github.event.head_commit.message }}··[$(date +"%Z %Y-%m-%d %A %H:%M:%S")]"
65 git push --force --quiet "https://${{ secrets.GITHUBUSERNAME }}:${{ secrets.GITEETOKEN }}@gitee.com/${{ secrets.GITHUBUSERNAME }}/blog.git" master:master
66 git push --force --quiet "https://${{ secrets.GITHUBUSERNAME }}:${{ secrets.GITHUBTOKEN }}@github.com/${{ secrets.GITHUBUSERNAME }}/liushen-blog.git" master:refs/heads/page
67