-
Notifications
You must be signed in to change notification settings - Fork 10
59 lines (48 loc) · 1.84 KB
/
deploy.yml
File metadata and controls
59 lines (48 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
name: Auto Deploy GitBook
on:
push:
branches: [ main, master ]
workflow_dispatch: # 允许手动触发
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: Build and Deploy GitBook
run: |
# 创建临时目录
tmpdir=$(mktemp -d)
builddir=$(mktemp -d)
# 清理函数
cleanup() {
rm -rf "$tmpdir" 2>/dev/null || true
rm -rf "$builddir" 2>/dev/null || true
}
trap cleanup EXIT
echo "🚀 Starting GitBook build and deployment..."
# 克隆目标仓库(使用带token的HTTPS URL)
echo "📥 Cloning target repository..."
git clone --depth 1 https://${{ secrets.DEPLOY_TOKEN }}@github.com/hitzhangjie/debugger101.io $tmpdir
# 使用Docker构建GitBook
echo "🔨 Building GitBook with Docker..."
docker run --name gitbook --rm \
-v ${PWD}:/root/gitbook \
-v $builddir:$builddir \
hitzhangjie/gitbook-cli:latest \
bash -c "cd book && gitbook install && cd - && gitbook build book $builddir"
# 复制构建结果到目标目录
echo "📋 Copying build results..."
cp -rf $builddir/* $tmpdir/
# 提交更改
echo "💾 Committing changes..."
cd $tmpdir
git config --local user.name "hitzhangjie"
git config --local user.email "hit.zhangjie@gmail.com"
git add .
git commit -m "Auto-deploy: $(date)"
# 使用 URL 重写方式推送,避免写入凭证文件
git remote set-url origin https://${{ secrets.DEPLOY_TOKEN }}@github.com/hitzhangjie/debugger101.io
git push -f -u origin master
cd -
echo "✅ Deployment completed successfully!"