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