Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 62 additions & 43 deletions .buildkite/commands/run-unit-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,65 +7,84 @@ 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
echo "^^^ +++"
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

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=(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Praise (❤️): Love this approach, much thing so much simpler, although, as per my previous comment, it is now harder to make this too dynamic... 💭

["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
10 changes: 9 additions & 1 deletion .buildkite/commands/upload-code-coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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[@]}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Praise (❤️): Nice and TIL! 🥇

61 changes: 10 additions & 51 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading