moonrepo / moon

A build system and monorepo management tool for the web ecosystem, written in Rust.
https://moonrepo.dev/moon
MIT License
2.82k stars 154 forks source link

[bug] outputStyle=(buffer-only-failure | none) is not working #1568

Open artsiommiksiuk opened 2 months ago

artsiommiksiuk commented 2 months ago

Describe the bug

Having this task definition

platform: system
tasks:
  test1:
    command: echo "hello"
    options:
      cache: false
      outputStyle: buffer-only-failure
  test2:
    deps:
      - "test1"
    options:
      cache: false

and selecting outputStyle either buffer-only-failure or even none, still prints hello in the console, independently if this is a transient or non transient dependency.

Steps to reproduce

➜  backend git:(main) ✗ moon oas-schema:test1
hello
▪▪▪▪ oas-schema:test1
▪▪▪▪ oas-schema:test1 (2ms)

Tasks: 1 completed
 Time: 3ms

➜  backend git:(main) ✗ moon oas-schema:test2
hello
▪▪▪▪ oas-schema:test1
▪▪▪▪ oas-schema:test1 (2ms)
▪▪▪▪ oas-schema:test2 (no op)

Tasks: 2 completed
 Time: 3ms

➜  backend git:(main) ✗ 

Expected behavior

Nothing is printed in the console if running via test2.

Environment


  System:
    OS: macOS 14.4.1
    CPU: (12) arm64 Apple M3 Pro
    Memory: 505.94 MB / 36.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.11.1 - ~/.nvm/versions/node/v20.11.1/bin/node
    npm: 10.2.4 - ~/.nvm/versions/node/v20.11.1/bin/npm
    pnpm: 8.15.6 - /opt/homebrew/bin/pnpm
  Managers:
    Homebrew: 4.3.9 - /opt/homebrew/bin/brew
    pip3: 24.0 - /opt/homebrew/bin/pip3
    RubyGems: 3.0.3.1 - /usr/bin/gem
  Utilities:
    Bazel: 7.1.2 - /opt/homebrew/bin/bazel
    Make: 3.81 - /usr/bin/make
    GCC: 15.0.0 - /usr/bin/gcc
    Git: 2.39.3 - /usr/bin/git
    Clang: 15.0.0 - /usr/bin/clang
    Curl: 8.4.0 - /usr/bin/curl
    OpenSSL: 3.3.1 - /opt/homebrew/bin/openssl
  Servers:
    Apache: 2.4.58 - /usr/sbin/apachectl
  Virtualization:
    Docker: 25.0.4 - /opt/homebrew/bin/docker
    Docker Compose: 2.24.6 - /usr/local/bin/docker-compose
  IDEs:
    VSCode: 1.91.1 - /usr/local/bin/code
    Vim: 9.0 - /usr/bin/vim
    Xcode: /undefined - /usr/bin/xcodebuild
  Languages:
    Bash: 3.2.57 - /bin/bash
    Perl: 5.34.1 - /usr/bin/perl
    Python: 3.10.14 - /Users/artsiommiksiuk/Projects/backend/.venv/bin/python
    Python3: 3.12.4 - /opt/homebrew/bin/python3
    Ruby: 2.6.10 - /usr/bin/ruby
  Databases:
    PostgreSQL: 14.11 - /opt/homebrew/bin/postgres
    SQLite: 3.43.2 - /usr/bin/sqlite3
  Browsers:
    Chrome: 126.0.6478.128
    Safari: 17.4.1
milesj commented 2 months ago

Hrmm, this is tricky. We have this condition that's being hit in this case:

// When a task is configured as local (no caching), or the interactive flag is passed,
// we don't "capture" stdout/stderr (which breaks stdin) and let it stream natively.
if !self.task.options.cache && context.primary_targets.len() == 1 {
    self.interactive = true;
}

It's basically to support stdin. If the command is buffered but requires stdin, the user would never know.

I can update the docs about this scenario at least.

artsiommiksiuk commented 2 months ago

I think there should be then flag which doesn't beef with other flags which just allows user to control output behaviour regardless of other settings. Explicit and simple output: yes | no will do.

milesj commented 2 months ago

This setting originally worked that way but then cause a bunch of confusion/issues because users couldn't understand how to handle stdin and assumed moon or their task was broken.

I'm not sure what the best solution is here.