You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@yetus.apache.org by aw...@apache.org on 2022/05/02 16:06:45 UTC

[yetus] branch main updated: YETUS-1030. Support linecomments in junit (#268)

This is an automated email from the ASF dual-hosted git repository.

aw pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/yetus.git


The following commit(s) were added to refs/heads/main by this push:
     new 4bf4bcd5 YETUS-1030. Support linecomments in junit (#268)
4bf4bcd5 is described below

commit 4bf4bcd57e2014a72bbc1a8ebb23fbf546a157c9
Author: Allen Wittenauer <aw...@apache.org>
AuthorDate: Mon May 2 09:06:40 2022 -0700

    YETUS-1030. Support linecomments in junit (#268)
    
    Signed-off-by: Nick Dimiduk <nd...@apache.org>
---
 .semaphore/semaphore-build.sh                      |  1 +
 .semaphore/semaphore.yml                           | 15 ++++-
 Jenkinsfile                                        | 11 ++++
 .../precommit/plugins/junit-bugsystem.html.md      |  8 +++
 entrypoint.sh                                      |  2 +-
 precommit/src/main/shell/core.d/linecomments.sh    |  2 +-
 precommit/src/main/shell/plugins.d/junit.sh        | 71 ++++++++++++++++++++++
 precommit/src/main/shell/robots.d/circleci.sh      |  3 +
 precommit/src/main/shell/test-patch.sh             |  1 -
 9 files changed, 110 insertions(+), 4 deletions(-)

diff --git a/.semaphore/semaphore-build.sh b/.semaphore/semaphore-build.sh
index ef151abc..a18509f5 100755
--- a/.semaphore/semaphore-build.sh
+++ b/.semaphore/semaphore-build.sh
@@ -23,6 +23,7 @@ PRECOMMITDIR=precommit/src/main/shell
   --mvn-custom-repos-dir=/tmp/yetus-m2 \
   --patch-dir=/tmp/yetus-out \
   --tests-filter=checkstyle,test4tests \
+  --junit-report-xml=/tmp/yetus-out/junit-results.xml \
   --docker \
   --dockerfile="${PRECOMMITDIR}/test-patch-docker/Dockerfile" \
   --docker-cache-from=ghcr.io/apache/yetus-base:main,ubuntu:focal
diff --git a/.semaphore/semaphore.yml b/.semaphore/semaphore.yml
index 341f4c94..ee073d8c 100644
--- a/.semaphore/semaphore.yml
+++ b/.semaphore/semaphore.yml
@@ -20,7 +20,8 @@ name: Apache Yetus
 agent:
   machine:
     type: e1-standard-2
-    os_image: ubuntu1804
+    os_image: ubuntu2004
+
 blocks:
   - name: "Apache Yetus"
     task:
@@ -29,3 +30,15 @@ blocks:
           commands:
             - checkout
             - .semaphore/semaphore-build.sh
+
+      epilogue:
+        always:
+          commands:
+            - test-results publish /tmp/yetus-out/junit-results.xml
+
+after_pipeline:
+  task:
+    jobs:
+      - name: Publish Results
+        commands:
+          - test-results gen-pipeline-report
diff --git a/Jenkinsfile b/Jenkinsfile
index b9305ac6..0ddbca26 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -189,6 +189,17 @@ pipeline {
         } catch(e) {
             echo 'junit processing: ' + e.toString()
         }
+
+        try {
+            recordIssues(
+              tool: junitParser(pattern: '**/junit-report.xml'),
+              enabledForFailure: true,
+              qualityGates: [[threshold: 1, type: 'TOTAL', unstable: true]]
+            )
+        } catch(e) {
+            echo 'warningsng processing: ' + e.toString()
+        }
+
         archiveArtifacts "${env.YETUS_RELATIVE_PATCHDIR}/**"
         // Publish the HTML report so that it can be looked at
         // Has to be relative to WORKSPACE.
diff --git a/asf-site-src/source/documentation/in-progress/precommit/plugins/junit-bugsystem.html.md b/asf-site-src/source/documentation/in-progress/precommit/plugins/junit-bugsystem.html.md
index 67ba54df..f8512a4c 100644
--- a/asf-site-src/source/documentation/in-progress/precommit/plugins/junit-bugsystem.html.md
+++ b/asf-site-src/source/documentation/in-progress/precommit/plugins/junit-bugsystem.html.md
@@ -41,8 +41,16 @@ None
 
 | Option | Notes |
 |:---------|:------|
+| `--junit-report-style=[full|line]` | Style of the junit report |
 | `--junit-report-xml=<file>` | Name of the output file |
 
+## JUnit Style
+
+The JUnit report type has two formats:
+
+* `full` - summarizes per-test and provides a link to the report for that test
+* `line` - summarizes per-file and works better with integrated CI systems and with external readers such as Jenkins WarningNG plug-in
+
 # Docker Notes
 
 None
diff --git a/entrypoint.sh b/entrypoint.sh
index 9ed32c4f..64616213 100755
--- a/entrypoint.sh
+++ b/entrypoint.sh
@@ -22,4 +22,4 @@ if [[ "${1:0:1}" = '-' ]]; then
 elif [[ -z "${1}" ]]; then
   set -- bash "$@"
 fi
-exec "$@"
\ No newline at end of file
+exec "$@"
diff --git a/precommit/src/main/shell/core.d/linecomments.sh b/precommit/src/main/shell/core.d/linecomments.sh
index a8fdfc4a..130d68e3 100755
--- a/precommit/src/main/shell/core.d/linecomments.sh
+++ b/precommit/src/main/shell/core.d/linecomments.sh
@@ -124,7 +124,7 @@ function bugsystem_linecomments_trigger
 
   for bugs in ${BUGLINECOMMENTS}; do
     if declare -f "${bugs}_linecomments_end" >/dev/null;then
-      "${bugs}_linecomments_end"
+      "${bugs}_linecomments_end" "${PATCH_DIR}/results-full.txt"
     fi
   done
 }
diff --git a/precommit/src/main/shell/plugins.d/junit.sh b/precommit/src/main/shell/plugins.d/junit.sh
index af0c7d13..9824e517 100755
--- a/precommit/src/main/shell/plugins.d/junit.sh
+++ b/precommit/src/main/shell/plugins.d/junit.sh
@@ -25,16 +25,21 @@ JUNIT_FAILED_TESTS=""
 JUNIT_TEST_OUTPUT_DIR="."
 JUNIT_TEST_PREFIX="org.apache."
 
+JUNIT_REPORT_STYLE="line"
+
 function junit_usage
 {
   yetus_add_option "--junit-test-output=<dir>" "Directory to search for the test output TEST-*.xml files, relative to the module directory (default:'${JUNIT_TEST_OUTPUT_DIR}')"
   yetus_add_option "--junit-test-prefix=<prefix to trim>" "Prefix of test names to be be removed. Used to shorten test names by removing common package name. (default:'${JUNIT_TEST_PREFIX}')"
+  yetus_add_option "--junit-report-style=[full|line]" "Format-type of the JUnit XML (default: ${JUNIT_REPORT_STYLE}"
   yetus_add_option "--junit-report-xml=<file>" "Filename to use when generating a JUnit-style report (default: ${JUNIT_REPORT_XML}"
 }
 
 function junit_parse_args
 {
   declare i
+  declare fn
+  declare style
 
   for i in "$@"; do
     case ${i} in
@@ -46,6 +51,10 @@ function junit_parse_args
         delete_parameter "${i}"
         JUNIT_TEST_PREFIX=${i#*=}
       ;;
+      --junit-report-style=*)
+        delete_parameter "${i}"
+        style=${i#*=}
+      ;;
       --junit-report-xml=*)
         delete_parameter "${i}"
         fn=${i#*=}
@@ -61,6 +70,12 @@ function junit_parse_args
       yetus_error "WARNING: cannot create JUnit XML report file ${fn}. Ignoring."
     fi
   fi
+
+  if [[ "${style}" == "line" || "${style}" == "full" ]]; then
+    JUNIT_REPORT_STYLE=${style}
+  elif [[ -n "${style}" ]]; then
+    yetus_error "WARNING: unknown junit style ${style}. Sticking with ${JUNIT_REPORT_STYLE}."
+  fi
 }
 
 function junit_process_tests
@@ -152,6 +167,10 @@ function junit_finalreport
     return
   fi
 
+  if [[ "${JUNIT_REPORT_STYLE}" != "full" ]]; then
+    return
+  fi
+
   big_console_header "Writing JUnit-style results to ${JUNIT_REPORT_XML}"
 
   url=$(get_artifact_url)
@@ -221,3 +240,55 @@ EOF
   echo "</testsuite>" >> "${JUNIT_REPORT_XML}"
   echo "</testsuites>" >> "${JUNIT_REPORT_XML}"
 }
+
+## @description  Line-based junit output
+## @audience     private
+## @stability    evolving
+## @replaceable  no
+## @param        runresult
+## @return       0 on success
+## @return       1 on failure
+function junit_linecomments_end
+{
+  declare testinfo=$1
+  declare linecount
+
+  if [[ "${JUNIT_REPORT_STYLE}" != "line" ]]; then
+    return
+  fi
+
+  linecount=$(wc -l "${testinfo}")
+  linecount=${linecount%% *}
+  timestamp=$(date +"%FT%T")
+
+  #shellcheck disable=SC2016
+  testcount=$("${AWK}" -F: '{print $4}' "${testinfo}" | sort -u | wc)
+
+  cat <<EOF > "${JUNIT_REPORT_XML}"
+<?xml version="1.0" encoding="UTF-8"?>
+<testsuite name="yetus" errors="0" failures="${linecount}" skipped="0" tests="${testcount}" time="${GLOBALTIMER}" timestamp="${timestamp}">
+EOF
+
+  while read -r ; do
+    fn=${REPLY%%:*}
+    rol=${REPLY/#${fn}:}
+    linenum=${rol%%:*}
+    rol=${rol/#${linenum}:}
+    column=${rol%%:*}
+    rol=${rol/#${column}:}
+    plugin=${rol%%:*}
+    text=${rol/#${plugin}:}
+    classname=${fn//\//.}
+    cat << EOF >> "${JUNIT_REPORT_XML}"
+  <testcase classname="${classname}" name="${plugin}" file="${fn}" line="${linenum}" column="${column}" time="0.003" timestamp="${timestamp}">
+    <failure message="ERROR" type="error">
+      ${fn}:${linenum}:${column} ${text}
+      </failure>
+  </testcase>
+EOF
+  done < <(cat "${testinfo}")
+
+  cat <<EOF >> "${JUNIT_REPORT_XML}"
+</testsuite>
+EOF
+}
diff --git a/precommit/src/main/shell/robots.d/circleci.sh b/precommit/src/main/shell/robots.d/circleci.sh
index 31177e8e..12e0435b 100755
--- a/precommit/src/main/shell/robots.d/circleci.sh
+++ b/precommit/src/main/shell/robots.d/circleci.sh
@@ -63,6 +63,9 @@ if [[ "${CIRCLECI}" = true ]] &&
     # shellcheck disable=SC2034
     GIT_BRANCH_SHA=${CIRCLE_SHA1}
 
+    # shellcheck disable=SC2034
+    JUNIT_REPORT_STYLE="full"
+
     yetus_add_array_element EXEC_MODES Circle_CI
   fi
 fi
diff --git a/precommit/src/main/shell/test-patch.sh b/precommit/src/main/shell/test-patch.sh
index 6890a1fa..9541bcf2 100755
--- a/precommit/src/main/shell/test-patch.sh
+++ b/precommit/src/main/shell/test-patch.sh
@@ -2175,7 +2175,6 @@ function check_unittests
   return 0
 }
 
-
 ## @description  Write the final output to the selected bug system
 ## @audience     private
 ## @stability    evolving