ci(docs): 简化文档构建和部署流程
Some checks failed
Build and Deploy mdBook / build-and-deploy (push) Failing after 1m27s
Some checks failed
Build and Deploy mdBook / build-and-deploy (push) Failing after 1m27s
使用专用的 docs-deployer runner 替代通用 runner,移除 Rust 工具链缓存和安装步骤 直接通过 volume mount 部署文档,使用 rsync 替代 cp 命令提高部署效率
This commit is contained in:
@@ -1,70 +1,40 @@
|
||||
name: Build and Deploy Dao OS Docs
|
||||
name: Build and Deploy mdBook
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main # 当推送到 main 分支时触发
|
||||
- main
|
||||
|
||||
jobs:
|
||||
build-and-deploy:
|
||||
runs-on: ubuntu-latest # 或者你的 Gitea Actions 运行器
|
||||
env: # 在 Job 级别设置环境变量
|
||||
ACTIONS_STEP_DEBUG: true # 启用 Actions 步骤的调试输出
|
||||
ACTIONS_RUNNER_DEBUG: true # 启用 Runner 的调试输出
|
||||
# 依然使用标签,确保任务只被这个配置了挂载的 Runner 执行
|
||||
runs-on: docs-deployer
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4 # 使用最新的 checkout action
|
||||
uses: actions/checkout@v3
|
||||
|
||||
# 步骤 1: 缓存 Rust 工具链和 Cargo 相关文件
|
||||
- name: Cache Rust and mdBook artifacts
|
||||
uses: actions/cache@v4 # 使用 actions/cache Action
|
||||
with:
|
||||
path: | # 需要缓存的路径
|
||||
~/.cargo/registry # Cargo 的包注册表缓存
|
||||
~/.cargo/git # Cargo 的 Git 依赖缓存
|
||||
~/.cargo/bin # Cargo 安装的二进制文件(mdBook 会在这里)
|
||||
~/.rustup # Rustup 工具链本身的安装目录
|
||||
key: ${{ runner.os }}-rust-${{ hashFiles('book.toml') }}-${{ hashFiles('.gitea/workflows/build-and-deploy-docs.yml') }} # 缓存键
|
||||
# 缓存键的含义:
|
||||
# - ${{ runner.os }}: 操作系统类型(如 Ubuntu),确保不同 OS 的缓存隔离
|
||||
# - rust-: 固定前缀
|
||||
# - ${{ hashFiles('book.toml') }}: 如果 book.toml 文件内容变化,缓存失效(例如 mdBook 配置或版本变更)
|
||||
# - ${{ hashFiles('.gitea/workflows/build-and-deploy-docs.yml') }}: 如果 workflow 文件本身变化,缓存失效(例如 Rust toolchain 版本变化或 mdBook 安装方式变化)
|
||||
restore-keys:
|
||||
| # 恢复键(当主键不匹配时,尝试恢复更旧的、不那么精确的缓存)
|
||||
${{ runner.os }}-rust-${{ hashFiles('book.toml') }}
|
||||
${{ runner.os }}-rust-
|
||||
|
||||
# 步骤 2: 设置 Rust 工具链
|
||||
- name: Setup Rust toolchain
|
||||
uses: actions-rs/toolchain@v1 # 使用 actions-rs/toolchain 来安装 Rust
|
||||
with:
|
||||
toolchain: stable # 安装稳定版 Rust
|
||||
profile: minimal # 安装最小化配置文件,只包含 cargo 和 rustc,下载更快
|
||||
override: true # 确保这个 Rust 版本被设置为默认
|
||||
|
||||
# 步骤 3: 有条件地安装 mdBook (如果缓存未命中)
|
||||
- name: Install mdBook
|
||||
run: |
|
||||
# 检查 mdbook 是否已经安装在 PATH 中 (通过缓存恢复)
|
||||
if ! command -v mdbook &> /dev/null
|
||||
then
|
||||
echo "mdBook not found or not in PATH, installing..."
|
||||
cargo install mdbook --locked --no-default-features
|
||||
else
|
||||
echo "mdBook already installed (from cache or previous step), skipping installation."
|
||||
fi
|
||||
uses: peaceiris/actions-mdbook@v1
|
||||
with:
|
||||
mdbook-version: "latest"
|
||||
|
||||
- name: Build mdBook
|
||||
run: mdbook build # 构建文档到默认的 'book' 目录
|
||||
run: mdbook build
|
||||
|
||||
- name: Deploy to Gitea Pages
|
||||
# 部署步骤变得无比简单!
|
||||
- name: Deploy to Gitea Pages Directory
|
||||
run: |
|
||||
# 确保 Gitea Runner 运行用户拥有 /root/gitea/gitea/data/pages/ 的写入权限
|
||||
sudo rm -rf /root/gitea/gitea/data/pages/dao-os/dao-os-docs/*
|
||||
sudo cp -r book/* /root/gitea/gitea/data/pages/dao-os/dao-os-docs/
|
||||
env:
|
||||
# 如果你的 Gitea Runner 需要特定权限来写入 pages 目录,这里需要配置
|
||||
# 例如:GITEA_SSH_KEY: ${{ secrets.GITEA_SSH_KEY }}
|
||||
# 具体取决于你的 Gitea Runner 如何与 Pages 目录进行权限交互。
|
||||
# 对于自建的 Gitea Actions Runner,你需要确保运行它的用户对 /root/gitea/gitea/data/pages 具有写入权限。
|
||||
# 这是我们挂载到容器内的路径,后面拼接上你的项目路径
|
||||
TARGET_DIR="/mnt/gitea-pages/dao-os/dao-os-docs"
|
||||
|
||||
echo "🚀 Deploying to host via volume mount..."
|
||||
|
||||
# 确保目标目录存在
|
||||
mkdir -p "$TARGET_DIR"
|
||||
|
||||
# 使用 rsync 进行高效、安全的本地文件同步
|
||||
# 它比 cp -r 更好,因为它只会同步有变化的文件,并且有 --delete 选项
|
||||
rsync -a --delete ./book/ "$TARGET_DIR/"
|
||||
|
||||
echo "✅ Deployment successful!"
|
||||
|
||||
Reference in New Issue
Block a user