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

推荐订阅源

F
Fortinet All Blogs
爱范儿
爱范儿
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
B
Blog
WordPress大学
WordPress大学
Jina AI
Jina AI
GbyAI
GbyAI
aimingoo的专栏
aimingoo的专栏
N
Netflix TechBlog - Medium
腾讯CDC
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
阮一峰的网络日志
阮一峰的网络日志
The GitHub Blog
The GitHub Blog
V
Visual Studio Blog
Google DeepMind News
Google DeepMind News
月光博客
月光博客
博客园 - Franky
Y
Y Combinator Blog
MyScale Blog
MyScale Blog
大猫的无限游戏
大猫的无限游戏
Martin Fowler
Martin Fowler
雷峰网
雷峰网
小众软件
小众软件
H
Hackread – Cybersecurity News, Data Breaches, AI and More

Hi, I Am I

[I Am I 年度简报] — 不知终日梦为鱼 初探 ESP32-CAM QQ 聊天记录 MHT 文件转 HTML [I Am I 年度简报] - 草木本无意,荣枯自有时。 Hexo 中实现 Live Photos 支持 写在当下 NKCTF 2024 1z_F0r3ns1c5 Writeup 春秋杯冬季赛 2023 Writeup [I Am I 年度简报] - 2023 某内网渗透内部赛 Writeup 强网拟态 2023 Writeup 浅析CobaltStrike流量解密 陇剑杯 2023 Writeup CTF线下赛AWDP总结 ISCC 2023 Writeup ISCC 2023 实战题 Writeup CISCN 2023 Writeup 福建闽盾杯网络空间安全大赛 2023 Writeup 天一永安杯宁波市网络安全大赛 2023 Writeup 贵阳大数据及网络安全精英对抗赛 2023 Writeup 红明谷杯 2023 Writeup Confetti 带来有仪式感的鼓励 记一次 JS 逆向密码加密 [I Am I 年度简报] – 2022 PHP 读取 Excel 文件内容并写入数据库 从0开始的 MoeCTF 开发之路 观安杯 2022 Writeup 利用微信服务号实现早安自动化 Cloudflare批量拉黑IP脚本 蓝帽杯 2022 Writeup
Github Actions 自动化部署 Hexo
2023-11-06 · via Hi, I Am I

上一次使用 Gtihub Actions 还是用在 TenAPI Docs 项目,通过 Actions 自动化编译 VuePress,不过目前每次更新文章到也不是很麻烦,直接两条命令完事。

hexo n 'title' # 新建文章
hexo g -d     # 编译部署

但是目前的痛点就是:每次终端和 Github 通信都需要开一下代理,而不像浏览器设置了分流规则… 其次就是面临备份的问题,所以干脆全套迁移线上了。

创建仓库

这里我们需要创建两个仓库

  • Blog - 私有仓库,用来存储你博客文件
  • [username].github.o - 公有仓库,用来存储编译后的博客文件及 Github Pages

生成公私钥

使用 CMD 执行以下命令,会在当前目录生成公私钥:hexo-action.pubhexo-action

ssh-keygen -t rsa -b 4096 -C "$(git config user.email)" -f hexo-ation -N ""

配置Deploy Key

<username>.github.ioSettings -> Deploy keys -> Add deploy key 中添加公钥 hexo-action.pubAllow write access 勾选,地址如下

https://github.com/<usernmae>/<repo>.github.io/settings/keys

BlogSettings -> Secrets -> Secrets and variables -> actions -> New repository secret 中添加私钥 hexo-action,同时命名为 ACTIONS_DEPLOY_KEY。具体地址如下

https://github.com/<usernmae>/<repo>/settings/secrets/actions

配置Github Actions

这里主要用的 actions-gh-pages 作为 Actions ,大家唯一需要修改的地方为部署仓库: external_repository 和提交分支:publish_branch 配置项。同时当 Blog 仓库的 main 分支(配置项:branches)发生 pull 时候将自动触发 Actions,将以下内容存放到 .github/workflows/deployment.yml 文件内即可。

name: Hexo-Build-Pages

on:
  push:
    branches:
    - main

jobs:
  pages:
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
    - uses: actions/checkout@v3
        with:
          submodules: true

    - name: Use Node.js 16.x
        uses: actions/setup-node@v3
        with:
          node-version: '16.18.1'

    - name: Install Dependencies
        run: npm install

    - name: Build
        run: npm run build

    - name: Deploy
        uses: peaceiris/actions-gh-pages@v3
        with:
          deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
          external_repository: <username>/<usernmae>.github.io
          publish_dir: ./public
          publish_branch: master
          force_orphan: true
          keep_files: false
          user_name: 'github-actions[bot]'
          user_email: 'github-actions[bot]@users.noreply.github.com'

目录总览

最终 Blog 仓库目录结构大致如下

Blog
├─ .github
│    └─ workflows
│           └─ deployment.yml
├─ .gitignore
├─ _config.yml
├─ db.json
├─ package.json
├─ source
└─ themes