You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by eo...@apache.org on 2022/04/24 10:42:27 UTC

[bookkeeper] branch master updated: [ci] [github] upload test log when fail (#3241)

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

eolivelli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git


The following commit(s) were added to refs/heads/master by this push:
     new 0a2f796c0f [ci] [github] upload test log when fail (#3241)
0a2f796c0f is described below

commit 0a2f796c0f27735c82c8d22b82fa0c88ddb1a674
Author: ZhangJian He <sh...@gmail.com>
AuthorDate: Sun Apr 24 18:42:21 2022 +0800

    [ci] [github] upload test log when fail (#3241)
---
 .github/actions/copy-test-reports/action.yml | 27 +++++++++++++++++
 .github/workflows/bookie-tests.yml           | 15 +++++++++-
 .github/workflows/client-tests.yml           | 13 +++++++++
 .github/workflows/owasp-dep-check.yml        |  2 +-
 .github/workflows/remaining-tests.yml        | 15 +++++++++-
 .github/workflows/replication-tests.yml      | 13 +++++++++
 .github/workflows/stream-tests.yml           | 13 +++++++++
 .github/workflows/tls-tests.yml              | 13 +++++++++
 dev/ci-tool                                  | 43 ++++++++++++++++++++++++++++
 9 files changed, 151 insertions(+), 3 deletions(-)

diff --git a/.github/actions/copy-test-reports/action.yml b/.github/actions/copy-test-reports/action.yml
new file mode 100644
index 0000000000..f2d03d5c38
--- /dev/null
+++ b/.github/actions/copy-test-reports/action.yml
@@ -0,0 +1,27 @@
+#
+# 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.
+#
+
+name: Copy test reports
+description: Aggregates all test reports to ./test-reports and ./surefire-reports directories
+runs:
+  using: composite
+  steps:
+    - run: |
+        $GITHUB_WORKSPACE/dev/ci-tool move_test_reports
+      shell: bash
diff --git a/.github/workflows/bookie-tests.yml b/.github/workflows/bookie-tests.yml
index 0421418274..58c32bf09e 100644
--- a/.github/workflows/bookie-tests.yml
+++ b/.github/workflows/bookie-tests.yml
@@ -63,6 +63,19 @@ jobs:
       - name: Run bookie tests
         run: mvn -B -nsu -pl bookkeeper-server test -Dtest="org.apache.bookkeeper.bookie.*Test" -DfailIfNoTests=false -Dorg.slf4j.simpleLogger.defaultLogLevel=INFO
 
+      - name: Aggregates all test reports to ./test-reports and ./surefire-reports directories If failure
+        if: failure()
+        continue-on-error: true
+        uses: ./.github/actions/copy-test-reports
+
+      - name: Upload Surefire reports
+        uses: actions/upload-artifact@v3
+        if: failure()
+        continue-on-error: true
+        with:
+          name: bookie-tests-reports
+          path: surefire-reports
+
       - name: print JVM thread dumps when cancelled
         if: cancelled()
-        run: ./dev/ci-tool print_thread_dumps
\ No newline at end of file
+        run: ./dev/ci-tool print_thread_dumps
diff --git a/.github/workflows/client-tests.yml b/.github/workflows/client-tests.yml
index 4089e98e3d..5feb146833 100644
--- a/.github/workflows/client-tests.yml
+++ b/.github/workflows/client-tests.yml
@@ -53,6 +53,19 @@ jobs:
       - name: Run client tests
         run: mvn -B -am -nsu -pl bookkeeper-server clean install test -Dtest="org.apache.bookkeeper.client.**" -DfailIfNoTests=false -Dorg.slf4j.simpleLogger.defaultLogLevel=INFO
 
+      - name: Aggregates all test reports to ./test-reports and ./surefire-reports directories If failure
+        if: failure()
+        continue-on-error: true
+        uses: ./.github/actions/copy-test-reports
+
+      - name: Upload Surefire reports
+        uses: actions/upload-artifact@v3
+        if: failure()
+        continue-on-error: true
+        with:
+          name: client-tests-reports
+          path: surefire-reports
+
       - name: print JVM thread dumps when cancelled
         if: cancelled()
         run: ./dev/ci-tool print_thread_dumps
diff --git a/.github/workflows/owasp-dep-check.yml b/.github/workflows/owasp-dep-check.yml
index 695d97c6ca..d61b019ae9 100644
--- a/.github/workflows/owasp-dep-check.yml
+++ b/.github/workflows/owasp-dep-check.yml
@@ -67,7 +67,7 @@ jobs:
         run: mvn -q -B -ntp clean install verify -Powasp-dependency-check -DskipTests -pl '!stream/distributedlog/io/dlfs'
 
       - name: Upload report
-        uses: actions/upload-artifact@v2
+        uses: actions/upload-artifact@v3
         if: ${{ cancelled() || failure() }}
         continue-on-error: true
         with:
diff --git a/.github/workflows/remaining-tests.yml b/.github/workflows/remaining-tests.yml
index 61d5dead79..d7eb6562a0 100644
--- a/.github/workflows/remaining-tests.yml
+++ b/.github/workflows/remaining-tests.yml
@@ -53,6 +53,19 @@ jobs:
       - name: Run remaining tests
         run: mvn -B -nsu -am -pl bookkeeper-server clean install test -Dtest="!org.apache.bookkeeper.client.**,!org.apache.bookkeeper.bookie.**,!org.apache.bookkeeper.replication.**,!org.apache.bookkeeper.tls.**" -DfailIfNoTests=false -Dorg.slf4j.simpleLogger.defaultLogLevel=INFO
 
+      - name: Aggregates all test reports to ./test-reports and ./surefire-reports directories If failure
+        if: failure()
+        continue-on-error: true
+        uses: ./.github/actions/copy-test-reports
+
+      - name: Upload Surefire reports
+        uses: actions/upload-artifact@v3
+        if: failure()
+        continue-on-error: true
+        with:
+          name: remaining-tests-reports
+          path: surefire-reports
+
       - name: print JVM thread dumps when cancelled
         if: cancelled()
-        run: ./dev/ci-tool print_thread_dumps
\ No newline at end of file
+        run: ./dev/ci-tool print_thread_dumps
diff --git a/.github/workflows/replication-tests.yml b/.github/workflows/replication-tests.yml
index 6845d8f137..e8997bc33c 100644
--- a/.github/workflows/replication-tests.yml
+++ b/.github/workflows/replication-tests.yml
@@ -53,6 +53,19 @@ jobs:
       - name: Run replication tests
         run: mvn -B -nsu -am -pl bookkeeper-server clean install test -Dtest="org.apache.bookkeeper.replication.**" -DfailIfNoTests=false -Dorg.slf4j.simpleLogger.defaultLogLevel=INFO
 
+      - name: Aggregates all test reports to ./test-reports and ./surefire-reports directories If failure
+        if: failure()
+        continue-on-error: true
+        uses: ./.github/actions/copy-test-reports
+
+      - name: Upload Surefire reports
+        uses: actions/upload-artifact@v3
+        if: failure()
+        continue-on-error: true
+        with:
+          name: replication-tests-reports
+          path: surefire-reports
+
       - name: print JVM thread dumps when cancelled
         if: cancelled()
         run: ./dev/ci-tool print_thread_dumps
diff --git a/.github/workflows/stream-tests.yml b/.github/workflows/stream-tests.yml
index 311417844f..d8bbe3b49f 100644
--- a/.github/workflows/stream-tests.yml
+++ b/.github/workflows/stream-tests.yml
@@ -54,6 +54,19 @@ jobs:
       - name: Run StreamStorage tests
         run: mvn -B -nsu -f stream/pom.xml verify -DstreamTests -Dorg.slf4j.simpleLogger.defaultLogLevel=INFO
 
+      - name: Aggregates all test reports to ./test-reports and ./surefire-reports directories If failure
+        if: failure()
+        continue-on-error: true
+        uses: ./.github/actions/copy-test-reports
+
+      - name: Upload Surefire reports
+        uses: actions/upload-artifact@v3
+        if: failure()
+        continue-on-error: true
+        with:
+          name: stream-tests-reports
+          path: surefire-reports
+
       - name: print JVM thread dumps when cancelled
         if: cancelled()
         run: ./dev/ci-tool print_thread_dumps
diff --git a/.github/workflows/tls-tests.yml b/.github/workflows/tls-tests.yml
index 1b456ca451..203e5ce0d0 100644
--- a/.github/workflows/tls-tests.yml
+++ b/.github/workflows/tls-tests.yml
@@ -53,6 +53,19 @@ jobs:
       - name: Run tls tests
         run: mvn -B -am -nsu -pl bookkeeper-server clean install test -Dtest="org.apache.bookkeeper.tls.**" -DfailIfNoTests=false -Dorg.slf4j.simpleLogger.defaultLogLevel=INFO
 
+      - name: Aggregates all test reports to ./test-reports and ./surefire-reports directories If failure
+        if: failure()
+        continue-on-error: true
+        uses: ./.github/actions/copy-test-reports
+
+      - name: Upload Surefire reports
+        uses: actions/upload-artifact@v3
+        if: failure()
+        continue-on-error: true
+        with:
+          name: tls-tests-reports
+          path: surefire-reports
+
       - name: print JVM thread dumps when cancelled
         if: cancelled()
         run: ./dev/ci-tool print_thread_dumps
diff --git a/dev/ci-tool b/dev/ci-tool
index 604f4fb5f0..08bc2e1386 100755
--- a/dev/ci-tool
+++ b/dev/ci-tool
@@ -37,6 +37,49 @@ function ci_print_thread_dumps() {
   return 0
 }
 
+# copies test reports into test-reports and surefire-reports directory
+# subsequent runs of tests might overwrite previous reports. This ensures that all test runs get reported.
+function ci_move_test_reports() {
+  (
+    if [ -n "${GITHUB_WORKSPACE}" ]; then
+      cd "${GITHUB_WORKSPACE}"
+      mkdir -p test-reports
+      mkdir -p surefire-reports
+    fi
+    # aggregate all junit xml reports in a single directory
+    if [ -d test-reports ]; then
+      # copy test reports to single directory, rename duplicates
+      find . -path '*/target/surefire-reports/junitreports/TEST-*.xml' -print0 | xargs -0 -r -n 1 mv -t test-reports --backup=numbered
+      # rename possible duplicates to have ".xml" extension
+      (
+        for f in test-reports/*~; do
+          mv -- "$f" "${f}.xml"
+        done 2>/dev/null
+      ) || true
+    fi
+    # aggregate all surefire-reports in a single directory
+    if [ -d surefire-reports ]; then
+      (
+        find . -type d -path '*/target/surefire-reports' -not -path './surefire-reports/*' |
+          while IFS=$'\n' read -r directory; do
+            echo "Copying reports from $directory"
+            target_dir="surefire-reports/${directory}"
+            if [ -d "$target_dir" ]; then
+              # rotate backup directory names *~3 -> *~2, *~2 -> *~3, *~1 -> *~2, ...
+              ( command ls -vr1d "${target_dir}~"* 2> /dev/null | awk '{print "mv "$0" "substr($0,0,length-1)substr($0,length,1)+1}' | sh ) || true
+              # backup existing target directory, these are the results of the previous test run
+              mv "$target_dir" "${target_dir}~1"
+            fi
+            # copy files
+            cp -R --parents "$directory" surefire-reports
+            # remove the original directory
+            rm -rf "$directory"
+          done
+      )
+    fi
+  )
+}
+
 if [ -z "$1" ]; then
   echo "usage: $0 [ci_tool_function_name]"
   echo "Available ci tool functions:"