From e43ea8e7d870c5e4d319ab1fc4c6feabb04a5cba Mon Sep 17 00:00:00 2001 From: Jagdish Prajapati Date: Sun, 16 Nov 2025 19:50:51 +0530 Subject: [PATCH 1/3] Add summary for both test-all and test-changed jobs in test workflow --- .github/workflows/java.yml | 24 ++++++++++++++++++++++++ bin/test-changed-exercise | 28 ++++++++++++++++++++++++++-- bin/test-with-test-runner | 16 ++++++++++++++++ 3 files changed, 66 insertions(+), 2 deletions(-) diff --git a/.github/workflows/java.yml b/.github/workflows/java.yml index 34ae302ed..8c9e5acce 100644 --- a/.github/workflows/java.yml +++ b/.github/workflows/java.yml @@ -47,6 +47,18 @@ jobs: - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 - name: Test all exercises using java-test-runner run: bin/test-with-test-runner + - name: Print summary + run: | + if [ -f exercises/build/summary.txt ]; then + echo "===== TEST SUMMARY =====" + cat exercises/build/summary.txt + echo "========================" + else + echo "===== ALL TESTS PASSED =====" + echo "No summary file was generated." + echo "=============================" + fi + if: always() - name: Archive test results uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 with: @@ -64,6 +76,18 @@ jobs: fetch-depth: 0 - name: Test changed exercises using java-test-runner run: bin/test-changed-exercise + - name: Print summary + run: | + if [ -f exercises/build/summary.txt ]; then + echo "===== TEST SUMMARY =====" + cat exercises/build/summary.txt + echo "========================" + else + echo "===== ALL TESTS PASSED =====" + echo "No summary file was generated." + echo "=============================" + fi + if: always() - name: Archive test results uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 with: diff --git a/bin/test-changed-exercise b/bin/test-changed-exercise index cbc684b79..3b987276a 100755 --- a/bin/test-changed-exercise +++ b/bin/test-changed-exercise @@ -35,7 +35,12 @@ echo "Changed exercises detected:" echo "$changed_exercises" echo "----------------------------------------" +summary_dir="exercises/build" +summary_file="${summary_dir}/summary.txt" +mkdir -p "$summary_dir" + # Run tests +exit_code=0 for dir in $changed_exercises; do slug=$(basename "$dir") @@ -47,8 +52,27 @@ for dir in $changed_exercises; do mkdir -p "$(dirname "$results_path")" if [[ $dir == exercises/practice/* ]]; then - ./exercises/gradlew -p exercises ":practice:$slug:test" 2>&1 | tee "$results_path" + ./exercises/gradlew -p exercises ":practice:$slug:test" 2>&1 | tee "$results_path" || true elif [[ $dir == exercises/concept/* ]]; then - ./exercises/gradlew -p exercises ":concept:$slug:test" 2>&1 | tee "$results_path" + ./exercises/gradlew -p exercises ":concept:$slug:test" 2>&1 | tee "$results_path" || true + fi + + # Detect failure + if grep -q "FAILED" "$results_path"; then + exit_code=1 + + # Determine practice/slug or concept/slug + relative_path=$(echo "$dir" | sed 's|^exercises/||') + + # Create summary.txt with header only on first failure + if [ ! -f "$summary_file" ]; then + echo "The following exercises did NOT pass:" > "$summary_file" + fi + + # Append the correct path (practice/slug or concept/slug) + echo "$relative_path" >> "$summary_file" fi + done + +exit $exit_code \ No newline at end of file diff --git a/bin/test-with-test-runner b/bin/test-with-test-runner index eed2d74b0..f32ab5778 100755 --- a/bin/test-with-test-runner +++ b/bin/test-with-test-runner @@ -12,6 +12,10 @@ docker pull exercism/java-test-runner exit_code=0 +summary_dir="exercises/build" +summary_file="${summary_dir}/summary.txt" +mkdir -p "$summary_dir" + function run_test_runner() { local slug=$1 local solution_dir=$2 @@ -56,6 +60,18 @@ function verify_exercise() { if [[ $(jq -r '.status' "${results_file}") != "pass" ]]; then echo "${slug}: ${implementation_file_key} solution did not pass the tests" + + # Determine practice/slug or concept/slug + local relative_path=$(echo "$dir" | sed -E 's|.*/exercises/||') + + # Create summary.txt with header only on first failure + if [ ! -f "$summary_file" ]; then + echo "The following exercises did NOT pass:" > "$summary_file" + fi + + # Append the correct path (practice/slug or concept/slug) + echo "$relative_path" >> "$summary_file" + exit_code=1 fi From a755f6935b1938f272f8e1146356a37ebefaf4c5 Mon Sep 17 00:00:00 2001 From: Jagdish Prajapati Date: Wed, 19 Nov 2025 00:18:47 +0530 Subject: [PATCH 2/3] Update bin/test-changed-exercise Co-authored-by: Kah Goh --- bin/test-changed-exercise | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/test-changed-exercise b/bin/test-changed-exercise index 3b987276a..b18a488e8 100755 --- a/bin/test-changed-exercise +++ b/bin/test-changed-exercise @@ -66,7 +66,7 @@ for dir in $changed_exercises; do # Create summary.txt with header only on first failure if [ ! -f "$summary_file" ]; then - echo "The following exercises did NOT pass:" > "$summary_file" + echo "The following exercises have test failures or test errors:" > "$summary_file" fi # Append the correct path (practice/slug or concept/slug) From eb8512fa0b2e953e5b22f7a90d76d2fc27324de8 Mon Sep 17 00:00:00 2001 From: Jagdish Prajapati Date: Wed, 19 Nov 2025 00:18:55 +0530 Subject: [PATCH 3/3] Update bin/test-with-test-runner Co-authored-by: Kah Goh --- bin/test-with-test-runner | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/test-with-test-runner b/bin/test-with-test-runner index f32ab5778..5e5dc8889 100755 --- a/bin/test-with-test-runner +++ b/bin/test-with-test-runner @@ -66,7 +66,7 @@ function verify_exercise() { # Create summary.txt with header only on first failure if [ ! -f "$summary_file" ]; then - echo "The following exercises did NOT pass:" > "$summary_file" + echo "The following exercises have test failures or test errors:" > "$summary_file" fi # Append the correct path (practice/slug or concept/slug)