ci(文档部署): 优化文档构建和部署流程
All checks were successful
Build and Deploy mdBook to Pages Branch / build-and-deploy (push) Successful in 1m32s
All checks were successful
Build and Deploy mdBook to Pages Branch / build-and-deploy (push) Successful in 1m32s
使用通用的 ubuntu-latest runner 替代专用 runner 改用 peaceiris/actions-mdbook 和 actions-gh-pages 简化流程 移除手动缓存和安装 mdbook 的步骤 将部署方式改为推送到 pages 分支
This commit is contained in:
@@ -1,49 +1,41 @@
|
|||||||
name: Build and Deploy mdBook
|
name: Build and Deploy mdBook to Pages Branch
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
|
# 只有 main 分支的变更才会触发部署
|
||||||
- main
|
- main
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-deploy:
|
build-and-deploy:
|
||||||
runs-on: docs-deployer
|
runs-on: ubuntu-latest # 现在我们可以用通用的 Runner,不再需要挂载数据卷
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Cache mdBook
|
|
||||||
id: cache-mdbook
|
|
||||||
uses: actions/cache@v3
|
|
||||||
with:
|
with:
|
||||||
path: ~/.local/bin/mdbook
|
# 获取所有历史记录,以便 peaceiris/actions-gh-pages 操作
|
||||||
key: ${{ runner.os }}-mdbook-0.4.36
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Install mdBook if not cached
|
- name: Install mdBook
|
||||||
# 只有在缓存未命中时才执行
|
uses: peaceiris/actions-mdbook@v1
|
||||||
if: steps.cache-mdbook.outputs.cache-hit != 'true'
|
|
||||||
run: |
|
|
||||||
# --- ↓↓↓ 新增的修复步骤 ↓↓↓ ---
|
|
||||||
# 在解压前,确保目标目录存在。-p 参数会创建所有必要的父目录。
|
|
||||||
echo "Creating directory ~/.local/bin..."
|
|
||||||
mkdir -p ~/.local/bin
|
|
||||||
# --- ↑↑↑ 修复步骤结束 ↑↑↑ ---
|
|
||||||
|
|
||||||
echo "Downloading and extracting mdBook..."
|
- name: Build mdBook
|
||||||
curl -sL https://github.com/rust-lang/mdBook/releases/download/v0.4.36/mdbook-v0.4.36-x86_64-unknown-linux-gnu.tar.gz | tar xvz -C ~/.local/bin
|
run: mdbook build
|
||||||
chmod +x ~/.local/bin/mdbook
|
|
||||||
|
|
||||||
- name: Build mdBook docs
|
- name: Deploy to 'pages' branch
|
||||||
# 使用缓存或刚刚安装的 mdbook 进行构建
|
uses: peaceiris/actions-gh-pages@v3
|
||||||
run: ~/.local/bin/mdbook build
|
with:
|
||||||
|
# 我们用 personal_token 替代默认的 github_token
|
||||||
- name: Deploy to Gitea Pages Directory
|
personal_token: d58a2e62b51446633a0c87df1591ba34db1ecacb
|
||||||
run: |
|
# 指定 Gitea 服务器的地址
|
||||||
TARGET_DIR="/mnt/gitea-pages/dao-os/dao-os-docs"
|
external_repository: Dao-OS/dao-os-docs
|
||||||
SOURCE_DIR="./book"
|
# 要推送到哪个分支
|
||||||
echo "🚀 Deploying to host via volume mount using 'cp'..."
|
publish_branch: pages
|
||||||
mkdir -p "$TARGET_DIR"
|
# 要推送哪个目录下的内容
|
||||||
find "$TARGET_DIR" -mindepth 1 -delete
|
publish_dir: ./book
|
||||||
cp -r "$SOURCE_DIR"/. "$TARGET_DIR/"
|
# 提交代码的用户信息
|
||||||
echo "✅ Deployment successful!"
|
user_name: "Gitea Actions"
|
||||||
|
user_email: "actions@gitea.example.com"
|
||||||
|
# Gitea 需要这个设置
|
||||||
|
gitea_server: nest.doylee.cn
|
||||||
|
|||||||
Reference in New Issue
Block a user