惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 三生石上(FineUI控件)
G
Google Developers Blog
Vercel News
Vercel News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
N
Netflix TechBlog - Medium
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Engineering at Meta
Engineering at Meta
B
Blog
博客园_首页
量子位
博客园 - 叶小钗
L
LangChain Blog
T
The Blog of Author Tim Ferriss
云风的 BLOG
云风的 BLOG
Blog — PlanetScale
Blog — PlanetScale
F
Fortinet All Blogs
S
SegmentFault 最新的问题
宝玉的分享
宝玉的分享
D
DataBreaches.Net
雷峰网
雷峰网
The Cloudflare Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Last Week in AI
Last Week in AI
P
Proofpoint News Feed
TaoSecurity Blog
TaoSecurity Blog
罗磊的独立博客
MongoDB | Blog
MongoDB | Blog
The GitHub Blog
The GitHub Blog
I
Intezer
H
Help Net Security
The Hacker News
The Hacker News
The Register - Security
The Register - Security
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
AWS News Blog
AWS News Blog
V
V2EX
Microsoft Security Blog
Microsoft Security Blog
T
Tenable Blog
Spread Privacy
Spread Privacy
A
Arctic Wolf
P
Proofpoint News Feed
T
Threat Research - Cisco Blogs
Schneier on Security
Schneier on Security
C
CERT Recently Published Vulnerability Notes
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The Last Watchdog
The Last Watchdog
Latest news
Latest news
T
Troy Hunt's Blog
L
LINUX DO - 热门话题

ThinkAlone

JavaCard 上手 灵车!开创! Step-CA 日常使用教程 灵上加灵:使用 Pico HSM 和 step-ca 自建一个CA 友善 FriendlyELEC NanoPC-T4 CPU跑分测试 CPU Benchmark 常见物品尺寸记录 树莓派5 Raspberry Pi 5 CPU跑分测试 CPU Benchmark 鼎阳 SDS804X HD 示波器带宽与选件升级 OrangePi Zero3 CPU跑分测试 CPU Benchmark Canokey Canary上手 在2024年配置IPv6是什么怎样一种体验 用 Orange Pi Zero 搭建一台 Stratum 1 的 NTP 服务器 难绷的Zip与中文密码 OrangePi Zero CPU跑分测试 CPU Benchmark 使用 Docker 部署 zhenxun_bot(绪山真寻Bot) 在Docker中运行Klipper 如何优雅的跳过/禁止Steam更新你的游戏 使用 Travis CI 自动构建 Hexo 博客 使DockerHub的Autobuild自动构建ARM/其他 架构的镜像 CoffeeMiner:劫持WiFi网络接入设备进行“挖矿”的框架
使用 GitHub Actions 自动部署Hexo
Disappear9 · 2020-12-26 · via ThinkAlone

2019年时给博客配置了Travis CI 自动构建,然后前几天准备发个文章,写完反手一个git push博客就崩了。

Hexo

首先你的Hexo必须是已经在本地环境下配置好的,能正常运行hexo g

生成&配置秘钥

使用ssh-keygen生成一对秘钥

1
ssh-keygen -t ed25519 -C "Hexo Deploy Key" -f github-deploy-key

直接回车,不要设置密码

在 GitHub 上打开仓库-> Settings -> Secrets添加一个Secrets,NameHEXO_DEPLOY_KEYValue把上面生成的私钥粘贴进去

打开仓库-> Settings -> Deploy keys添加一个Key,TitleHEXO_DEPLOY_PUBKey把上面生成的公钥粘贴进去,勾选下面的Allow write access

准备文件

创建一个空的分支,从原有的hexo源文件目录下拷贝这些文件&文件夹:

  • scaffolds
  • source
  • themes
  • _config.yml(hexo的)
  • package.json

修改配置文件

为了防止以后由于长时间未维护,主题或hexo更新导致的博客炸掉,所以配置主题为submodule。

1
git submodule add https://github.com/JoeyBling/hexo-theme-yilia-plus themes/yilia

在_config.yml的最后添加一项theme_config:

参考:https://blog.xxwhite.com/2020/blog-ci.html#%E4%B8%BB%E9%A2%98%E5%AD%90%E6%A8%A1%E5%9D%97%E5%8C%96

配置Workflow

创建一个新文件:.github/workflows/deploy.yml

.github/workflows/deploy.yml
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
name: Hexo Deploy

on:
push:
branches:
- source

jobs:
build:
runs-on: ubuntu-18.04
if: github.event.repository.owner.id == github.event.sender.id

steps:
- name: Checkout source
uses: actions/checkout@v2
with:
ref: source

- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: '12'

- name: Setup Hexo
env:
ACTION_DEPLOY_KEY: $
run: |
mkdir -p ~/.ssh/
echo "$ACTION_DEPLOY_KEY" > ~/.ssh/id_ed25519
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519
ssh-keyscan github.com >> ~/.ssh/known_hosts
git config --global user.email "[email protected]" #设置git提交时的Email
git config --global user.name "Disappear9" #设置git提交时的用户名
npm install hexo-cli -g
npm install
git submodule update --init --recursive #拉取submodule
rm themes/yilia/_config.yml #删除主题自带的配置文件
chmod +x deploy.sh

- name: Deploy
run: |
hexo g
./deploy.sh

由于使用hexo d部署会让git的commit看起来很丑,所以把部署写进脚本deploy.sh(放在新建分支的根目录下)

deploy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/bin/bash
set -ev
export TZ='Asia/Shanghai'

git clone --depth=1 -b master [email protected]:{用户名}/{仓库}.git .deploy_git

cd .deploy_git
git checkout master
mv .git/ ../public/
cd ../public

git add .
git commit -m "Site updated: `date +"%Y-%m-%d %H:%M:%S"`"
git push origin master:master --force

加个Badge

Build Status

参考:https://docs.github.com/cn/actions/managing-workflow-runs/adding-a-workflow-status-badge

1
https://github.com/<OWNER>/<REPOSITORY>/workflows/Hexo%20Deploy/badge.svg

https://github.com/Disappear9/disappear9.github.io/tree/source
欢迎参考