]> git.xonotic.org Git - xonotic/xonotic.git/blob - misc/tools/xonotic-map-compiler-autobuild
add an autoscreenshot method
[xonotic/xonotic.git] / misc / tools / xonotic-map-compiler-autobuild
1 #!/bin/sh
2
3 set -e
4
5 bspdir="$PWD/data"
6 url=http://beta.xonotic.org/autobuild-bsp/
7 url_ssh=xonotic-beta:autobuild-bsp/
8 build_cachedir="$HOME/xonotic-map-compiler.cache/"
9 screenshot_cachedir="$HOME/xonotic-map-screenshot.cache/"
10 override="-bsp_timeout 900 -vis_timeout 3600 -light_timeout 14400 -minimap_timeout 900 -scale_timeout 900"
11 screenshot_override="9 300"
12
13 allmaps()
14 {
15         for F in maps/*.map.options; do
16                 if ! [ -f "$F" ]; then
17                         continue
18                 fi
19                 if ! [ -f "${F%.options}" ]; then
20                         continue
21                 fi
22                 M=${F#maps/}
23                 M=${M%.map.options}
24                 blobhash=`git ls-files -s -- "$F" | cut -d ' ' -f 2`-`git ls-files -s -- "${F%.options}" | cut -d ' ' -f 2`
25                 "$@" "$M" "$blobhash"
26         done
27 }
28
29 pre2spam()
30 {
31         map=$1
32         url=$2
33         branch=$3
34         hash=$4
35
36         branch=${branch##refs/heads/}
37         branch=${branch##refs/remotes/}
38         branch=${branch##origin/}
39         hash=`echo "$hash" | cut -c 1-7`
40
41         echo "[$branch $hash] starting map compile of $map"
42 }
43
44 ss2spam()
45 {
46         map=$1
47         url=$2
48         branch=$3
49         hash=$4
50
51         branch=${branch##refs/heads/}
52         branch=${branch##refs/remotes/}
53         branch=${branch##origin/}
54         hash=`echo "$hash" | cut -c 1-7`
55
56         echo "[$branch $hash] screenshots of $map are available on $url"
57 }
58
59 log2spam()
60 {
61         map=$1
62         url=$2
63         branch=$3
64         hash=$4
65         status=$5
66         time=$6
67
68         hash=`echo "$hash" | cut -c 1-7`
69
70         branch=${branch##refs/heads/}
71         branch=${branch##refs/remotes/}
72         branch=${branch##origin/}
73
74         s_samplesize=
75         s_failshaders=
76         s_leaked=
77         s_error=
78
79         if [ "$status" -ne 0 ]; then
80                 s_error="exited with status $status"
81         fi
82         while IFS= read -r L; do
83                 case "$L" in
84                         WARNING:\ surface\ at\ *\ too\ large\ for\ desired\ samplesize*)
85                                 s=${L##* }
86                                 if [ -z "$s_samplesize" ] || [ "$s" -gt "$s_samplesize" ]; then
87                                         s_samplesize=$s
88                                 fi
89                                 ;;
90                         WARNING:\ Couldn\'t\ find\ image\ for\ shader\ textures/NULL)
91                                 # radiant stupid
92                                 ;;
93                         WARNING:\ Couldn\'t\ find\ image\ for\ shader\ *)
94                                 s_failshaders="$s_failshaders ${L##* }"
95                                 ;;
96                         '******* leaked *******')
97                                 s_leaked=1
98                                 ;;
99                         '************ ERROR ************')
100                                 IFS= read -r s_error
101                                 ;;
102                 esac
103         done
104         s_failshaders=`echo "$s_failshaders" | sed "s, textures/, ,g"`
105         s_failshaders=${s_failshaders# }
106         if [ -n "$s_error" ]; then
107                 echo -n "[$branch $hash] \ 34failed"
108         else
109                 echo -n "[$branch $hash] finished"
110         fi
111         echo -n " map compile of $map ($url): $time sec"
112         if [ -n "$s_samplesize" ]; then
113                 echo -n ", FIX samplesize >= $s_samplesize"
114         fi
115         if [ -n "$s_failshaders" ]; then
116                 if [ -n "`echo "$s_failshaders" | cut -d ' ' -f 4-`" ]; then
117                         s_failshaders="`echo "$s_failshaders" | cut -d ' ' -f 1-3`..."
118                 fi
119                 echo -n ", FIX shaders $s_failshaders"
120         fi
121         if [ -n "$s_leaked" ]; then
122                 echo -n ", FIX LEAK"
123         fi
124         if [ -n "$s_error" ]; then
125                 s_error=`echo "$s_error" | sed "s,$PWD/\?,,g"`
126                 echo -n ", ERROR: $s_error"
127         fi
128         echo
129 }
130
131 buildthemap()
132 {
133         REFNAME=$1
134         HASH=$2
135         url=$3
136         M=$4
137         blobhash=$5
138         if HEAD "$url$M-$blobhash.pk3"; then
139                 continue
140         fi
141         if [ -n "$IRCSPAM" ]; then
142                 pre2spam "$M" "$url$M-$blobhash.pk3" "$REFNAME" "$HASH" | $IRCSPAM
143         fi
144         t0=`date +%s`
145         (
146                 cd maps
147                 ../../../misc/tools/xonotic-map-compiler "$M" `grep ^- "$M.map.options" | cut -d '#' -f 1` $override > "$M.log"
148         )
149         t1=`date +%s`
150         dt=$(($t1 - $t0))
151         status=$?
152         if [ -n "$IRCSPAM" ]; then
153                 cat "maps/$M.log" | log2spam "$M" "$url$M-$blobhash.pk3" "$REFNAME" "$HASH" "$status" "$dt" > "maps/$M.irc"
154         fi
155         zip -9r "$M-$blobhash.pk3" "maps/$M.bsp" "maps/$M.log" "maps/$M.irc" "maps/$M/" "maps/$M.lin" "gfx/${M}_mini.tga"
156         ln -snf "../$M-$blobhash.pk3" "$M.pk3" # from ALL branches, so beware!
157         cp "$M-$blobhash.pk3" "$M-full-$blobhash.pk3"
158         zip -9r "$M-full-$blobhash.pk3" `git diff --name-only --diff-filter=ACMRTUXB master...HEAD` || true
159         ln -snf "../$M-full-$blobhash.pk3" "$M-full.pk3" # from ALL branches, so beware!
160         rsync -vaSHP "$M-$blobhash.pk3" "$M-full-$blobhash.pk3" "$url_ssh"
161         rsync -vaSHP "$M.pk3" "$M-full.pk3" "$url_ssh""latest/"
162         if [ -n "$IRCSPAM" ]; then
163                 $IRCSPAM < "maps/$M.irc"
164         fi
165 }
166
167 screenshotthemap()
168 {
169         REFNAME=$1
170         HASH=$2
171         url=$3
172         M=$4
173         blobhash=$5
174         if HEAD "$url$M-$blobhash/"; then
175                 continue
176         fi
177         rm -rf ~/.xonotic
178         (
179         )
180         if [ -n "$IRCSPAM" ]; then
181                 ss2spam "$M" "$url$M-$blobhash/" "$REFNAME" "$HASH" > "maps/$M.ircss"
182         fi
183         mv ~/.xonotic/data/screenshots "$M-$blobhash"
184         ln -snf "../$M-$blobhash" "$M" # from ALL branches, so beware!
185         rsync -vaSHP "$M-$blobhash" "$url_ssh"
186         rsync -vaSHP "$M" "$url_ssh""latest/"
187         if [ -n "$IRCSPAM" ]; then
188                 $IRCSPAM < "maps/$M.ircss"
189         fi
190 }
191
192 getthemap()
193 {
194         url=$1
195         bspdir_old=$2
196         bspdir=$3
197         M=$4
198         blobhash=$5
199         if mv "$bspdir_old/$M-$blobhash.pk3" "$bspdir/$M-$blobhash.pk3"; then
200                 continue
201         fi
202         if ! wget -O "$bspdir/$M-$blobhash.pk3" "$url$M-$blobhash.pk3"; then
203                 if ! curl -o "$bspdir/$M-$blobhash.pk3" "$url$M-$blobhash.pk3"; then
204                         rm -f "$bspdir/$M-$blobhash.pk3"
205                         echo "WARNING: could not download $url$M-$blobhash.pk3, maybe not ready yet"
206                         return 0
207                 fi
208         fi
209         if ! unzip -l "$bspdir/$M-$blobhash.pk3"; then
210                 rm -f "$bspdir/$M-$blobhash.pk3"
211                 echo "WARNING: could not download $url$M-$blobhash.pk3, invalid zip file"
212                 return 0
213         fi
214 }
215
216 case "$1" in
217         build)
218                 cd data/xonotic-maps.pk3dir
219                 git for-each-ref 'refs/remotes' | while read -r HASH TYPE REFNAME; do
220                         if [ -f "$build_cachedir/$HASH" ]; then
221                                 continue
222                         fi
223                         git reset --hard
224                         git clean -xfd
225                         git checkout -f "$HASH"
226                         allmaps buildthemap "$REFNAME" "$HASH" "$url"
227                         touch "$build_cachedir/$HASH"
228                 done
229                 git checkout -f master
230                 ;;
231         screenshot)
232                 cd data/xonotic-maps.pk3dir
233                 git for-each-ref 'refs/remotes' | while read -r HASH TYPE REFNAME; do
234                         if [ -f "$screenshot_cachedir/$HASH" ]; then
235                                 continue
236                         fi
237                         git reset --hard
238                         git clean -xfd
239                         git checkout -f "$HASH"
240                         allmaps screenshotthemap "$REFNAME" "$HASH" "$url"
241                         touch "$screenshot_cachedir/$HASH"
242                 done
243                 git checkout -f master
244                 ;;
245         download)
246                 mkdir -p "$bspdir" "$bspdir.old"
247                 for b in "$bspdir"/*-????????????????????????????????????????-????????????????????????????????????????.pk3; do
248                         if [ -e "$b" ]; then
249                                 mv "$b" "$bspdir.old"/
250                         fi
251                 done
252                 cd data/xonotic-maps.pk3dir
253                 allmaps getthemap "$url" "$bspdir.old" "$bspdir"
254                 echo "List of maps that got deleted (if any) and currently are in $bspdir.old:"
255                 ls -l "$bspdir.old"
256                 ;;
257         download-latest)
258                 mkdir -p "$bspdir"
259                 cd "$bspdir"
260                 rm -f *-????????????????????????????????????????-????????????????????????????????????????.pk3
261                 wget -r -l1 -A "*.pk3" -N --no-parent --no-directories "$url""latest"
262                 ;;
263         log2spam-test)
264                 log2spam "mapname" "http://mapurl" "branch" "commit" "0"
265                 ;;
266 esac