Github action 部署博客
Github action 部署博客(vitepress)
双仓库方案:
source 仓库: 存放源码和.md 文件(随着该仓库的更新,会自动触发 action 构建到.io 仓库)
username.github.io 仓库: 存放构建后的静态文件
GitHub Action 配置
- 在 source 仓库创建 workflow 文件:
- 设置部署密钥:
- 生成 SSH 密钥对
- 私钥添加到 source 仓库的 Secrets
- 公钥添加到部署仓库的 Deploy Keys
详细指南
- 在 source 仓库
1 | ssh-keygen -t rsa -b 4096 -C "your-email@example.com" -f deploy_key |
- 配置仓库密钥:
在 Source 仓库:
去 Settings -> Secrets and variables -> Actions -> New repository secret
添加名为 DEPLOY_KEY 的 secret,内容是 deploy_key(私钥里面完整内容)
在 .io 仓库:
去 Settings -> Deploy keys -> Add deploy key
添加名为 DEPLOY_KEY 的 secret,内容是 deploy_key.pub(公钥里面完整内容)
勾选 “Allow write access”
- 在 Source 仓库创建 deploy.yml 文件
示例:
1 | name: Deploy VitePress site to Pages |
GitHub Actions 流程
- 拉取代码
- 安装依赖
- 构建站点
- 自动部署到 github.io 仓库
All articles on this blog are licensed under CC BY-NC-SA 4.0 unless otherwise stated.