melos icon indicating copy to clipboard operation
melos copied to clipboard

How to 'fail' (exit code != 0) a melos script if a single step failed?

Open aardjon opened this issue 6 months ago • 1 comments

Hi,

I'm using Melos 6.3.2 for my monorepo project, and defined a melos script that runs all unit tests (from all sub-projects) and also does some reporting and coverage analysis. Simplified and shortened excerpt from the melos.yaml:

test:
    steps:
      - melos exec --no-flutter --dir-exists=test dart test
      - melos exec --flutter --dir-exists=test flutter test

I run it with melos run test. My problem is: When a single test of the first step fails, the whole melos script still exits with 0 and says "SUCCESS" at the end, so the failure may stay unnoticed.

I also tried using run instead, but the behaviour was the same:

test:
    run: |
      melos exec --no-flutter --dir-exists=test dart test
      melos exec --flutter --dir-exists=test flutter test

My question: How can I make the whole script fail if any of its steps failed? I'm not asking about "fail fast" because I'd prefer to still run all tests (so that I can create a report of failing tests).

Thanks in advance for any advice!

aardjon avatar Jun 22 '25 16:06 aardjon

This was fixed and released in Melos 7.0.0-dev.8. So if you can, I would recommend you to migrate to Melos v7, it will be moved to stable when the next Flutter version is released.

spydon avatar Jun 22 '25 18:06 spydon

Thanks! I can't migrate now, but I will try as soon as possible. Just to be sure: By "next Flutter version released", you mean Flutter 3.33 or newer, don't you?

aardjon avatar Jun 28 '25 10:06 aardjon

Hey, @aardjon 👋🏼 Have you tried with this?

test:
  run: >
    melos exec --no-flutter --dir-exists=test dart test
    &&
    melos exec --flutter --dir-exists=test flutter test

mrverdant13 avatar Jul 02 '25 17:07 mrverdant13

@mrverdant13 that is not using the steps feature, which this issue is about. But yes, not using steps can be a workaround.

spydon avatar Jul 03 '25 08:07 spydon

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

github-actions[bot] avatar Jul 31 '25 08:07 github-actions[bot]