Hexo使用Github Action自动部署

Hexo 配置

1
2
3
4
deploy:
type: git
repo: "git@github.com:simonkimi/simonkimi.github.io.git"
branch: master

需要在 Page 的仓库中配置 Deploy Key,用于 Github Action 自动部署。

secrets.DEPLOY_KEY 为私钥。

Github Action 配置

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
name: 自动部署文章

on:
push:
branches:
- master
workflow_dispatch:

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: "recursive"

- name: Setup Git LFS
run: |
sudo apt-get install git-lfs
git lfs install
git lfs pull

- name: Setup .npmrc for GitHub Packages
run: |
echo "@simonkimi:registry=https://npm.pkg.github.com" >> .npmrc
echo "//npm.pkg.github.com/:_authToken=${{ secrets.PACKAGE_TOKEN }}" >> .npmrc

- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: "latest"

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "18"
cache: "pnpm"

- name: Setup SSH for deploy
uses: webfactory/ssh-agent@v0.5.3
with:
ssh-private-key: ${{ secrets.DEPLOY_KEY }}

- name: Install dependencies
run: pnpm install

- name: Configure Git
run: |
git config --global user.email "git@z31.mozmail.ink"
git config --global user.name "simonkimi"

- name: Deploy
run: pnpm exec hexo clean && pnpm exec hexo deploy


Hexo使用Github Action自动部署
https://simonkimi.githubio.io/2022/01/30/Hexo使用Github-Action自动部署/
作者
simonkimi
发布于
2022年1月30日
许可协议