deploy.yml
· 1.8 KiB · YAML
Raw
name: 自动部署
on:
push:
branches:
- main
release:
types:
- published
workflow_dispatch:
env:
TZ: Asia/Shanghai
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: 检查分支
uses: actions/checkout@main
with:
ref: main
- name: 缓存项目 npm 包
id: cache-node-modules
uses: actions/cache@v2
with:
path: node_modules
key: ${{ runner.os }}-${{ matrix.node-version }}-nodeModules-${{ hashFiles('package-lock.json') }}-${{ hashFiles('package.json') }}
restore-keys: |
${{ runner.os }}-${{ matrix.node-version }}-nodeModules-
- name: 安装 Node
uses: actions/setup-node@main
with:
node-version: "20.x"
- name: 安装 Hexo 及 压缩插件
run: |
npm install hexo-cli --global
- name: 安装依赖
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: |
npm install --save
- name: 清理文件树
run: |
npm run clean
- name: 生成静态文件并压缩
run: |
npm run build
- name: 部署
run: |
cd ./public
git init
git config --global user.name '${{ secrets.GITHUBUSERNAME }}'
git config --global user.email '${{ secrets.GITHUBEMAIL }}'
git add .
git commit -m "${{ github.event.head_commit.message }}··[$(date +"%Z %Y-%m-%d %A %H:%M:%S")]"
git push --force --quiet "https://${{ secrets.GITHUBUSERNAME }}:${{ secrets.GITEETOKEN }}@gitee.com/${{ secrets.GITHUBUSERNAME }}/blog.git" master:master
git push --force --quiet "https://${{ secrets.GITHUBUSERNAME }}:${{ secrets.GITHUBTOKEN }}@github.com/${{ secrets.GITHUBUSERNAME }}/liushen-blog.git" master:refs/heads/page
1 | name: 自动部署 |
2 | |
3 | on: |
4 | push: |
5 | branches: |
6 | - main |
7 | |
8 | release: |
9 | types: |
10 | - published |
11 | |
12 | workflow_dispatch: |
13 | |
14 | env: |
15 | TZ: Asia/Shanghai |
16 | |
17 | jobs: |
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 |