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

推荐订阅源

WordPress大学
WordPress大学
博客园 - 司徒正美
宝玉的分享
宝玉的分享
阮一峰的网络日志
阮一峰的网络日志
The Cloudflare Blog
月光博客
月光博客
博客园 - 【当耐特】
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 三生石上(FineUI控件)
博客园 - 聂微东
小众软件
小众软件
Hugging Face - Blog
Hugging Face - Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Apple Machine Learning Research
Apple Machine Learning Research
V
V2EX
Jina AI
Jina AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
罗磊的独立博客
雷峰网
雷峰网
博客园 - 叶小钗
量子位
IT之家
IT之家

Louis C Deng's Blog

RoPE: Properties, Patterns, and Long-Context Behavior CS336 Assignment 1: Large Language Model Training and Inference CS231n Lecture Note: Generative Models CS231n Lecture Note: Self-Supervised Learning CS231n Lecture Note: Large Scale Distributed Training 自動微分 | DIY 實現自己的 PyTorch From RNNs to Transformers CS231n Lecture Note VII: Recurrent Neural Networks Uncovering Batch & Layer Normalization CS231n Lecture Note VI: CNN Architectures and Training CS231n Lecture Note V: Convolution Neural Networks Basics Demystifying Softmax Loss: A Step-by-Step Derivation for Linear Classifiers Backpropagation: A Vector Calculus Perspective CS231n Lecture Note IV: Neural Networks and Backpropagation CS231n Lecture Note III: Optimization CS231n Lecture Note II: Linear Classifiers CS231n Lecture Note I: Image Classification CSAPP Cache Lab II: Optimizing Matrix Transposition CSAPP Cache Lab I: Let's simulate a cache memory! CS188 Search Lecture Notes III CS188 Search Lecture Notes II How to Use TouchID for Sudo Commands on macOS CS188 Search Lecture Notes I RECAP2025: 留白 CSAPP Bomb Lab 解析 x64 暫存器速查表 CSAPP Data Lab 解析 矩陣的 Modified Gram Schmidt 方法 聊一聊位掩碼(Bit Mask) 整數溢位與未定義行為
用 GitHub Actions 部署 Hexo 部落格
Louis C Deng · 2020-08-22 · via Louis C Deng's Blog

最近有一個朋友找我,說她弄了一個 Hexo 部落格,想做 GitHub Actions 自動部署,奈何不會弄,只好讓我幫忙。

GitHub Actions

GitHub Actions 是 GitHub 推出的持續整合服務,最近不要錢了,用(白嫖)的人就多起來了。

程式碼

話不多說,直接上程式碼:

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
name: "Hexo Blog Builder"

on: [push, pull_request]

jobs:
build:
name: "Hexo Blog Build"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 1
- uses: actions/setup-node@v1
with:
node-version: '12'
- name: Install Hexo
run: npm install -g hexo
- name: Install Dependencies
run: npm install
- name: Clean Previous Build
run: rm -rf docs
- name: Hexo Clean
run: hexo clean
- name: Generate New Build
run: hexo generate
- name: Move docs/
run: mv public docs
- name: Publish
run: |
mkdir -p ~/.ssh/
echo "${{ secrets.KEY }}" > ~/.ssh/id_rsa.pub
chmod 600 ~/.ssh/id_rsa.pub
ssh-keyscan github.com >> ~/.ssh/known_hosts
git config --global user.name "Hexo Deploy Bot"
git config --global user.email "nobody@nobody.nobody"
git config --global core.quotepath false
git add --all
git commit -m "Hexo Blog Build"
git push origin master

本 Action 需要你的 ssh 公鑰,也就是 id_rsa.pub 存在專案設定中的 Secrets 內。

TL;DR

具體實現很簡單,用 Hexo 自帶生成器生成到 public 目錄,把 public 目錄改名為 docs。最後 push 到專案裡。

push 使用 SSH Key,實現免密碼。

在 GitHub Pages 設定中,需要把 Source 改為 docs 目錄。

後記

如果大家有什麼改進的好方法,可以在下方評論!