also do a pre-compile irc notification for map compiles
[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
8 bspoutdir="$HOME/public_html/bsp-autobuilds/"
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
48         branch=${branch##refs/heads/}
49         branch=${branch##refs/remotes/}
50         branch=${branch##origin/}
51
52         s_time=
53         s_samplesize=
54         s_failshaders=
55         s_leaked=
56         s_error=
57
58         while IFS= read -r L; do
59                 case "$L" in
60                         *\ seconds\ elapsed)
61                                 s_time=$(($s_time + ${L%% seconds elapsed}))
62                                 ;;
63                         WARNING:\ surface\ at\ *\ too\ large\ for\ desired\ samplesize*)
64                                 s=${L##* }
65                                 if [ -z "$s_samplesize" ] || [ "$s" -gt "$s_samplesize" ]; then
66                                         s_samplesize=$s
67                                 fi
68                                 ;;
69                         WARNING:\ Couldn\'t\ find\ image\ for\ shader\ textures/NULL)
70                                 # radiant stupid
71                                 ;;
72                         WARNING:\ Couldn\'t\ find\ image\ for\ shader\ *)
73                                 s_failshaders="$s_failshaders ${L##* }"
74                                 ;;
75                         '******* leaked *******')
76                                 s_leaked=1
77                                 ;;
78                         '************ ERROR ************')
79                                 IFS= read -r s_error
80                                 ;;
81                 esac
82         done
83         s_failshaders=`echo "$s_failshaders" | sed "s, textures/, ,g"`
84         s_failshaders=${s_failshaders# }
85         if [ -n "$s_error" ]; then
86                 echo -n "[$branch $hash] \ 34failed"
87         else
88                 echo -n "[$branch] finished"
89         fi
90         echo -n " map compile of $map ($url): $s_time sec"
91         if [ -n "$s_samplesize" ]; then
92                 echo -n ", FIX samplesize >= $s_samplesize"
93         fi
94         if [ -n "$s_failshaders" ]; then
95                 if [ -n "`echo "$s_failshaders" | cut -d ' ' -f 4-`" ]; then
96                         s_failshaders="`echo "$s_failshaders" | cut -d ' ' -f 1-3`..."
97                 fi
98                 echo -n ", FIX shaders $s_failshaders"
99         fi
100         if [ -n "$s_leaked" ]; then
101                 echo -n ", FIX LEAK"
102         fi
103         if [ -n "$s_error" ]; then
104                 s_error=`echo "$s_error" | sed "s,$PWD/\?,,g"`
105                 echo -n ", ERROR: $s_error"
106         fi
107         echo
108 }
109
110 buildthemap()
111 {
112         REFNAME=$1
113         HASH=$2
114         url=$3
115         bspdir=$4
116         M=$5
117         blobhash=$6
118         if [ -f "$bspdir/$M-$blobhash.pk3" ]; then
119                 continue
120         fi
121         if [ -n "$IRCSPAM" ]; then
122                 pre2spam "$M" "$url$M-$blobhash.pk3" "$REFNAME" "$HASH" | $IRCSPAM
123         fi
124         (
125                 cd maps
126                 ../../../misc/tools/xonotic-map-compiler "$M" `head -n 1 "$M.map.options"` 2>&1 | tee "$M.log"
127         )
128         zip -9r "$bspdir/$M-$blobhash.pk3" "maps/$M.bsp" "maps/$M.log" "maps/$M/" "maps/$M.lin" "gfx/${M}_mini.tga"
129         ln -snf "../$M-$blobhash.pk3" "$bspdir/latest/$M.pk3" # from ALL branches, so beware!
130         if [ -n "$IRCSPAM" ]; then
131                 cat "maps/$M.log" | log2spam "$M" "$url$M-$blobhash.pk3" "$REFNAME" "$HASH" | $IRCSPAM
132         fi
133 }
134
135 getthemap()
136 {
137         url=$1
138         bspdir_old=$2
139         bspdir=$3
140         M=$4
141         blobhash=$5
142         if mv "$bspdir_old/$M-$blobhash.pk3" "$bspdir/$M-$blobhash.pk3"; then
143                 continue
144         fi
145         if ! wget -O "$bspdir/$M-$blobhash.pk3" "$url$M-$blobhash.pk3"; then
146                 rm -f "$bspdir/$M-$blobhash.pk3"
147                 echo "WARNING: could not download $url$M-$blobhash.pk3, maybe not ready yet"
148                 return 1
149         fi
150         if ! unzip -l "$bspdir/$M-$blobhash.pk3"; then
151                 rm -f "$bspdir/$M-$blobhash.pk3"
152                 echo "WARNING: could not download $url$M-$blobhash.pk3, invalid zip file"
153                 return 1
154         fi
155 }
156
157 case "$1" in
158         build)
159                 mkdir -p "$bspoutdir"
160                 mkdir -p "$bspoutdir/latest"
161                 cd data/xonotic-maps.pk3dir
162                 git for-each-ref 'refs/remotes' | while read -r HASH TYPE REFNAME; do
163                         git reset --hard
164                         git clean -xfd
165                         git checkout "$HASH"
166                         allmaps buildthemap "$REFNAME" "$HASH" "$url" "$bspoutdir"
167                 done
168                 git checkout master
169                 ;;
170         download)
171                 mkdir -p "$bspdir" "$bspdir.old"
172                 mv "$bspdir"/*-????????????????????????????????????????-????????????????????????????????????????.pk3 "$bspdir.old"/ || true
173                 cd data/xonotic-maps.pk3dir
174                 allmaps getthemap "$url" "$bspdir.old" "$bspdir"
175                 echo "List of maps that got deleted (if any) and currently are in $bspdir.old:"
176                 ls -l "$bspdir.old"
177                 ;;
178         download-latest)
179                 mkdir -p "$bspdir"
180                 cd "$bspdir"
181                 rm -f *-????????????????????????????????????????-????????????????????????????????????????.pk3
182                 wget -r -l1 -A "*.pk3" -N --no-parent --no-directories "$url""latest"
183                 ;;
184         log2spam-test)
185                 log2spam "mapname" "http://mapurl" "branch" "commit"
186                 ;;
187 esac