From 3c5ffa19fdb214930541564b233dc0525e451579 Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Fri, 2 Aug 2024 13:18:48 +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 --- .idea/.gitignore | 8 +++++ .idea/a8c-ci-toolkit-buildkite-plugin.iml | 9 +++++ .idea/misc.xml | 6 ++++ .idea/modules.xml | 8 +++++ .idea/vcs.xml | 6 ++++ bin/merge_junit.sh | 40 +++++++++++++++++++++++ 6 files changed, 77 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/a8c-ci-toolkit-buildkite-plugin.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100755 bin/merge_junit.sh diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..13566b81 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/a8c-ci-toolkit-buildkite-plugin.iml b/.idea/a8c-ci-toolkit-buildkite-plugin.iml new file mode 100644 index 00000000..d6ebd480 --- /dev/null +++ b/.idea/a8c-ci-toolkit-buildkite-plugin.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..72991755 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..092013bc --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..35eb1ddf --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file 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"