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