diff --git a/.buildkite/commands/run-unit-tests.sh b/.buildkite/commands/run-unit-tests.sh index a9ec43fba860..9b1e5be2c019 100755 --- a/.buildkite/commands/run-unit-tests.sh +++ b/.buildkite/commands/run-unit-tests.sh @@ -7,41 +7,22 @@ fi "$(dirname "${BASH_SOURCE[0]}")/restore-cache.sh" -echo "--- ๐Ÿงช Testing" +echo "+++ ๐Ÿงช Testing" set +e -if [ "$1" == "wordpress" ]; then - test_suite="testWordpressVanillaRelease koverXmlReportWordpressVanillaRelease" - test_results_dir="WordPress/build/test-results" - test_log_dir="${test_results_dir}/*/*.xml" - code_coverage_report="WordPress/build/reports/kover/reportWordpressVanillaRelease.xml" -elif [ "$1" == "processors" ]; then - test_suite=":libs:processors:test :libs:processors:koverXmlReport" - test_results_dir="libs/processors/build/test-results" - test_log_dir="${test_results_dir}/test/*.xml" - code_coverage_report="libs/processors/build/reports/kover/report.xml" -elif [ "$1" == "image-editor" ]; then - test_suite=":libs:image-editor:testReleaseUnitTest :libs:image-editor:koverXmlReportRelease" - test_results_dir="libs/image-editor/build/test-results" - test_log_dir="${test_results_dir}/testReleaseUnitTest/*.xml" - code_coverage_report="libs/image-editor/build/reports/kover/reportRelease.xml" -elif [ "$1" == "fluxc" ]; then - test_suite=":libs:fluxc:testReleaseUnitTest :libs:fluxc:koverXmlReportRelease" - test_results_dir="libs/fluxc/build/test-results" - test_log_dir="${test_results_dir}/testReleaseUnitTest/*.xml" - code_coverage_report="libs/fluxc/build/reports/kover/reportRelease.xml" -elif [ "$1" == "login" ]; then - test_suite=":libs:login:testReleaseUnitTest :libs:login:koverXmlReportRelease" - test_results_dir="libs/login/build/test-results" - test_log_dir="${test_results_dir}/testReleaseUnitTest/*.xml" - code_coverage_report="libs/login/build/reports/kover/reportRelease.xml" -else - echo "Invalid Test Suite! Expected 'wordpress', 'processors', or 'image-editor', received '$1' instead" - exit 1 -fi - -./gradlew $test_suite +./gradlew \ + testWordpressWasabiDebugUnitTest \ + :libs:processors:test \ + :libs:image-editor:testDebugUnitTest \ + :libs:fluxc:testDebugUnitTest \ + :libs:login:testDebugUnitTest \ + koverXmlReportWordpressWasabiDebug \ + :libs:processors:koverXmlReportJvm \ + :libs:image-editor:koverXmlReportDebug \ + :libs:fluxc:koverXmlReportDebug \ + :libs:login:koverXmlReportDebug TESTS_EXIT_STATUS=$? set -e +echo "" if [[ "$TESTS_EXIT_STATUS" -ne 0 ]]; then # Keep the (otherwise collapsed) current "Testing" section open in Buildkite logs on error. See https://buildkite.com/docs/pipelines/managing-log-output#collapsing-output @@ -49,23 +30,61 @@ if [[ "$TESTS_EXIT_STATUS" -ne 0 ]]; then echo "Unit Tests failed!" fi -echo "--- ๐Ÿšฆ Report Tests Status" -results_file="$test_results_dir/merged-test-results.xml" +if [[ "$TESTS_EXIT_STATUS" -eq 0 ]]; then + echo "--- โš’๏ธ Uploading code coverage" + # Find all kover XML reports and upload them + coverage_files=$(find . -path "*/build/reports/kover/*.xml" -type f) + if [ -n "$coverage_files" ]; then + .buildkite/commands/upload-code-coverage.sh $coverage_files + else + echo "No coverage files found matching pattern */build/reports/kover/*.xml" + fi +fi + +echo "--- ๐Ÿšฆ Collecting Test Results" + +# Define test result directories for each module +declare -A TEST_RESULT_DIRS=( + ["WordPress:wordpress"]="WordPress/build/test-results/testWordpressWasabiDebugUnitTest" + ["processors"]="libs/processors/build/test-results/test" + ["image-editor"]="libs/image-editor/build/test-results/testDebugUnitTest" + ["fluxc"]="libs/fluxc/build/test-results/testDebugUnitTest" + ["login"]="libs/login/build/test-results/testDebugUnitTest" +) +# Create temporary directory for collecting all test results +temp_test_results_dir=$(mktemp -d) + +# Copy all XML test results to temporary directory +for module in "${!TEST_RESULT_DIRS[@]}"; do + test_results_dir="${TEST_RESULT_DIRS[$module]}" + + if [ -d "$test_results_dir" ]; then + echo "Collecting test results from ${module}..." + cp "$test_results_dir"/*.xml "$temp_test_results_dir/" 2>/dev/null || true + else + echo "Test results directory $test_results_dir does not exist for module $module. Skipping..." + fi +done + +echo "--- ๐Ÿšฆ Report Tests Status" +results_file="WordPress/build/test-results/merged-test-results.xml" # Merge JUnit results into a single file (for performance reasons with reporting) -merge_junit_reports -d ${test_log_dir%/*} -o $results_file +# See https://github.com/Automattic/a8c-ci-toolkit-buildkite-plugin/pull/103 +merge_junit_reports -d "$temp_test_results_dir" -o "$results_file" + +# Clean up temporary directory +rm -rf "$temp_test_results_dir" if [[ $BUILDKITE_BRANCH == trunk ]] || [[ $BUILDKITE_BRANCH == release/* ]]; then - annotate_test_failures "$results_file" --slack "build-and-ship" + annotate_test_failures "$results_file" --slack "build-and-ship" else - annotate_test_failures "$results_file" + annotate_test_failures "$results_file" fi -echo "--- ๐Ÿงช Copying test logs for test collector" -mkdir buildkite-test-analytics -cp $results_file buildkite-test-analytics - -echo "--- โš’๏ธ Uploading code coverage" -.buildkite/commands/upload-code-coverage.sh $code_coverage_report +echo "--- ๐Ÿงช Copying Test Logs for Test Collector" +mkdir -p buildkite-test-analytics +cp "$results_file" "buildkite-test-analytics/merged-test-results.xml" +echo "--- ๐Ÿ“Š Tests Status" exit $TESTS_EXIT_STATUS diff --git a/.buildkite/commands/upload-code-coverage.sh b/.buildkite/commands/upload-code-coverage.sh index 1d3c343f6319..844becbcdb74 100755 --- a/.buildkite/commands/upload-code-coverage.sh +++ b/.buildkite/commands/upload-code-coverage.sh @@ -7,4 +7,12 @@ curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM.sig gpgv codecov.SHA256SUM.sig codecov.SHA256SUM sha256sum -c codecov.SHA256SUM chmod +x codecov -./codecov -t "$CODECOV_TOKEN" -f "$1" + +# Build arguments with multiple -f flags for each coverage file +coverage_args=() +for coverage_file in "$@"; do + coverage_args+=("-f" "$coverage_file") +done + +# Upload all coverage reports in a single execution +./codecov -t "$CODECOV_TOKEN" "${coverage_args[@]}" diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index e9ecd9ca4702..9bb2ac013346 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -101,57 +101,16 @@ steps: ################# # Unit Tests ################# - - group: "๐Ÿ”ฌ Unit Tests" - steps: - - label: "๐Ÿ”ฌ Unit Test WordPress" - command: ".buildkite/commands/run-unit-tests.sh wordpress" - plugins: - - $CI_TOOLKIT - - $TEST_COLLECTOR : - <<: *test_collector_common_params - api-token-env-name: "BUILDKITE_ANALYTICS_TOKEN_UNIT_TESTS_WORDPRESS" - artifact_paths: - - "**/build/test-results/merged-test-results.xml" - - - label: "๐Ÿ”ฌ Unit Test Processors" - command: ".buildkite/commands/run-unit-tests.sh processors" - plugins: - - $CI_TOOLKIT - - $TEST_COLLECTOR : - <<: *test_collector_common_params - api-token-env-name: "BUILDKITE_ANALYTICS_TOKEN_UNIT_TESTS_PROCESSORS" - artifact_paths: - - "**/build/test-results/merged-test-results.xml" - - - label: "๐Ÿ”ฌ Unit Test Image Editor" - command: ".buildkite/commands/run-unit-tests.sh image-editor" - plugins: - - $CI_TOOLKIT - - $TEST_COLLECTOR : - <<: *test_collector_common_params - api-token-env-name: "BUILDKITE_ANALYTICS_TOKEN_UNIT_TESTS_IMAGE_EDITOR" - artifact_paths: - - "**/build/test-results/merged-test-results.xml" - - - label: "๐Ÿ”ฌ Unit Test FluxC" - command: ".buildkite/commands/run-unit-tests.sh fluxc" - plugins: - - $CI_TOOLKIT - - $TEST_COLLECTOR: - <<: *test_collector_common_params - api-token-env-name: "BUILDKITE_ANALYTICS_TOKEN_UNIT_TESTS_FLUXC" - artifact_paths: - - "**/build/test-results/merged-test-results.xml" - - - label: "๐Ÿ”ฌ Unit Test Login" - command: ".buildkite/commands/run-unit-tests.sh login" - plugins: - - $CI_TOOLKIT - - $TEST_COLLECTOR: - <<: *test_collector_common_params - api-token-env-name: "BUILDKITE_ANALYTICS_TOKEN_UNIT_TESTS_LOGIN" - artifact_paths: - - "**/build/test-results/merged-test-results.xml" + - label: "๐Ÿ”ฌ Unit Tests" + command: ".buildkite/commands/run-unit-tests.sh" + plugins: + - $CI_TOOLKIT + - $TEST_COLLECTOR : + <<: *test_collector_common_params + api-token-env-name: "BUILDKITE_ANALYTICS_TOKEN_UNIT_TESTS_WORDPRESS" + artifact_paths: + - "**/build/test-results/merged-test-results.xml" + - "**/build/reports/kover/*.xml" ################# # Instrumented (aka UI) Tests