forked from godotengine/godot-docs
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·126 lines (115 loc) · 4.02 KB
/
build.sh
File metadata and controls
executable file
·126 lines (115 loc) · 4.02 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/bash
#
# Redot Documentation Build Script
# Builds documentation and outputs to /output for Cloudflare Pages
#
# Usage:
# FULL_RUN=1 ./build.sh # Full build
# ./build.sh # Skip build (for testing)
#
# Environment Variables:
# FULL_RUN - Set to enable full documentation build
# CF_PAGES - Automatically set by Cloudflare Pages
# CF_PAGES_BRANCH - Branch being built (set by Cloudflare Pages)
# BUILD_DIR - Override the output directory name (e.g., "4.3", "4.4", "dev")
set -e # Exit on error
# Configuration
inputDir="."
migrateDir="_migrated"
sphinxDir="_sphinx"
# Determine output directory based on branch
gitBranch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "master")
if [ -n "$CF_PAGES" ]; then
echo "Building on Cloudflare Pages"
gitBranch="${CF_PAGES_BRANCH:-master}"
fi
# Map branches to output directories
# master -> latest, everything else -> branch name
# Allow BUILD_DIR override for versioned builds
if [ -n "$BUILD_DIR" ]; then
buildDir="$BUILD_DIR"
elif [ -n "$CF_PAGES" ]; then
buildDir="${CF_PAGES_BRANCH:-master}"
if [ "$buildDir" = "master" ]; then
buildDir="latest"
fi
else
buildDir="$gitBranch"
if [ "$buildDir" = "master" ]; then
buildDir="latest"
fi
fi
echo "========================================"
echo "Redot Documentation Build"
echo "========================================"
echo "Branch: $gitBranch"
echo "Output: html/en/$buildDir"
echo "Date: $(date)"
echo "========================================"
# Clean and prepare directories
# Skip migration if _migrated exists (for faster rebuilds)
echo ""
echo "[1/4] Preparing build directories..."
rm -rf "$sphinxDir"
mkdir -p "$sphinxDir"
# Full build (only if FULL_RUN is set)
if [ -n "$FULL_RUN" ]; then
# Check if migration is needed
if [ -d "$migrateDir" ] && [ -f "$migrateDir/index.rst" ]; then
echo ""
echo "[2/4] Using existing migrated files (skipping migration)..."
else
echo ""
echo "[2/4] Migrating Godot to Redot (with --exclude-classes)..."
rm -rf "$migrateDir"
mkdir -p "$migrateDir"
# Check if we're building from upstream branch (doesn't support --exclude-classes)
# by checking if BUILD_DIR is set (our feature branch sets it, upstream builds won't)
if [ -n "$BUILD_DIR" ] && [ "$gitBranch" != "HEAD" ]; then
# Our branch with new migrate.py - use --exclude-classes
python migrate.py --exclude-classes "$inputDir" "$migrateDir"
else
# Upstream branch - old migrate.py, don't use --exclude-classes
python migrate.py "$inputDir" "$migrateDir"
fi
fi
echo ""
echo "[3/4] Building HTML documentation with Sphinx..."
# Use -j 4 for consistent performance
# Use -d for doctree caching (enables incremental builds)
mkdir -p "$sphinxDir/.doctrees"
sphinx-build -b html \
-j 4 \
-d "$sphinxDir/.doctrees" \
--color \
"$migrateDir" \
"$sphinxDir"
echo ""
echo "[4/4] Copying build output..."
# Cloudflare Pages serves from /output
# Build triggered: $(date)
outputDir="output/html/en/$buildDir"
mkdir -p "$outputDir"
cp -r "$sphinxDir"/* "$outputDir/"
echo ""
echo "========================================"
echo "Build Complete!"
echo "Output: $outputDir"
echo "========================================"
else
echo ""
echo "[2/4] Skipping migration and build (FULL_RUN not set)"
echo ""
echo "[3/4] Creating placeholder output..."
mkdir -p "output/html/en/$buildDir"
echo "Build skipped. Set FULL_RUN=1 to build documentation." > "output/html/en/$buildDir/index.html"
echo ""
echo "[4/4] Done (placeholder only)"
echo ""
echo "========================================"
echo "Build Skipped (FULL_RUN not set)"
echo "========================================"
fi
echo ""
echo "Build script finished successfully"
echo "Build completed at $(date)"