0febde397344478db6fe0c51ee5bfe5d10958914
[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         zip -9r "$bspdir/$M-$blobhash.pk3" "maps/$M.bsp" "maps/$M.log" "maps/$M/" "maps/$M.lin" "gfx/${M}_mini.tga"
134         ln -snf "../$M-$blobhash.pk3" "$bspdir/latest/$M.pk3" # from ALL branches, so beware!
135         if [ -n "$IRCSPAM" ]; then
136                 cat "maps/$M.log" | log2spam "$M" "$url$M-$blobhash.pk3" "$REFNAME" "$HASH" "$status" | $IRCSPAM
137         fi
138 }
139
140 getthemap()
141 {
142         url=$1
143         bspdir_old=$2
144         bspdir=$3
145         M=$4
146         blobhash=$5
147         if mv "$bspdir_old/$M-$blobhash.pk3" "$bspdir/$M-$blobhash.pk3"; then
148                 continue
149         fi
150         if ! wget -O "$bspdir/$M-$blobhash.pk3" "$url$M-$blobhash.pk3"; then
151                 rm -f "$bspdir/$M-$blobhash.pk3"
152                 echo "WARNING: could not download $url$M-$blobhash.pk3, maybe not ready yet"
153                 return 1
154         fi
155         if ! unzip -l "$bspdir/$M-$blobhash.pk3"; then
156                 rm -f "$bspdir/$M-$blobhash.pk3"
157                 echo "WARNING: could not download $url$M-$blobhash.pk3, invalid zip file"
158                 return 1
159         fi
160 }
161
162 case "$1" in
163         build)
164                 mkdir -p "$bspoutdir"
165                 mkdir -p "$bspoutdir/latest"
166                 cd data/xonotic-maps.pk3dir
167                 git for-each-ref 'refs/remotes' | while read -r HASH TYPE REFNAME; do
168                         git reset --hard
169                         git clean -xfd
170                         git checkout "$HASH"
171                         allmaps buildthemap "$REFNAME" "$HASH" "$url" "$bspoutdir"
172                 done
173                 git checkout master
174                 ;;
175         download)
176                 mkdir -p "$bspdir" "$bspdir.old"
177                 mv "$bspdir"/*-????????????????????????????????????????-????????????????????????????????????????.pk3 "$bspdir.old"/ || true
178                 cd data/xonotic-maps.pk3dir
179                 allmaps getthemap "$url" "$bspdir.old" "$bspdir"
180                 echo "List of maps that got deleted (if any) and currently are in $bspdir.old:"
181                 ls -l "$bspdir.old"
182                 ;;
183         download-latest)
184                 mkdir -p "$bspdir"
185                 cd "$bspdir"
186                 rm -f *-????????????????????????????????????????-????????????????????????????????????????.pk3
187                 wget -r -l1 -A "*.pk3" -N --no-parent --no-directories "$url""latest"
188                 ;;
189         log2spam-test)
190                 log2spam "mapname" "http://mapurl" "branch" "commit" "0"
191                 ;;
192 esac