-
Notifications
You must be signed in to change notification settings - Fork 2
269 lines (237 loc) · 9.49 KB
/
build-and-deploy.yml
File metadata and controls
269 lines (237 loc) · 9.49 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
name: Build Videos and Deploy Site
on:
push:
branches: [main]
paths:
- '.github/workflows/**'
- 'Chapter*/**'
- 'scene_utils/**'
- 'imgs/**'
- 'docs/**/*.md'
- 'mkdocs.yml'
- 'manim.cfg'
- 'requirements.txt'
workflow_dispatch:
inputs:
chapters:
description: 'Chapters to rebuild (comma-separated, e.g. "0,3,5" or "all")'
required: false
default: 'all'
prod:
description: 'Use ElevenLabs TTS for production quality narration'
required: false
type: boolean
default: false
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: pages
cancel-in-progress: false
jobs:
build-and-deploy:
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y ffmpeg sox libcairo2-dev libpango1.0-dev \
texlive texlive-latex-extra texlive-fonts-extra
- name: Install Python dependencies
run: |
pip install 'setuptools<82'
pip install manim manim-voiceover[gtts] invoke python-graphblas \
networkx matplotlib python-dotenv \
mkdocs mkdocs-material pymdown-extensions
if [ "${{ inputs.prod }}" = "true" ]; then
pip install 'elevenlabs>=0.2.27,<0.3.0'
fi
- name: Restore dev video cache
uses: actions/cache@v4
with:
path: .video-cache/dev
key: dev-videos-${{ hashFiles('Chapter**/Scene*.py', 'Chapter**/Thumb.py', 'scene_utils/**/*.py', 'imgs/**', 'manim.cfg') }}
restore-keys: dev-videos-
- name: Restore prod video cache
uses: actions/cache@v4
with:
path: .video-cache/prod
key: prod-videos-${{ hashFiles('Chapter**/Scene*.py', 'Chapter**/Thumb.py', 'scene_utils/**/*.py', 'imgs/**', 'manim.cfg') }}
restore-keys: prod-videos-
- name: Restore voiceover cache
uses: actions/cache@v4
with:
path: |
Chapter0/media/voiceovers
Chapter1/media/voiceovers
Chapter2/media/voiceovers
Chapter3/media/voiceovers
Chapter4/media/voiceovers
Chapter5/media/voiceovers
Chapter6/media/voiceovers
Chapter7/media/voiceovers
Chapter8/media/voiceovers
Chapter9/media/voiceovers
key: voiceovers-${{ hashFiles('Chapter**/Scene*.py') }}
restore-keys: voiceovers-
- name: Determine chapters to build
id: chapters
run: |
mkdir -p .video-cache/dev .video-cache/prod
# Per-chapter source hash. A chapter is rebuilt when this hash differs
# from the .hash sidecar stored alongside the cached video. Inputs:
# the chapter's own scene/thumb sources plus shared files that affect
# every chapter (scene_utils, imgs, manim.cfg). The cache restore-keys
# fallback can resurrect stale videos, so existence-only checks are
# not sufficient — see commit 496d908 for the bug this guards against.
# NOTE: keep this function in sync with the copy in "Build chapters".
compute_chapter_hash() {
local chapter="$1"
{
find "$chapter" -maxdepth 1 -type f \( -name 'Scene*.py' -o -name 'Thumb.py' \) -print0 \
| sort -z | xargs -0 sha256sum
find scene_utils -type f -name '*.py' -print0 \
| sort -z | xargs -0 sha256sum
find imgs -type f -print0 \
| sort -z | xargs -0 sha256sum
sha256sum manim.cfg
} | sha256sum | awk '{print $1}'
}
# Determine build mode
if [ "${{ inputs.prod }}" = "true" ]; then
CACHE_DIR=".video-cache/prod"
else
CACHE_DIR=".video-cache/dev"
fi
# On workflow_dispatch, use the input
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
if [ "${{ inputs.chapters }}" = "all" ]; then
echo "rebuild=0,1,2,3,4,5,6,7,8,9" >> "$GITHUB_OUTPUT"
else
echo "rebuild=${{ inputs.chapters }}" >> "$GITHUB_OUTPUT"
fi
else
# On push, rebuild chapters whose source hash doesn't match the cached hash
REBUILD=""
for N in 0 1 2 3 4 5 6 7 8 9; do
CHAPTER="Chapter${N}"
[ -d "$CHAPTER" ] || continue
VIDEO="${CACHE_DIR}/${CHAPTER}_480p15.mp4"
THUMB="${CACHE_DIR}/${CHAPTER}.png"
HASHFILE="${CACHE_DIR}/${CHAPTER}.hash"
CURRENT_HASH=$(compute_chapter_hash "$CHAPTER")
if [ ! -f "$VIDEO" ] || [ ! -f "$THUMB" ] || [ ! -f "$HASHFILE" ]; then
echo "${CHAPTER}: rebuild (missing artifact)"
REBUILD="${REBUILD:+${REBUILD},}${N}"
elif [ "$(cat "$HASHFILE")" != "$CURRENT_HASH" ]; then
echo "${CHAPTER}: rebuild (source changed: $(cat "$HASHFILE") -> $CURRENT_HASH)"
REBUILD="${REBUILD:+${REBUILD},}${N}"
else
echo "${CHAPTER}: cache hit"
fi
done
echo "rebuild=${REBUILD}" >> "$GITHUB_OUTPUT"
fi
- name: Build chapters
env:
ELEVEN_API_KEY: ${{ secrets.ELEVEN_API_KEY }}
run: |
# NOTE: keep this function in sync with the copy in "Determine chapters to build".
compute_chapter_hash() {
local chapter="$1"
{
find "$chapter" -maxdepth 1 -type f \( -name 'Scene*.py' -o -name 'Thumb.py' \) -print0 \
| sort -z | xargs -0 sha256sum
find scene_utils -type f -name '*.py' -print0 \
| sort -z | xargs -0 sha256sum
find imgs -type f -print0 \
| sort -z | xargs -0 sha256sum
sha256sum manim.cfg
} | sha256sum | awk '{print $1}'
}
# Determine target cache directory
if [ "${{ inputs.prod }}" = "true" ]; then
CACHE_DIR=".video-cache/prod"
else
CACHE_DIR=".video-cache/dev"
fi
REBUILD="${{ steps.chapters.outputs.rebuild }}"
echo "Build mode: $([ "${{ inputs.prod }}" = "true" ] && echo "PROD" || echo "DEV")"
echo "Chapters to rebuild: ${REBUILD:-none}"
# Build chapters that need rebuilding
if [ -n "$REBUILD" ]; then
IFS=',' read -ra CHAPTERS <<< "$REBUILD"
for N in "${CHAPTERS[@]}"; do
N=$(echo "$N" | tr -d ' ')
CHAPTER="Chapter${N}"
if [ ! -d "$CHAPTER" ]; then
echo "Skipping ${CHAPTER} (directory not found)"
continue
fi
echo "=========================================="
echo "Building ${CHAPTER}"
echo "=========================================="
# Build and stitch the chapter
if [ "${{ inputs.prod }}" = "true" ]; then
invoke build-chapter --chapter "$CHAPTER" --quality l --pause-time 0 --prod
else
invoke build-chapter --chapter "$CHAPTER" --quality l --pause-time 0
fi
# Render thumbnail
cd "$CHAPTER"
manim -ql -s Thumb.py Thumb -o "../../../../docs/${CHAPTER}.png"
cd ..
# Cache the results
cp "docs/${CHAPTER}_480p15.mp4" "${CACHE_DIR}/${CHAPTER}_480p15.mp4"
cp "docs/${CHAPTER}.png" "${CACHE_DIR}/${CHAPTER}.png"
compute_chapter_hash "$CHAPTER" > "${CACHE_DIR}/${CHAPTER}.hash"
echo "${CHAPTER} complete"
done
fi
- name: Assemble and build site
run: |
# Step 1: Build prod site at root (if prod videos exist)
PROD_VIDEOS_EXIST=false
for N in 0 1 2 3 4 5 6 7 8 9; do
CHAPTER="Chapter${N}"
if [ -f ".video-cache/prod/${CHAPTER}_480p15.mp4" ]; then
cp ".video-cache/prod/${CHAPTER}_480p15.mp4" "docs/${CHAPTER}_480p15.mp4"
cp ".video-cache/prod/${CHAPTER}.png" "docs/${CHAPTER}.png"
PROD_VIDEOS_EXIST=true
fi
done
if [ "$PROD_VIDEOS_EXIST" = "true" ]; then
echo "Building prod site at root..."
mkdocs build -d site
else
echo "No prod videos cached yet. Building placeholder prod site..."
mkdocs build -d site
fi
# Step 2: Build dev site at /dev/
for N in 0 1 2 3 4 5 6 7 8 9; do
CHAPTER="Chapter${N}"
if [ -f ".video-cache/dev/${CHAPTER}_480p15.mp4" ]; then
cp ".video-cache/dev/${CHAPTER}_480p15.mp4" "docs/${CHAPTER}_480p15.mp4"
cp ".video-cache/dev/${CHAPTER}.png" "docs/${CHAPTER}.png"
fi
done
echo "Building dev site at /dev/..."
mkdocs build -d site/dev
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: site
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4