GitHub Actions 自动部署 Hexo 脚本
2023-06-13 09:16:05 时间
警告
本文最后更新于 2019-12-28,文中内容可能已过时。
前言
网上虽然有很多通过 GitHub Actions 自动部署 Hexo 的教程,但都有各种各样的问题。 主要问题还是 Workflow 脚本没有写正确,比如插件部分。
步骤
1、生成密钥对(这个也不会的话,方法自行 Google)
ssh-keygen -t rsa -b 4096 -f ~/.ssh/GitHub-actions-deploy
然后会获得一个公钥和私钥。
2、在 GitHub Pages 所在的仓库中添加 “公钥”
找到仓库的 Settings
- Deploye keys
- Add deploy key
Title
填入:ACTION_DEPLOY_KEY
Key
填入:# 步骤 1 生成的密钥对中的公钥
勾上Allow write access
3、在存放 Hexo 源文件的仓库中添加 “私钥”
PS: 跟步骤 2 中的仓库可能是同一个,也可能不是同一个。根据自己的选型设置。
找到仓库的 Settings
- Secrets
- Add a new secret
Name
填入:ACTION_DEPLOY_KEY
Value
填入:# 步骤 1 生成的密钥对中的私钥
4、修改一下 Actions 脚本
下文贴出的 Actions 的 Wordflows 脚本中,其中 3 个地方要改为自己的信息:
git config --global user.name "eallion"
git config --global user.email "eallion@eallion.com"
git clone https://github.com/eallion/eallion.GitHub.io .deploy_git
5、其他注意事项
- 脚本中插件部分可按自己实际用的插件删改,
npm ls --depth 0
可查看自己安装了哪些插件 - 如果没有用到
hexo douban
插件,部署命令:hexo g && hexo douban && hexo deploy
可改为hexo g -d
另外一个建议是,所使用的 theme
中的 主题目录
用 git subtree
添加为子项目去维护。
这样在多环境多终端发布文章时,不会 clone
或 pull
一个空 theme
。
6、git push
文章写好后,不需要在本地构建,只需要 git push
到 GitHub 仓库即可自动部署。
其中部署方式在 Hexo 根目录的 _config.yml
中配置。
脚本配置
注意修改其中提到的几个地方
name: 自动部署 Hexo
#on: [push]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.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.ACTION_DEPLOY_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 "eallion"
git config --global user.email "eallion@eallion.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 1W star 成就达成!
- 基于Vercel部署github-readme-stats
- GitHub page接入Google广告
- 喜大普奔,Github 支持 Markdown 数学公式渲染,README终于可以显示公式了!
- Github 不限量提供免费私有仓库
- 【学习笔记】Git&Github的基本使用
- 国内首发的一本IntelliJ IDEA软件开发手册,GitHub已获百万标星
- git拉取代码冲突了怎么解决_github拉取代码慢
- php漏洞 乌云,GitHub – grt1st/wooyun_search: 乌云公开漏洞、知识库搜索 search from wooyun.org…
- Hexo 搭建博客并部署 github 详解
- 不会PS也没关系!一键生成精美的GitHub推广图!!
- 让程序员动嘴写代码,Copilot测试新功能「嘿,GitHub!」
- 2022 如何在 GitHub 上搭建个人网站(github.io)
- 使用Github Action自动化部署
- Github Actions Hexo 自动部署
- Github Actions 自动部署 Hexo - wuuconix's blog
- 攻击者可滥用 GitHub 代码空间传递恶意软件
- Github 如何查看自己的 star 和 fork
- 最潮程序员,教你打造超有“个性化”的Github主页
- Git在windows下上传文件至github流程详解程序员
- Github Atom简史:差点被GitHub创始人放弃
- 程序员开发抢茅台脚本,两天刷榜 GitHub 后谢幕