From a1ca4d2d0437e97d5336359c9d73408b8f78b2b3 Mon Sep 17 00:00:00 2001 From: Katherine Chen Date: Thu, 19 Dec 2024 18:10:31 +1100 Subject: [PATCH] Add check for the number of tests run --- .github/workflows/shared-build-and-test.yaml | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/.github/workflows/shared-build-and-test.yaml b/.github/workflows/shared-build-and-test.yaml index 414eadcb..1507cd1d 100644 --- a/.github/workflows/shared-build-and-test.yaml +++ b/.github/workflows/shared-build-and-test.yaml @@ -38,8 +38,25 @@ jobs: - name: Build and run unit tests if: ${{ inputs.vulnerability_scan_only == 'false' }} - run: mvn -B clean compile test working-directory: ${{ inputs.working_dir }} + run: | + mvn -B clean compile test | tee build.log + + tests_run=$(cat build.log | grep "Tests run:" | tail -n 1 | sed 's/.*Tests run: \([0-9]*\).*/\1/') + + echo "DEBUG: tests_run = $tests_run" + + if [ -z "$tests_run" ]; then + echo "WARNING: Could not determine the number of tests run." + tests_run=0 + fi + + if [ "$tests_run" -eq 0 ]; then + echo "ERROR: No tests were run!" + exit 1 + fi + + echo "INFO: $tests_run tests were run!" - name: Generate code coverage if: ${{ inputs.vulnerability_scan_only == 'false' }}