Skip to content

Commit a6ca273

Browse files
authored
Add summary for both test-all and test-changed jobs in test workflow (#3049)
1 parent 7b72f07 commit a6ca273

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

.github/workflows/java.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@ jobs:
4747
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
4848
- name: Test all exercises using java-test-runner
4949
run: bin/test-with-test-runner
50+
- name: Print summary
51+
run: |
52+
if [ -f exercises/build/summary.txt ]; then
53+
echo "===== TEST SUMMARY ====="
54+
cat exercises/build/summary.txt
55+
echo "========================"
56+
else
57+
echo "===== ALL TESTS PASSED ====="
58+
echo "No summary file was generated."
59+
echo "============================="
60+
fi
61+
if: always()
5062
- name: Archive test results
5163
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4
5264
with:
@@ -64,6 +76,18 @@ jobs:
6476
fetch-depth: 0
6577
- name: Test changed exercises using java-test-runner
6678
run: bin/test-changed-exercise
79+
- name: Print summary
80+
run: |
81+
if [ -f exercises/build/summary.txt ]; then
82+
echo "===== TEST SUMMARY ====="
83+
cat exercises/build/summary.txt
84+
echo "========================"
85+
else
86+
echo "===== ALL TESTS PASSED ====="
87+
echo "No summary file was generated."
88+
echo "============================="
89+
fi
90+
if: always()
6791
- name: Archive test results
6892
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4
6993
with:

bin/test-changed-exercise

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@ echo "Changed exercises detected:"
3535
echo "$changed_exercises"
3636
echo "----------------------------------------"
3737

38+
summary_dir="exercises/build"
39+
summary_file="${summary_dir}/summary.txt"
40+
mkdir -p "$summary_dir"
41+
3842
# Run tests
43+
exit_code=0
3944
for dir in $changed_exercises; do
4045
slug=$(basename "$dir")
4146

@@ -47,8 +52,27 @@ for dir in $changed_exercises; do
4752
mkdir -p "$(dirname "$results_path")"
4853

4954
if [[ $dir == exercises/practice/* ]]; then
50-
./exercises/gradlew -p exercises ":practice:$slug:test" 2>&1 | tee "$results_path"
55+
./exercises/gradlew -p exercises ":practice:$slug:test" 2>&1 | tee "$results_path" || true
5156
elif [[ $dir == exercises/concept/* ]]; then
52-
./exercises/gradlew -p exercises ":concept:$slug:test" 2>&1 | tee "$results_path"
57+
./exercises/gradlew -p exercises ":concept:$slug:test" 2>&1 | tee "$results_path" || true
58+
fi
59+
60+
# Detect failure
61+
if grep -q "FAILED" "$results_path"; then
62+
exit_code=1
63+
64+
# Determine practice/slug or concept/slug
65+
relative_path=$(echo "$dir" | sed 's|^exercises/||')
66+
67+
# Create summary.txt with header only on first failure
68+
if [ ! -f "$summary_file" ]; then
69+
echo "The following exercises have test failures or test errors:" > "$summary_file"
70+
fi
71+
72+
# Append the correct path (practice/slug or concept/slug)
73+
echo "$relative_path" >> "$summary_file"
5374
fi
75+
5476
done
77+
78+
exit $exit_code

bin/test-with-test-runner

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ docker pull exercism/java-test-runner
1212

1313
exit_code=0
1414

15+
summary_dir="exercises/build"
16+
summary_file="${summary_dir}/summary.txt"
17+
mkdir -p "$summary_dir"
18+
1519
function run_test_runner() {
1620
local slug=$1
1721
local solution_dir=$2
@@ -56,6 +60,18 @@ function verify_exercise() {
5660

5761
if [[ $(jq -r '.status' "${results_file}") != "pass" ]]; then
5862
echo "${slug}: ${implementation_file_key} solution did not pass the tests"
63+
64+
# Determine practice/slug or concept/slug
65+
local relative_path=$(echo "$dir" | sed -E 's|.*/exercises/||')
66+
67+
# Create summary.txt with header only on first failure
68+
if [ ! -f "$summary_file" ]; then
69+
echo "The following exercises have test failures or test errors:" > "$summary_file"
70+
fi
71+
72+
# Append the correct path (practice/slug or concept/slug)
73+
echo "$relative_path" >> "$summary_file"
74+
5975
exit_code=1
6076
fi
6177

0 commit comments

Comments
 (0)