Actions自动部署Hexo博客

381 字
2 分钟
Actions自动部署Hexo博客

参考#

利用 Github Actions 自动部署 Hexo 博客 GitHub Action + Hexo 实现在线写作

前言#

为了搭建HexoPlusPlus所以先部署了Actions.

准备仓库#

Source_code //放源代码文件scaffolds、source、themes、_config.yml、package.json、package-lock.json(删除.git) limitationai.github.io //放静态文件(也就是发布页)

生成密钥,公钥#

#生成公钥,密钥
ssh-keygen -f github-deploy-key

Windows生成后会在C:\Users\你的用户名.ssh文件夹里面有两个文件分别是公钥github_rsa.pub和密钥github_rsa。

配置密钥#

复制 github-deploy-key 文件内容,在放源码的Source_code仓库 Settings -> Secrets -> Add a new secret 页面上添加。

配置公钥#

复制 github-deploy-key.pub 文件内容,在 limitationai.github.io 仓库 Settings -> Deploy keys -> Add deploy key 页面上添加。

添加Actions#

将以下的代码复制粘贴,并且根据自身情况修改

name: 自動部署 Hexo
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]
steps:
- name: 开始运行
uses: actions/checkout@v1
- name: 设置 Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: 配置 Git 环境
env:
ACTION_DEPLOY_KEY: ${{secrets.HEXO_DEPLOY_PRIVATE_KEY}}
run: |
mkdir -p ~/.ssh/
echo "$ACTION_DEPLOY_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan github.com >> ~/.ssh/known_hosts
git config --global user.name "limitationai"
git config --global user.email "limitationai@gmail.com"
- name: 安装 Hexo CI
run: |
export TZ='Asia/Shanghai'
npm i -g hexo-cli
npm i
- name: 安装插件
run: |
npm install hexo-renderer-pug --save
npm install hexo-renderer-stylus --save
npm install hexo-deployer-git --save
npm install hexo-generator-search --save
npm install hexo-douban --save
npm install hexo-generator-feed --save
npm install hexo-abbrlink --save
npm install hexo-wordcount --save
- name: 部署博客
run: |
rm -rf .deploy_git
hexo g && hexo douban && hexo deploy
rm ~/.ssh/id_rsa

结语#

最后去github个人仓库界面看见有橙色的小圆点就代表部署成功了

文章分享

如果这篇文章对你有帮助,欢迎分享给更多人!

Actions自动部署Hexo博客
https://vtdd.vip/posts/actions自动部署hexo博客/
作者
Zero
发布于
2021-08-26
许可协议
CC BY-NC-SA 4.0

评论区

Profile Image of the Author
Zero
有三件事人类都要经历:出生、生活和死亡。他们出生时无知无觉,死到临头,痛不欲生,活着的时候却又怠慢了人生。——拉布吕耶尔
分类
标签
最新动态
站点统计
文章
25
动态
1
分类
7
标签
27
总字数
11,266
运行时长
0
最后活动
0 天前
站点信息
构建平台
Local
博客版本
Firefly v6.14.3
文章许可
CC BY-NC-SA 4.0