-
Notifications
You must be signed in to change notification settings - Fork 2
171 lines (151 loc) · 5.46 KB
/
Copy pathbuild-and-deploy.yml
File metadata and controls
171 lines (151 loc) · 5.46 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
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
container:
image: manimcommunity/manim:latest
options: --user root
env:
PATH: /opt/conda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Install dependencies
run: |
pip install 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 video cache
uses: actions/cache@v4
with:
path: .video-cache
key: videos-${{ hashFiles('Chapter**/Scene*.py', 'Chapter**/Thumb.py', 'scene_utils/**/*.py', 'imgs/**', 'manim.cfg') }}
restore-keys: 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
# 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 that have cache misses
REBUILD=""
for N in 0 1 2 3 4 5 6 7 8 9; do
CHAPTER="Chapter${N}"
if [ ! -f ".video-cache/${CHAPTER}_480p15.mp4" ] || [ ! -f ".video-cache/${CHAPTER}.png" ]; then
if [ -d "$CHAPTER" ]; then
REBUILD="${REBUILD:+${REBUILD},}${N}"
fi
fi
done
echo "rebuild=${REBUILD}" >> "$GITHUB_OUTPUT"
fi
- name: Build chapters
env:
ELEVEN_API_KEY: ${{ secrets.ELEVEN_API_KEY }}
run: |
REBUILD="${{ steps.chapters.outputs.rebuild }}"
echo "Chapters to rebuild: ${REBUILD:-none}"
# Copy cached videos for chapters we are NOT rebuilding
for N in 0 1 2 3 4 5 6 7 8 9; do
CHAPTER="Chapter${N}"
if [ -f ".video-cache/${CHAPTER}_480p15.mp4" ] && [ -f ".video-cache/${CHAPTER}.png" ]; then
echo "Using cached video for ${CHAPTER}"
cp ".video-cache/${CHAPTER}_480p15.mp4" "docs/${CHAPTER}_480p15.mp4"
cp ".video-cache/${CHAPTER}.png" "docs/${CHAPTER}.png"
fi
done
# 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" ".video-cache/${CHAPTER}_480p15.mp4"
cp "docs/${CHAPTER}.png" ".video-cache/${CHAPTER}.png"
echo "${CHAPTER} complete"
done
fi
- name: Build MkDocs site
run: mkdocs build
- 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