跨仓库部署
从 Github 的 A 仓库构建完成之后,将构建产物部署到 B 仓库上
使用 peaceiris/actions-gh-pages@v3 以及 deploy_key
进行部署
- 生成 ssh 公钥 和 私钥
sh
ssh-keygen -t ed25519 -C "<email>"
Tip
将 <email> 替换为需要生成 ssh
的邮箱
- 进入 B 仓库设置,进入目录
Settings > Deploy Keys(Security)
,点击Add deploy key
,填入任意Title
以及第一步中生成的 公钥,并勾选Allow write access
Tip
如果第一步没有修改文件名,应该是名称为 id_ed25519.pub 的文件
- 进入 A 仓库,进入目录
Settings > Secrets and variables > Actions
,在Secrets
的 tab 下点击New repository secret
,填入任意Name
(在后续会使用到这个 Name,建议可以设置为比如ACTIONS_DEPLOY_KEY
),在Secrets
填入第一步中生成的 私钥
Tip
如果第一步中没有修改名,应该是名称为 id_ed25519 的文件
- 新增 A 仓库的
.github/workflows/deploy.yml
(文件名可任意) 文件,并添加下面内容
yml
name: Deploy Docs
on:
workflow_dispatch: {}
# master 发生 push 时触发部署
push:
branches:
- master
jobs:
build-and-deploy:
name: Start Deploy
# 指定运行机器
runs-on: ubuntu-latest
# 执行步骤
steps:
# 检出仓库
- uses: actions/checkout@v3
with:
fetch-depth: 0
# 安装 Node.js
- uses: actions/setup-node@v3
with:
node-version: '16.19.0'
cache: npm
# 安装依赖
- name: Install dependencies
run: npm ci
# 构建文档
- name: Build
run: npm run docs:build
# 部署到 GitHub Pages
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }} # 第 3 步中填写的 Name
publish_dir: ./docs/.vitepress/dist # 需要从 A 仓库中发布到 B 仓库的打包产物
external_repository: lin52025iq/lin52025iq.github.io # B 仓库的地址
publish_branch: gh-pages # 发布到 B 仓库的分支