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