From 771b5f32c376f921eec8ed2a0dfc4c3f8120a760 Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Fri, 2 Aug 2024 13:19:37 +0200 Subject: [PATCH] Introduce `merge_junit` script To improve performance of Android unit tests collection. Originated it https://github.com/woocommerce/woocommerce-android/pull/12064 --- bin/merge_junit.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 bin/merge_junit.sh diff --git a/bin/merge_junit.sh b/bin/merge_junit.sh new file mode 100755 index 00000000..b4935373 --- /dev/null +++ b/bin/merge_junit.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +# Initialize variables +reports_dir="" +output_file="" + +# Function to show usage +usage() { + echo "Usage: $0 -d -o " + exit 1 +} + +# Parse command-line options +while getopts "d:o:" opt; do + case $opt in + d) reports_dir=$OPTARG ;; + o) output_file=$OPTARG ;; + ?) usage ;; + esac +done + +# Check if both arguments were provided +if [ -z "$reports_dir" ] || [ -z "$output_file" ]; then + usage +fi + +# Write XML header to the output file +echo '' > "$output_file" +echo '' >> "$output_file" + +# Merge the content of all input JUnit files in the directory. +# (Note that in the case of Unit Tests, the JUnit XML files produced by Gradle +# don't have a parent `` root tag, so there's no need to try and remove it) +sed '/<\?xml .*\?>/d' "$reports_dir"/*.xml >> "$output_file" + +# Close the testsuites tag +echo '' >> "$output_file" + +# Print the result +echo "Merged XML reports into $output_file"