313827dfc0d24887af3830c0d25f5b9a36f7f9f8
[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=beta.xonotic.org:autobuild-bsp/
8 override="-bsp_timeout 900 -vis_timeout 3600 -light_timeout 14400 -minimap_timeout 900 -scale_timeout 900"
9
10 allmaps()
11 {
12         for F in maps/*.map.options; do
13                 if ! [ -f "$F" ]; then
14                         continue
15                 fi
16                 if ! [ -f "${F%.options}" ]; then
17                         continue
18                 fi
19                 M=${F#maps/}
20                 M=${M%.map.options}
21                 blobhash=`git ls-files -s -- "$F" | cut -d ' ' -f 2`-`git ls-files -s -- "${F%.options}" | cut -d ' ' -f 2`
22                 "$@" "$M" "$blobhash"
23         done
24 }
25
26 pre2spam()
27 {
28         map=$1
29         url=$2
30         branch=$3
31         hash=$4
32
33         branch=${branch##refs/heads/}
34         branch=${branch##refs/remotes/}
35         branch=${branch##origin/}
36         hash=`echo "$hash" | cut -c 1-7`
37
38         echo "[$branch $hash] starting map compile of $map"
39 }
40
41 log2spam()
42 {
43         map=$1
44         url=$2
45         branch=$3
46         hash=$4
47         status=$5
48         time=$6
49
50         hash=`echo "$hash" | cut -c 1-7`
51
52         branch=${branch##refs/heads/}
53         branch=${branch##refs/remotes/}
54         branch=${branch##origin/}
55
56         s_samplesize=
57         s_failshaders=
58         s_leaked=
59         s_error=
60
61         if [ "$status" -ne 0 ]; then
62                 s_error="exited with status $status"
63         fi
64         while IFS= read -r L; do
65                 case "$L" in
66                         WARNING:\ surface\ at\ *\ too\ large\ for\ desired\ samplesize*)
67                                 s=${L##* }
68                                 if [ -z "$s_samplesize" ] || [ "$s" -gt "$s_samplesize" ]; then
69                                         s_samplesize=$s
70                                 fi
71                                 ;;
72                         WARNING:\ Couldn\'t\ find\ image\ for\ shader\ textures/NULL)
73                                 # radiant stupid
74                                 ;;
75                         WARNING:\ Couldn\'t\ find\ image\ for\ shader\ *)
76                                 s_failshaders="$s_failshaders ${L##* }"
77                                 ;;
78                         '******* leaked *******')
79                                 s_leaked=1
80                                 ;;
81                         '************ ERROR ************')
82                                 IFS= read -r s_error
83                                 ;;
84                 esac
85         done
86         s_failshaders=`echo "$s_failshaders" | sed "s, textures/, ,g"`
87         s_failshaders=${s_failshaders# }
88         if [ -n "$s_error" ]; then
89                 echo -n "[$branch $hash] \ 34failed"
90         else
91                 echo -n "[$branch $hash] finished"
92         fi
93         echo -n " map compile of $map ($url): $time sec"
94         if [ -n "$s_samplesize" ]; then
95                 echo -n ", FIX samplesize >= $s_samplesize"
96         fi
97         if [ -n "$s_failshaders" ]; then
98                 if [ -n "`echo "$s_failshaders" | cut -d ' ' -f 4-`" ]; then
99                         s_failshaders="`echo "$s_failshaders" | cut -d ' ' -f 1-3`..."
100                 fi
101                 echo -n ", FIX shaders $s_failshaders"
102         fi
103         if [ -n "$s_leaked" ]; then
104                 echo -n ", FIX LEAK"
105         fi
106         if [ -n "$s_error" ]; then
107                 s_error=`echo "$s_error" | sed "s,$PWD/\?,,g"`
108                 echo -n ", ERROR: $s_error"
109         fi
110         echo
111 }
112
113 buildthemap()
114 {
115         REFNAME=$1
116         HASH=$2
117         url=$3
118         bspdir=$4
119         M=$5
120         blobhash=$6
121         if [ -f "$bspdir/$M-$blobhash.pk3" ]; then
122                 continue
123         fi
124         if [ -n "$IRCSPAM" ]; then
125                 pre2spam "$M" "$url$M-$blobhash.pk3" "$REFNAME" "$HASH" | $IRCSPAM
126         fi
127         t0=`date +%s`
128         (
129                 cd maps
130                 ../../../misc/tools/xonotic-map-compiler "$M" `grep ^- "$M.map.options" | cut -d '#' -f 1` $override > "$M.log"
131         )
132         t1=`date +%s`
133         dt=$(($t1 - $t0))
134         status=$?
135         if [ -n "$IRCSPAM" ]; then
136                 cat "maps/$M.log" | log2spam "$M" "$url$M-$blobhash.pk3" "$REFNAME" "$HASH" "$status" "$dt" > "maps/$M.irc"
137         fi
138         zip -9r "$M-$blobhash.pk3" "maps/$M.bsp" "maps/$M.log" "maps/$M.irc" "maps/$M/" "maps/$M.lin" "gfx/${M}_mini.tga"
139         ln -snf "../$M-$blobhash.pk3" "$M.pk3" # from ALL branches, so beware!
140         rsync -vaSHP "$M-$blobhash.pk3" "$url_ssh"
141         rsync -vaSHP "$M.pk3" "$url_ssh""latest/"
142         rm -f *.pk3
143         if [ -n "$IRCSPAM" ]; then
144                 $IRCSPAM < "maps/$M.irc"
145         fi
146 }
147
148 getthemap()
149 {
150         url=$1
151         bspdir_old=$2
152         bspdir=$3
153         M=$4
154         blobhash=$5
155         if mv "$bspdir_old/$M-$blobhash.pk3" "$bspdir/$M-$blobhash.pk3"; then
156                 continue
157         fi
158         if ! wget -O "$bspdir/$M-$blobhash.pk3" "$url$M-$blobhash.pk3"; then
159                 if ! curl -o "$bspdir/$M-$blobhash.pk3" "$url$M-$blobhash.pk3"; then
160                         rm -f "$bspdir/$M-$blobhash.pk3"
161                         echo "WARNING: could not download $url$M-$blobhash.pk3, maybe not ready yet"
162                         return 0
163                 fi
164         fi
165         if ! unzip -l "$bspdir/$M-$blobhash.pk3"; then
166                 rm -f "$bspdir/$M-$blobhash.pk3"
167                 echo "WARNING: could not download $url$M-$blobhash.pk3, invalid zip file"
168                 return 0
169         fi
170 }
171
172 case "$1" in
173         build)
174                 cd data/xonotic-maps.pk3dir
175                 git for-each-ref 'refs/remotes' | while read -r HASH TYPE REFNAME; do
176                         git reset --hard
177                         git clean -xfd
178                         git checkout -f "$HASH"
179                         allmaps buildthemap "$REFNAME" "$HASH" "$url" "$bspoutdir"
180                 done
181                 git checkout -f master
182                 ;;
183         download)
184                 mkdir -p "$bspdir" "$bspdir.old"
185                 for b in "$bspdir"/*-????????????????????????????????????????-????????????????????????????????????????.pk3; do
186                         if [ -e "$b" ]; then
187                                 mv "$b" "$bspdir.old"/
188                         fi
189                 done
190                 cd data/xonotic-maps.pk3dir
191                 allmaps getthemap "$url" "$bspdir.old" "$bspdir"
192                 echo "List of maps that got deleted (if any) and currently are in $bspdir.old:"
193                 ls -l "$bspdir.old"
194                 ;;
195         download-latest)
196                 mkdir -p "$bspdir"
197                 cd "$bspdir"
198                 rm -f *-????????????????????????????????????????-????????????????????????????????????????.pk3
199                 wget -r -l1 -A "*.pk3" -N --no-parent --no-directories "$url""latest"
200                 ;;
201         log2spam-test)
202                 log2spam "mapname" "http://mapurl" "branch" "commit" "0"
203                 ;;
204 esac