From 8135d23e5ea16ac8c4e69226679aba81a86001fa Mon Sep 17 00:00:00 2001 From: Dominik Toton <166132265+dtscalac@users.noreply.github.com> Date: Mon, 7 Oct 2024 15:23:59 +0200 Subject: [PATCH] fix(earthly-flutter): Make sure earthly target fails when flutter tests fail (#329) * fix(earthly-flutter): Make sure earthly target fails when flutter tests fail * chore(earthly-flutter): retain error logs in case of unit tests failure --- earthly/flutter/Earthfile | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/earthly/flutter/Earthfile b/earthly/flutter/Earthfile index 325ef592..c4cec1ca 100644 --- a/earthly/flutter/Earthfile +++ b/earthly/flutter/Earthfile @@ -143,18 +143,31 @@ UNIT_TESTS: IF [ -f melos.yaml ] RUN echo "Running unit tests with melos." - RUN melos run test-report + + # We always want to save the test_reports and coverage + # therefore we must defer the error reported here until later. + RUN melos run test-report > melos-output.txt 2>&1 || touch fail + + # If not failed then print the output immediately, + # if it has failed then it's printed at the end of the function when exiting. + IF [ ! -f fail ] + RUN cat melos-output.txt + END WAIT SAVE ARTIFACT test_reports AS LOCAL test_reports SAVE ARTIFACT coverage AS LOCAL coverage END + + # Defer the failure to here. + IF [ -f fail ] + RUN echo "Error occurred when running: melos run test-report"; \ + cat melos-output.txt; \ + exit 1 + END ELSE RUN echo "Running flutter test" RUN flutter test - WAIT - SAVE ARTIFACT test_reports AS LOCAL test_reports - END END # Build web app and save artifacts locally if needed.