Skip to content
Permalink
Browse files
[ci] [github] upload test log when fail (#3241)
  • Loading branch information
Shoothzj committed Apr 24, 2022
1 parent 0aace4e commit 0a2f796c0f27735c82c8d22b82fa0c88ddb1a674
Showing 9 changed files with 151 additions and 3 deletions.
@@ -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
@@ -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
run: ./dev/ci-tool print_thread_dumps
@@ -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
@@ -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:
@@ -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
run: ./dev/ci-tool print_thread_dumps
@@ -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
@@ -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
@@ -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
@@ -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:"

0 comments on commit 0a2f796

Please sign in to comment.