#!/bin/bash set -x . /etc/mason.conf REPORT_PATH=/var/mason/report.html SERVER_PATH=/srv/mason SERVER_REPORT_PATH="$SERVER_PATH/index.html" sed_escape() { printf "%s\n" "$1" | sed -e 's/\W/\\&/g' } create_report() { cat > $REPORT_PATH <<'EOF'
Mason
Build log of changes to BRANCH
from TROVE
. Most recent first.
Started | Ref | Duration | Result |
---|
....-..-.. ..:..:..<\/code>/'"$(sed_escape "$build_start_time")"'<\/code>/' $REPORT_PATH
fi
}
START_TIME=`date +%Y-%m-%d\ %T`
update_report_time "$START_TIME"
cp "$REPORT_PATH" "$SERVER_PATH/index.html"
logfile="$(mktemp)"
#Update current.log symlink to point to the current build log
ln -sf "$logfile" "$SERVER_PATH"/current.log
#Copy current server report, to restore when result is "skip"
cp "$SERVER_REPORT_PATH" "$SERVER_REPORT_PATH".bak
update_report "$START_TIME" \
"$UPSTREAM_TROVE_ADDRESS" \
"$DEFINITIONS_REF" \
"" \
" - " \
"progress" \
"$SERVER_REPORT_PATH" \
"current.log"
/usr/lib/mason/mason.sh 2>&1 | tee "$logfile"
case "${PIPESTATUS[0]}" in
0)
RESULT=pass
;;
33)
RESULT=skip
;;
42)
RESULT=nonet
;;
*)
RESULT=fail
;;
esac
# TODO: Update page with last executed time
if [ "$RESULT" = skip ]; then
# Restore copied server report, otherwise the 'progress' row will
# be still present with a broken link after we remove the $logfile
mv "$SERVER_REPORT_PATH".bak "$SERVER_REPORT_PATH"
rm "$logfile"
exit 0
fi
DURATION=$(( $(date +%s) - $(date --date="$START_TIME" +%s) ))
SHA1="$(cd "ws/$DEFINITIONS_REF/$UPSTREAM_TROVE_ADDRESS/baserock/baserock/definitions" && git rev-parse HEAD)"
BUILD_LOG="log/${SHA1}--${START_TIME}.log"
update_report "$START_TIME" \
"$UPSTREAM_TROVE_ADDRESS" \
"$DEFINITIONS_REF" \
"$SHA1" \
"$DURATION" \
"$RESULT" \
"$REPORT_PATH" \
"$BUILD_LOG"
#
# Copy report into server directory
#
cp "$REPORT_PATH" "$SERVER_REPORT_PATH"
mkdir "$SERVER_PATH/log"
mv "$logfile" "$SERVER_PATH/$BUILD_LOG"
# Cleanup
mkdir -p /srv/distbuild/remove
mv /srv/distbuild/!(remove) /srv/distbuild/remove
rm -r /srv/distbuild/remove