YETUS-376. add ability to write report to an HTML formatted file Signed-off-by: Allen Wittenauer <[email protected]>
Project: http://git-wip-us.apache.org/repos/asf/yetus/repo Commit: http://git-wip-us.apache.org/repos/asf/yetus/commit/2fe2b360 Tree: http://git-wip-us.apache.org/repos/asf/yetus/tree/2fe2b360 Diff: http://git-wip-us.apache.org/repos/asf/yetus/diff/2fe2b360 Branch: refs/heads/YETUS-156 Commit: 2fe2b360fae5cda7d5ea7cf698a742c4f8eecefc Parents: aa0bd72 Author: Allen Wittenauer <[email protected]> Authored: Wed Apr 13 21:40:13 2016 -0700 Committer: Allen Wittenauer <[email protected]> Committed: Fri Apr 22 13:25:07 2016 -0700 ---------------------------------------------------------------------- .../in-progress/precommit-advanced.md | 5 + precommit/test-patch.d/htmlout.sh | 231 +++++++++++++++++++ precommit/test-patch.sh | 9 +- 3 files changed, 242 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/yetus/blob/2fe2b360/asf-site-src/source/documentation/in-progress/precommit-advanced.md ---------------------------------------------------------------------- diff --git a/asf-site-src/source/documentation/in-progress/precommit-advanced.md b/asf-site-src/source/documentation/in-progress/precommit-advanced.md index d64392a..953b44e 100644 --- a/asf-site-src/source/documentation/in-progress/precommit-advanced.md +++ b/asf-site-src/source/documentation/in-progress/precommit-advanced.md @@ -80,6 +80,9 @@ Similarly, there are other functions that may be defined during the test-patch r * pluginname\_initialize - After argument parsing and prior to any other work, the initialize step allows a plug-in to do any precursor work, set internal defaults, etc. +* pluginname\_docker\_support + - Perform any necessary setup to configure Docker support for the given plugin. Typically this means adding parameters to the docker run command line via adding to the DOCKER\_EXTRAARGS array. + * pluginname\_precheck - executed prior to the patch being applied but after the git repository is setup. Returning a fail status here will exit test-patch. @@ -253,6 +256,8 @@ There are a handful of extremely important system variables that make life easie * CHANGED\_MODULES[@] is an array of all modules that house all of the CHANGED\_FILES[@]. Be aware that the root of the source tree is reported as '.'. +* DOCKER\_EXTRAARGS[@] is an array of command line arguments to apply to the `docker run` command. + * GITHUB\_REPO is to help test-patch when talking to Github. If test-patch is given just a number on the command line, it will default to using this repo to determine the pull request. * JIRA\_ISSUE\_RE is to help test-patch when talking to JIRA. It helps determine if the given project is appropriate for the given JIRA issue. http://git-wip-us.apache.org/repos/asf/yetus/blob/2fe2b360/precommit/test-patch.d/htmlout.sh ---------------------------------------------------------------------- diff --git a/precommit/test-patch.d/htmlout.sh b/precommit/test-patch.d/htmlout.sh new file mode 100755 index 0000000..29af898 --- /dev/null +++ b/precommit/test-patch.d/htmlout.sh @@ -0,0 +1,231 @@ +#!/usr/bin/env bash +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This bug system provides github integration + +add_bugsystem htmlout + +## @description Usage info for htmlout plugin +## @audience private +## @stability evolving +## @replaceable no +function htmlout_usage +{ + yetus_add_option "--html-report-file=<file>" "Save the final report to an HTML-formated file" +} + +## @description Option parsing for htmlout plugin +## @audience private +## @stability evolving +## @replaceable no +function htmlout_parse_args +{ + declare i + declare fn + + for i in "$@"; do + case ${i} in + --html-report-file=*) + fn=${i#*=} + ;; + esac + done + + if [[ -n "${fn}" ]]; then + touch "${fn}" 2>/dev/null + if [[ $? != 0 ]]; then + yetus_error "WARNING: cannot create ${fn}. Ignoring." + else + HTMLOUT_REPORTFILE=$(yetus_abs "${fn}") + fi + fi +} + +## @description Give access to the HTML report file in docker mode +## @audience private +## @stability evolving +## @replaceable no +function htmlout_docker_support +{ + if [[ -n ${HTMLOUT_REPORTFILE} ]]; then + DOCKER_EXTRAARGS=("${DOCKER_EXTRAARGS[@]}" "-v" "${HTMLOUT_REPORTFILE}:${HTMLOUT_REPORTFILE}") + fi +} + + +## @description Write out an HTML version of the final report to a file +## @audience private +## @stability evolving +## @replaceable no +## @param runresult +function htmlout_finalreport +{ + declare result=$1 + declare i + declare commentfile="${HTMLOUT_REPORTFILE}" + declare comment + declare vote + declare ourstring + declare ela + declare subs + declare color + declare comment + + rm "${commentfile}" 2>/dev/null + + if [[ -z "${HTMLOUT_REPORTFILE}" ]]; then + return + fi + + big_console_header "Writing HTML to ${commentfile}" + + { + echo "<table><tbody>" + + if [[ ${result} == 0 ]]; then + echo "<tr><th><font color=\"green\">+1 overall</font></th></tr>" + else + echo "<tr><th><font color=\"red\">-1 overall</font></th></tr>" + fi + echo "</table></tbody>" + echo "<p></p>" + } > "${commentfile}" + + i=0 + until [[ $i -eq ${#TP_HEADER[@]} ]]; do + ourstring=$(echo "${TP_HEADER[${i}]}" | tr -s ' ') + comment=$(echo "${ourstring}" | cut -f2 -d\|) + printf "<tr><td>%s</td></tr>\n" "${comment}" + ((i=i+1)) + done + + { + echo "<table><tbody>" + echo "<tr>" + echo "<th>Vote</th>" + echo "<th>Subsystem</th>" + echo "<th>Runtime</th>" + echo "<th>Comment</th>" + echo "</tr>" + } >> "${commentfile}" + + i=0 + until [[ $i -eq ${#TP_VOTE_TABLE[@]} ]]; do + ourstring=$(echo "${TP_VOTE_TABLE[${i}]}" | tr -s ' ') + vote=$(echo "${ourstring}" | cut -f2 -d\| | tr -d ' ') + subs=$(echo "${ourstring}" | cut -f3 -d\|) + ela=$(echo "${ourstring}" | cut -f4 -d\|) + comment=$(echo "${ourstring}" | cut -f5 -d\|) + + # summary line + if [[ -z ${vote} + && -n ${ela} ]]; then + color="black" + elif [[ -z ${vote} ]]; then + # keep same color + true + else + # new vote line + case ${vote} in + 1|"+1") + color="green" + ;; + -1) + color="red" + ;; + 0) + color="blue" + ;; + *) + color="black" + ;; + esac + fi + + { + echo "<tr>" + printf "<td><font color=\"%s\">%s</font></td>" "${color}" "${vote}" + printf "<td><font color=\"%s\">%s</font></td>" "${color}" "${subs}" + printf "<td><font color=\"%s\">%s</font></td>" "${color}" "${ela}" + printf "<td><font color=\"%s\">%s</font></td>" "${color}" "${comment}" + echo "</tr>" + } >> "${commentfile}" + ((i=i+1)) + done + { + echo "</tbody></table>" + echo "<p></p>" + } >> "${commentfile}" + + if [[ ${#TP_TEST_TABLE[@]} -gt 0 ]]; then + { + echo "<table><tbody>" + echo "<tr>" + echo "<th>Reason</th>" + echo "<th>Tests</th>" + echo "</tr>" + } >> "${commentfile}" + + i=0 + until [[ $i -eq ${#TP_TEST_TABLE[@]} ]]; do + ourstring=$(echo "${TP_TEST_TABLE[${i}]}" | tr -s ' ') + subs=$(echo "${ourstring}" | cut -f2 -d\|) + comment=$(echo "${ourstring}" | cut -f3 -d\|) + { + echo "<tr>" + printf "<td><font color=\"%s\">%s</font></td>" "${color}" "${subs}" + printf "<td><font color=\"%s\">%s</font></td>" "${color}" "${comment}" + echo "</tr>" + } >> "${commentfile}" + ((i=i+1)) + done + + { + echo "</tbody></table>" + echo "<p></p>" + } >> "${commentfile}" + fi + + { + echo "<table><tbody>" + echo "<tr>" + echo "<th>Subsystem</th>" + echo "<th>Report/Notes</th>" + echo "</tr>" + } >> "${commentfile}" + + i=0 + until [[ $i -eq ${#TP_FOOTER_TABLE[@]} ]]; do + ourstring=$(echo "${TP_FOOTER_TABLE[${i}]}" | + ${SED} -e "s,@@BASE@@,${BUILD_URL}${BUILD_URL_ARTIFACTS},g" | + tr -s ' ') + subs=$(echo "${ourstring}" | cut -f2 -d\|) + comment=$(echo "${ourstring}" | cut -f3 -d\|) + { + echo "<tr>" + printf "<td><font color=\"%s\">%s</font></td>" "${color}" "${subs}" + printf "<td><font color=\"%s\">%s</font></td>" "${color}" "${comment}" + echo "</tr>" + } >> "${commentfile}" + ((i=i+1)) + done + { + echo "</tbody></table>" + echo "<p></p>" + } >> "${commentfile}" + + printf "<p>This message was automatically generated.</p>" >> "${commentfile}" +} http://git-wip-us.apache.org/repos/asf/yetus/blob/2fe2b360/precommit/test-patch.sh ---------------------------------------------------------------------- diff --git a/precommit/test-patch.sh b/precommit/test-patch.sh index 6d36819..05a075e 100755 --- a/precommit/test-patch.sh +++ b/precommit/test-patch.sh @@ -1633,6 +1633,7 @@ function check_reexec declare tpdir declare copy=false declare testdir + declare plugin if [[ ${REEXECED} == true ]]; then big_console_header "Re-exec mode detected. Continuing." @@ -1693,9 +1694,11 @@ function check_reexec # if we are doing docker, then we re-exec, but underneath the # container - if declare -f ${BUILDTOOL}_docker_support >/dev/null; then - "${BUILDTOOL}_docker_support" - fi + for plugin in ${PROJECT_NAME} ${BUILDTOOL} ${BUGSYSTEMS} ${TESTTYPES} ${TESTFORMATS}; do + if declare -f ${plugin}_docker_support >/dev/null; then + "${plugin}_docker_support" + fi + done TESTPATCHMODE="${USER_PARAMS[*]}" if [[ -n "${BUILD_URL}" ]]; then
