invertase / melos

🌋 A tool for managing Dart projects with multiple packages. With IntelliJ and Vscode IDE support. Supports automated versioning, changelogs & publishing via Conventional Commits.
https://melos.invertase.dev/~melos-latest
Apache License 2.0
1.19k stars 206 forks source link

fix: Melos doesn't work without 'global activation' if 'exec' is used #690

Open wujek-srujek opened 8 months ago

wujek-srujek commented 8 months ago

Is there an existing issue for this?

Version

5.3.0

Description

I have the following melos.yaml:

name: test

packages:
  - .
  - packages/*
  - packages/*/example

scripts:
  pwd:
    run: pwd
    exec:
      concurrency: 1
      orderDependents: true

On CI, we turn on melos using dart pub global activate melos. This has issues because if there are more than 1 job running on the system, and melos / dart / flutter versions differ, the second global activation also changes the command for the already running job, and melos commands may fail - this has just happened to me as a job for the main branch failed because another job for an 'upgrade everything' branch globally activated melos in another version (also dart and flutter were different).

So the idea is to not activate it globally on CI, and it makes problems. While calling

dart run melos --version

works, this doesn't:

$ dart run melos run --no-select pwd
melos run pwd
  â””> melos exec --concurrency 1 --order-dependents -- "pwd"
     â””> RUNNING

ERROR: /bin/sh: melos: command not found

melos run pwd
  â””> melos exec --concurrency 1 --order-dependents -- "pwd"
     â””> FAILED
ScriptException: The script pwd failed to execute.

This is likely because Melos is trying to shell out, and the new processes don't find the melos command.

Yes, melos is not on PATH, but that's the whole point, I want each job to have it own melos. How do I do that?

It seems to have something to do with using the exec block. If I remove it, it works, but only for the top-level package, which is not what I want:

$ dart run melos run --no-select pwd
melos run pwd
  â””> pwd
     â””> RUNNING

/Users/wujek/Development/melos_test

melos run pwd
  â””> pwd
     â””> SUCCESS

Steps to reproduce

  1. Deactivate melos globally (if activated): dart pub global deactivate melos.
  2. Try to call a script with dart run melos run ....

Expected behavior

The command works.

wujek-srujek commented 7 months ago

To make it work on CI we now set PUB_CACHE so that each GitHub Actions runner gets its own Pub cache and the global activation is scoped to jobs on that runner only, effectively fixing the issue for us.

There are other ways to make it work as well, like setting a different $HOME for each runner, which effectively also scopes dart/flutter/melos to that directory.

However, the underlying issue in Melos that it cannot be used without global activation persist. Others might not be able to use my approach so fixing this issue would be helpful.

yauhenuzum commented 5 months ago

Also struggling with it, thanks for the temporary solution