4 # Copyright (c) 2017 Vojtech Horky
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
11 # - Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # - Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in the
15 # documentation and/or other materials provided with the distribution.
16 # - The name of the author may not be used to endorse or promote products
17 # derived from this software without specific prior written permission.
19 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 CI_HOME
=`which -- "$0" 2>/dev/null`
32 # Maybe, we are running Bash
33 [ -z "$CI_HOME" ] && CI_HOME
=`which -- "$BASH_SOURCE" 2>/dev/null`
34 CI_HOME
=`dirname -- "$CI_HOME"`
39 list_build_numbers
() {
42 find -maxdepth 1 -mindepth 1 -type d
-name 'build-*'
57 CI_WEB_ROOT
="$PWD/web-ci"
59 CI_BUILD_DIR
="$PWD/tmp-ci"
62 # Load user configuration
63 if [ -e "ci.rc" ]; then
72 mkdir
-p "$CI_BUILD_DIR"
73 ( cd "$CI_BUILD_DIR"; rm -rf * )
76 # Ensure we are the only ones running
77 LOCK_DIR
="$CI_BUILD_DIR/lock-dir"
79 if ! mkdir
"$LOCK_DIR"; then
80 echo "Error: another build in progress, aborting." >&2
81 echo "Note: if no other build process is running, try removing $LOCK_DIR." >&2
86 # Run the rest of the script in subshell (shall ensure that we remove the
87 # lock directory upon termination).
91 mkdir
-p "$CI_WEB_ROOT"
94 BUILD_NUMBER
=`list_build_numbers "$CI_WEB_ROOT" | head -n 1`
95 if [ -z "$BUILD_NUMBER" ]; then
98 BUILD_NUMBER
=$
(( $BUILD_NUMBER + 1 ))
101 # Our directory with HTML report
102 WEB_DIR
="$CI_WEB_ROOT/build-$BUILD_NUMBER"
103 WEB_DIR_HIDDEN
="$CI_WEB_ROOT/.build-$BUILD_NUMBER"
106 "--build-id=$BUILD_NUMBER" \
107 "--build-directory=$CI_BUILD_DIR" \
108 "--artefact-directory=$WEB_DIR_HIDDEN" \
109 "--rss-url=../rss.xml" \
110 "--resource-path=../" \
113 if ! [ -e "$WEB_DIR_HIDDEN/report.xml" ]; then
114 echo "$WEB_DIR_HIDDEN/report.xml not found, aborting!" >&2
118 # Switch the new pages
119 mv "$WEB_DIR_HIDDEN" "$WEB_DIR"
121 # Ensure stylesheet and scripts are available
122 for i
in main.css jquery-2.1
.4.min.js
; do
123 cp -n "$CI_HOME/hbuild/web/$i" "$CI_WEB_ROOT/$i"
127 KEPT_BUILDS
=`list_build_numbers "$CI_WEB_ROOT" | head -n $CI_HISTORY_LENGTH | grep -v "^$BUILD_NUMBER\$" | paste '-sd '`
129 # Recreate the index page
131 --stringparam LAST_BUILD
$BUILD_NUMBER \
132 --stringparam PREVIOUS_BUILDS
"$KEPT_BUILDS" \
133 "$CI_HOME/hbuild/web/index.xsl" "$WEB_DIR/report.xml" \
134 >"$CI_WEB_ROOT/index.html"
138 --stringparam WEB_ROOT_ABSOLUTE_FILE_PATH
"$CI_WEB_ROOT" \
139 --stringparam PREVIOUS_BUILDS
"$KEPT_BUILDS" \
140 "$CI_HOME/hbuild/web/rss.xsl" "$WEB_DIR/report.xml" \
141 >"$CI_WEB_ROOT/rss.xml"
145 for ID
in $KEPT_BUILDS; do
146 KEPT_REPORTS
="$KEPT_REPORTS $CI_WEB_ROOT/build-$ID/report.xml"
149 --stringparam PREVIOUS_REPORTS
"$KEPT_REPORTS" \
150 "$CI_HOME/hbuild/web/diff-rss.xsl" "$WEB_DIR/report.xml" \
151 >"$CI_WEB_ROOT/diff-rss.xml"
153 # Remove older builds
154 for i
in `list_build_numbers "$CI_WEB_ROOT" | tail -n +$(( $CI_HISTORY_LENGTH + 1 ))`; do
155 rm -rf "$CI_WEB_ROOT/build-$i"
158 # Keep latest/ pointing to the latest build
161 ln -sTf "build-$BUILD_NUMBER" latest