also add a screenshot script
[xonotic/xonotic.git] / misc / tools / xonotic-map-compiler-autobuild
1 #!/bin/sh
2
3 set -e
4
5 bspdir="$PWD/data"
6 url=http://beta.xonotic.org/autobuild-bsp/
7 url_ssh=xonotic-beta:autobuild-bsp/
8 build_cachedir="$HOME/xonotic-map-compiler.cache/"
9 screenshot_cachedir="$HOME/xonotic-map-screenshot.cache/"
10 build_override="-bsp_timeout 900 -vis_timeout 3600 -light_timeout 14400 -minimap_timeout 900 -scale_timeout 900"
11 screenshot_override="9 300"
12
13 allmaps()
14 {
15         for F in maps/*.map.options; do
16                 if ! [ -f "$F" ]; then
17                         continue
18                 fi
19                 if ! [ -f "${F%.options}" ]; then
20                         continue
21                 fi
22                 M=${F#maps/}
23                 M=${M%.map.options}
24                 blobhash=`git ls-files -s -- "$F" | cut -d ' ' -f 2`-`git ls-files -s -- "${F%.options}" | cut -d ' ' -f 2`
25                 "$@" "$M" "$blobhash"
26         done
27 }
28
29 pre2spam()
30 {
31         map=$1
32         url=$2
33         branch=$3
34         hash=$4
35
36         branch=${branch##refs/heads/}
37         branch=${branch##refs/remotes/}
38         branch=${branch##origin/}
39         hash=`echo "$hash" | cut -c 1-7`
40
41         echo "[$branch $hash] starting map compile of $map"
42 }
43
44 ss2spam()
45 {
46         map=$1
47         url=$2
48         branch=$3
49         hash=$4
50         status=$5
51
52         branch=${branch##refs/heads/}
53         branch=${branch##refs/remotes/}
54         branch=${branch##origin/}
55         hash=`echo "$hash" | cut -c 1-7`
56
57         s_error=
58
59         if [ "$status" -ne 0 ]; then
60                 s_error="exited with status $status"
61         fi
62
63         if [ -n "$s_error" ]; then
64                 echo "[$branch $hash] \ 34screenshots of $map could not be made: $s_error"
65         else
66                 echo "[$branch $hash] screenshots of $map are available on $url"
67         fi
68 }
69
70 log2spam()
71 {
72         map=$1
73         url=$2
74         branch=$3
75         hash=$4
76         status=$5
77         time=$6
78
79         hash=`echo "$hash" | cut -c 1-7`
80
81         branch=${branch##refs/heads/}
82         branch=${branch##refs/remotes/}
83         branch=${branch##origin/}
84
85         s_samplesize=
86         s_failshaders=
87         s_leaked=
88         s_error=
89
90         if [ "$status" -ne 0 ]; then
91                 s_error="exited with status $status"
92         fi
93         while IFS= read -r L; do
94                 case "$L" in
95                         WARNING:\ surface\ at\ *\ too\ large\ for\ desired\ samplesize*)
96                                 s=${L##* }
97                                 if [ -z "$s_samplesize" ] || [ "$s" -gt "$s_samplesize" ]; then
98                                         s_samplesize=$s
99                                 fi
100                                 ;;
101                         WARNING:\ Couldn\'t\ find\ image\ for\ shader\ textures/NULL)
102                                 # radiant stupid
103                                 ;;
104                         WARNING:\ Couldn\'t\ find\ image\ for\ shader\ *)
105                                 s_failshaders="$s_failshaders ${L##* }"
106                                 ;;
107                         '******* leaked *******')
108                                 s_leaked=1
109                                 ;;
110                         '************ ERROR ************')
111                                 IFS= read -r s_error
112                                 ;;
113                 esac
114         done
115         s_failshaders=`echo "$s_failshaders" | sed "s, textures/, ,g"`
116         s_failshaders=${s_failshaders# }
117         if [ -n "$s_error" ]; then
118                 echo -n "[$branch $hash] \ 34failed"
119         else
120                 echo -n "[$branch $hash] finished"
121         fi
122         echo -n " map compile of $map ($url): $time sec"
123         if [ -n "$s_samplesize" ]; then
124                 echo -n ", FIX samplesize >= $s_samplesize"
125         fi
126         if [ -n "$s_failshaders" ]; then
127                 if [ -n "`echo "$s_failshaders" | cut -d ' ' -f 4-`" ]; then
128                         s_failshaders="`echo "$s_failshaders" | cut -d ' ' -f 1-3`..."
129                 fi
130                 echo -n ", FIX shaders $s_failshaders"
131         fi
132         if [ -n "$s_leaked" ]; then
133                 echo -n ", FIX LEAK"
134         fi
135         if [ -n "$s_error" ]; then
136                 s_error=`echo "$s_error" | sed "s,$PWD/\?,,g"`
137                 echo -n ", ERROR: $s_error"
138         fi
139         echo
140 }
141
142 buildthemap()
143 {
144         REFNAME=$1
145         HASH=$2
146         url=$3
147         M=$4
148         blobhash=$5
149         if HEAD "$url$M-$blobhash.pk3"; then
150                 continue
151         fi
152         if [ -n "$IRCSPAM" ]; then
153                 pre2spam "$M" "$url$M-$blobhash.pk3" "$REFNAME" "$HASH" | $IRCSPAM
154         fi
155         t0=`date +%s`
156         (
157                 cd maps
158                 ../../../misc/tools/xonotic-map-compiler "$M" `grep ^- "$M.map.options" | cut -d '#' -f 1` $build_override > "$M.log"
159         )
160         t1=`date +%s`
161         dt=$(($t1 - $t0))
162         status=$?
163         if [ -n "$IRCSPAM" ]; then
164                 cat "maps/$M.log" | log2spam "$M" "$url$M-$blobhash.pk3" "$REFNAME" "$HASH" "$status" "$dt" > "maps/$M.irc"
165         fi
166         zip -9r "$M-$blobhash.pk3" "maps/$M.bsp" "maps/$M.log" "maps/$M.irc" "maps/$M/" "maps/$M.lin" "gfx/${M}_mini.tga"
167         ln -snf "../$M-$blobhash.pk3" "$M.pk3" # from ALL branches, so beware!
168         cp "$M-$blobhash.pk3" "$M-full-$blobhash.pk3"
169         zip -9r "$M-full-$blobhash.pk3" `git diff --name-only --diff-filter=ACMRTUXB master...HEAD` || true
170         ln -snf "../$M-full-$blobhash.pk3" "$M-full.pk3" # from ALL branches, so beware!
171         rsync -vaSHP "$M-$blobhash.pk3" "$M-full-$blobhash.pk3" "$url_ssh"
172         rsync -vaSHP "$M.pk3" "$M-full.pk3" "$url_ssh""latest/"
173         if [ -n "$IRCSPAM" ]; then
174                 $IRCSPAM < "maps/$M.irc"
175         fi
176 }
177
178 screenshotthemap()
179 {
180         REFNAME=$1
181         HASH=$2
182         url=$3
183         M=$4
184         blobhash=$5
185         if HEAD "$url$M-$blobhash/"; then
186                 continue
187         fi
188         rm -rf ~/.xonotic
189         (
190                 ../../misc/tools/xonotic-map-screenshot "$M" $screenshot_override +scr_screenshot_name "$M"
191         )
192         if ! mv ~/.xonotic/data/screenshots "$M-$blobhash"; then
193                 if [ -n "$IRCSPAM" ]; then
194                         ss2spam "$M" "$url$M-$blobhash/" "$REFNAME" "$HASH" > "maps/$M.ircss"
195                 fi
196                 return 1
197         fi
198         if [ -n "$IRCSPAM" ]; then
199                 ss2spam "$M" "$url$M-$blobhash/" "$REFNAME" "$HASH" > "maps/$M.ircss"
200         fi
201         mv ~/.xonotic/data/screenshots "$M-$blobhash"
202         ln -snf "../$M-$blobhash" "$M" # from ALL branches, so beware!
203         rsync -vaSHP "$M-$blobhash" "$url_ssh"
204         rsync -vaSHP "$M" "$url_ssh""latest/"
205         if [ -n "$IRCSPAM" ]; then
206                 $IRCSPAM < "maps/$M.ircss"
207         fi
208 }
209
210 getthemap()
211 {
212         url=$1
213         bspdir_old=$2
214         bspdir=$3
215         M=$4
216         blobhash=$5
217         if mv "$bspdir_old/$M-$blobhash.pk3" "$bspdir/$M-$blobhash.pk3"; then
218                 continue
219         fi
220         if ! wget -O "$bspdir/$M-$blobhash.pk3" "$url$M-$blobhash.pk3"; then
221                 if ! curl -o "$bspdir/$M-$blobhash.pk3" "$url$M-$blobhash.pk3"; then
222                         rm -f "$bspdir/$M-$blobhash.pk3"
223                         echo "WARNING: could not download $url$M-$blobhash.pk3, maybe not ready yet"
224                         return 0
225                 fi
226         fi
227         if ! unzip -l "$bspdir/$M-$blobhash.pk3"; then
228                 rm -f "$bspdir/$M-$blobhash.pk3"
229                 echo "WARNING: could not download $url$M-$blobhash.pk3, invalid zip file"
230                 return 0
231         fi
232 }
233
234 case "$1" in
235         build)
236                 cd data/xonotic-maps.pk3dir
237                 git for-each-ref 'refs/remotes' | while read -r HASH TYPE REFNAME; do
238                         if [ -f "$build_cachedir/$HASH" ]; then
239                                 continue
240                         fi
241                         git reset --hard
242                         git clean -xfd
243                         git checkout -f "$HASH"
244                         allmaps buildthemap "$REFNAME" "$HASH" "$url"
245                         touch "$build_cachedir/$HASH"
246                 done
247                 git checkout -f master
248                 ;;
249         screenshot)
250                 cd data/xonotic-maps.pk3dir
251                 git for-each-ref 'refs/remotes' | while read -r HASH TYPE REFNAME; do
252                         if [ -f "$screenshot_cachedir/$HASH" ]; then
253                                 continue
254                         fi
255                         git reset --hard
256                         git clean -xfd
257                         git checkout -f "$HASH"
258                         allmaps screenshotthemap "$REFNAME" "$HASH" "$url"
259                         touch "$screenshot_cachedir/$HASH"
260                 done
261                 git checkout -f master
262                 ;;
263         download)
264                 mkdir -p "$bspdir" "$bspdir.old"
265                 for b in "$bspdir"/*-????????????????????????????????????????-????????????????????????????????????????.pk3; do
266                         if [ -e "$b" ]; then
267                                 mv "$b" "$bspdir.old"/
268                         fi
269                 done
270                 cd data/xonotic-maps.pk3dir
271                 allmaps getthemap "$url" "$bspdir.old" "$bspdir"
272                 echo "List of maps that got deleted (if any) and currently are in $bspdir.old:"
273                 ls -l "$bspdir.old"
274                 ;;
275         download-latest)
276                 mkdir -p "$bspdir"
277                 cd "$bspdir"
278                 rm -f *-????????????????????????????????????????-????????????????????????????????????????.pk3
279                 wget -r -l1 -A "*.pk3" -N --no-parent --no-directories "$url""latest"
280                 ;;
281         log2spam-test)
282                 log2spam "mapname" "http://mapurl" "branch" "commit" "0"
283                 ;;
284 esac