-
Notifications
You must be signed in to change notification settings - Fork 5
/
entrypoint.sh
153 lines (131 loc) · 3 KB
/
entrypoint.sh
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
#!/bin/bash
set -e
info() {
echo -e "\033[1;34m$1\033[0m"
}
warn() {
echo "::warning :: $1"
}
error() {
echo "::error :: $1"
exit 1
}
source_file="${1}"
scene_names="${2}"
args="${3}"
manim_repo="${4}"
extra_packages="${5}"
extra_system_packages="${6}"
pre_render="${7}"
post_render="${8}"
merge_assets="${9}"
fonts_dir="${10}"
extra_repos="${11}"
community="${12}"
if [[ "$manim_repo" == "https://github.com/ManimCommunity/manim" || "$manim_repo" == "https://github.com/ManimCommunity/manim/" ]]; then
community=true
fi
echo "Community? $community"
if [[ -z "$source_file" ]]; then
error "Input 'source_file' is missing."
fi
if [[ -n $fonts_dir ]]; then
info "Adding fonts..."
cp -r "$fonts_dir" /usr/share/fonts/custom
ls /usr/share/fonts/custom
apt install fontconfig -y
mkfontscale
mkfontdir
fc-cache -fv
fi
info "Cloning $manim_repo ..."
if [[ $community == true ]]; then
git clone "$manim_repo" manimcm --depth=1
else
git clone "$manim_repo" manim --depth=1
fi
merge() {
if [[ -e $1 && -e $2 ]]; then
for i in $(ls $2); do
if [[ -e "$1$i" ]]; then
if [[ -d "$1$i" ]]; then
merge "$1$i/" "$2$i/"
fi
else
mv "$2$i" "$1$i"
fi
done
rm -rf "$2"
fi
}
if [[ $merge_assets == true && $community == false ]]; then
merge "assets/" "manim/assets/"
fi
if [[ $community == true ]]; then
mv manimcm/* .
else
mv manim/* .
fi
info "Installing requirements of manim..."
if [[ community == true ]]; then
python -m pip install -e .
else
python -m pip install -r requirements.txt
fi
if [[ -n "$extra_system_packages" ]]; then
for pkg in $extra_system_packages; do
info "Installing $pkg by apk..."
apk --no-cache add "$pkg"
done
fi
if [[ -n "$extra_packages" ]]; then
for pkg in $extra_packages; do
info "Installing $pkg by pip..."
python -m pip install "$pkg"
done
fi
if [[ -n "$extra_repos" ]]; then
for repo in $extra_repos; do
info "Cloning $repo by git..."
git clone "$repo" --depth=1
done
fi
if [[ -n "$pre_render" ]]; then
info "Run pre compile commands"
eval "$pre_render"
fi
info "Rendering..."
if [[ $community == true ]]; then
for sce in $scene_names; do
python -m manim "$source_file" $sce ${args[@]}
if [ $? -ne 0 ]; then
error "manim render error"
fi
done
else
for sce in $scene_names; do
python manim.py "$source_file" $sce ${args[@]}
if [ $? -ne 0 ]; then
error "manim render error"
fi
done
fi
if [[ -n "$post_render" ]]; then
info "Run post compile commands"
eval "$post_render"
fi
info "Searching outputs..."
cnt=0
videos_path="/github/workspace/media/videos/"
for sce in $scene_names; do
video=$(find ${videos_path} -name "${sce}.mp4" -o -name "${sce}.mov" -o -name "${sce}.png")
output[$cnt]=$video
cnt=$cnt+1
done
mkdir /github/workspace/outputs
for file in ${output[@]}; do
cp $file "/github/workspace/outputs/"
done
echo "All ${#output[@]} outputs: ${output[@]}"
ls /github/workspace/outputs
echo "::set-output name=video_path::./outputs/*"