fix(cli): disable colors when GitHub Actions auto-enables github reporter#9215
Conversation
When `biome ci` runs in GitHub Actions, the github reporter is auto-enabled but colors are force-enabled, causing ANSI escape codes to wrap ::error/::warning workflow command lines. This breaks GitHub's ability to parse them as workflow commands. Closes biomejs#9189
🦋 Changeset detectedLatest commit: 73e81d3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
WalkthroughAdds a centralized is_github_actions() helper and updates CLI color handling so that, when running in CI on GitHub Actions and the user has not explicitly set colors, the CLI disables colours (returns ColorsArg::Off). get_execution in the CI command now uses the new helper. Also adds a changeset documenting a patch release noting that GitHub Actions CI now disables colours so workflow commands aren’t wrapped in ANSI escape codes. Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
crates/biome_cli/src/commands/mod.rs (1)
722-722: Minor nit: stale grammatical error in the comment.
"We want force colors in CI"— "to" is missing fromwant to force.✏️ One-word fix
- // We want force colors in CI, to give a better UX experience + // We want to force colors in CI for a better UX🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@crates/biome_cli/src/commands/mod.rs` at line 722, Update the inline comment text that reads "We want force colors in CI, to give a better UX experience" to fix the grammar by adding the missing "to" so it reads "We want to force colors in CI, to give a better UX experience"; locate and edit the comment near the color/CI handling logic in mod.rs (the comment containing "We want force colors in CI") to apply this one-word change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@crates/biome_cli/src/commands/mod.rs`:
- Line 722: Update the inline comment text that reads "We want force colors in
CI, to give a better UX experience" to fix the grammar by adding the missing
"to" so it reads "We want to force colors in CI, to give a better UX
experience"; locate and edit the comment near the color/CI handling logic in
mod.rs (the comment containing "We want force colors in CI") to apply this
one-word change.
crates/biome_cli/src/commands/mod.rs
Outdated
| if !cfg!(debug_assertions) | ||
| && std::env::var("GITHUB_ACTIONS") | ||
| .ok() | ||
| .is_some_and(|v| v == "true") | ||
| { | ||
| return Some(&ColorsArg::Off); | ||
| } |
There was a problem hiding this comment.
Please extract this code into a utility function. We have the same code in another place. Please keep the comment of the other code
Comment forwarded from another PR; #9236 (comment)
There was a problem hiding this comment.
Ill extract it into a helper function one sec
There was a problem hiding this comment.
🧹 Nitpick comments (1)
crates/biome_cli/src/commands/mod.rs (1)
768-780: Solid helper — one small note on testability.The
cfg!(debug_assertions)guard is a pragmatic solution to the CI-ception problem and is well-documented. Just worth being aware that theColorsArg::Offpath inget_color(and theExecutionEnvironment::GitHubpath inci.rs) are permanently unreachable from unit tests, so behaviour verification relies entirely on manual testing or integration/end-to-end CI runs.If coverage matters to you, one option is an injectable seam (e.g. a
#[cfg(test)]override or an environment-based escape hatch), but for something this simple it's likely overkill.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@crates/biome_cli/src/commands/mod.rs` around lines 768 - 780, The is_github_actions() helper currently hard-circuits debug builds via cfg!(debug_assertions), making the ColorsArg::Off branch in get_color and ExecutionEnvironment::GitHub in ci.rs unreachable in unit tests; add a testable seam by allowing an override (e.g., check an environment variable like "BIOME_FORCE_GITHUB_ACTIONS" or provide a #[cfg(test)] path) so tests can simulate CI: modify is_github_actions() to still return false in debug by default but honor the override env var or test-only flag, and update usages (get_color, ExecutionEnvironment detection) to rely on the revised is_github_actions().
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@crates/biome_cli/src/commands/mod.rs`:
- Around line 768-780: The is_github_actions() helper currently hard-circuits
debug builds via cfg!(debug_assertions), making the ColorsArg::Off branch in
get_color and ExecutionEnvironment::GitHub in ci.rs unreachable in unit tests;
add a testable seam by allowing an override (e.g., check an environment variable
like "BIOME_FORCE_GITHUB_ACTIONS" or provide a #[cfg(test)] path) so tests can
simulate CI: modify is_github_actions() to still return false in debug by
default but honor the override env var or test-only flag, and update usages
(get_color, ExecutionEnvironment detection) to rely on the revised
is_github_actions().
Summary
Fixes #9189
When
biome ciruns in GitHub Actions, the github reporter gets auto-enabled but colors are also force-enabled. This causes ANSI reset sequences to wrap the::error/::warninglines, which prevents GitHub from recognizing them as workflow commands.The fix checks for
GITHUB_ACTIONS=truebefore forcing colors on, so the auto-detected path behaves the same way as explicitly passing--reporter=default --reporter=github(which already works correctly).Uses the same
cfg!(debug_assertions)guard as the existing GitHub detection inci.rsto avoid breaking tests.