Skip to content

Commit

Permalink
fix(cli): disable colors when using the github reporter (#3281)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sec-ant authored Jun 25, 2024
1 parent b3d8bfd commit c6c5e6c
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 22 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

- Fix [#3104](https://github.com/biomejs/biome/issues/3104) by suppressing node warnings when using `biome migrate`. Contributed by @SuperchupuDev

- Force colors to be off when using the GitHub reporter to properly create annotations in GitHub actions ([#3148](https://github.com/biomejs/biome/issues/3148)). Contributed by @Sec-ant

### Parser

#### New features
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_cli/src/cli_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub struct CliOptions {
/// Allows to change how diagnostics and summary are reported.
#[bpaf(
long("reporter"),
argument("json|json-pretty|summary"),
argument("json|json-pretty|github|junit|summary"),
fallback(CliReporter::default())
)]
pub reporter: CliReporter,
Expand Down
16 changes: 14 additions & 2 deletions crates/biome_cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::changed::{get_changed_files, get_staged_files};
use crate::cli_options::{cli_options, CliOptions, ColorsArg};
use crate::cli_options::{cli_options, CliOptions, CliReporter, ColorsArg};
use crate::diagnostics::{DeprecatedArgument, DeprecatedConfigurationFile};
use crate::execute::Stdin;
use crate::logging::LoggingKind;
Expand Down Expand Up @@ -476,7 +476,19 @@ impl BiomeCommand {

pub const fn get_color(&self) -> Option<&ColorsArg> {
match self.cli_options() {
Some(cli_options) => cli_options.colors.as_ref(),
Some(cli_options) => {
// To properly display GitHub annotations we need to disable colors
if matches!(cli_options.reporter, CliReporter::GitHub) {
return Some(&ColorsArg::Off);
}
// We want force colors in CI, to give e better UX experience
// Unless users explicitly set the colors flag
if matches!(self, BiomeCommand::Ci { .. }) && cli_options.colors.is_none() {
return Some(&ColorsArg::Force);
}
// Normal behaviors
cli_options.colors.as_ref()
}
None => None,
}
}
Expand Down
14 changes: 2 additions & 12 deletions crates/biome_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use biome_cli::{
biome_command, open_transport, setup_panic_handler, to_color_mode, BiomeCommand, CliDiagnostic,
CliSession,
};
use biome_console::{markup, ColorMode, ConsoleExt, EnvConsole};
use biome_console::{markup, ConsoleExt, EnvConsole};
use biome_diagnostics::{set_bottom_frame, Diagnostic, PrintDiagnostic};
use biome_service::workspace;
use std::process::{ExitCode, Termination};
Expand Down Expand Up @@ -37,17 +37,7 @@ fn main() -> ExitCode {
let mut console = EnvConsole::default();
let command = biome_command().fallback_to_usage().run();

let color_mode = to_color_mode(command.get_color());
// we want force colours in CI, to give e better UX experience
if let BiomeCommand::Ci { cli_options, .. } = &command {
if cli_options.colors.is_none() {
console.set_color(ColorMode::Enabled);
} else {
console.set_color(color_mode);
}
} else {
console.set_color(color_mode);
}
console.set_color(to_color_mode(command.get_color()));

let is_verbose = command.is_verbose();
let result = run_workspace(&mut console, command);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ Global options applied to all commands
--no-errors-on-unmatched Silence errors that would be emitted in case no files were processed
during the execution of the command.
--error-on-warnings Tell Biome to exit with an error code if some diagnostics emit warnings.
--reporter=<json|json-pretty|summary> Allows to change how diagnostics and summary are reported.
--reporter=<json|json-pretty|github|junit|summary> Allows to change how diagnostics and summary
are reported.
--log-level=<none|debug|info|warn|error> The level of logging. In order, from the most verbose
to the least verbose: debug, info, warn, error.
The value `none` won't show any logging.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ Global options applied to all commands
--no-errors-on-unmatched Silence errors that would be emitted in case no files were processed
during the execution of the command.
--error-on-warnings Tell Biome to exit with an error code if some diagnostics emit warnings.
--reporter=<json|json-pretty|summary> Allows to change how diagnostics and summary are reported.
--reporter=<json|json-pretty|github|junit|summary> Allows to change how diagnostics and summary
are reported.
--log-level=<none|debug|info|warn|error> The level of logging. In order, from the most verbose
to the least verbose: debug, info, warn, error.
The value `none` won't show any logging.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ Global options applied to all commands
--no-errors-on-unmatched Silence errors that would be emitted in case no files were processed
during the execution of the command.
--error-on-warnings Tell Biome to exit with an error code if some diagnostics emit warnings.
--reporter=<json|json-pretty|summary> Allows to change how diagnostics and summary are reported.
--reporter=<json|json-pretty|github|junit|summary> Allows to change how diagnostics and summary
are reported.
--log-level=<none|debug|info|warn|error> The level of logging. In order, from the most verbose
to the least verbose: debug, info, warn, error.
The value `none` won't show any logging.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ Global options applied to all commands
--no-errors-on-unmatched Silence errors that would be emitted in case no files were processed
during the execution of the command.
--error-on-warnings Tell Biome to exit with an error code if some diagnostics emit warnings.
--reporter=<json|json-pretty|summary> Allows to change how diagnostics and summary are reported.
--reporter=<json|json-pretty|github|junit|summary> Allows to change how diagnostics and summary
are reported.
--log-level=<none|debug|info|warn|error> The level of logging. In order, from the most verbose
to the least verbose: debug, info, warn, error.
The value `none` won't show any logging.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ Global options applied to all commands
--no-errors-on-unmatched Silence errors that would be emitted in case no files were processed
during the execution of the command.
--error-on-warnings Tell Biome to exit with an error code if some diagnostics emit warnings.
--reporter=<json|json-pretty|summary> Allows to change how diagnostics and summary are reported.
--reporter=<json|json-pretty|github|junit|summary> Allows to change how diagnostics and summary
are reported.
--log-level=<none|debug|info|warn|error> The level of logging. In order, from the most verbose
to the least verbose: debug, info, warn, error.
The value `none` won't show any logging.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ Global options applied to all commands
--no-errors-on-unmatched Silence errors that would be emitted in case no files were processed
during the execution of the command.
--error-on-warnings Tell Biome to exit with an error code if some diagnostics emit warnings.
--reporter=<json|json-pretty|summary> Allows to change how diagnostics and summary are reported.
--reporter=<json|json-pretty|github|junit|summary> Allows to change how diagnostics and summary
are reported.
--log-level=<none|debug|info|warn|error> The level of logging. In order, from the most verbose
to the least verbose: debug, info, warn, error.
The value `none` won't show any logging.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function generateVariants(variants: SortConfig["variants"]) {
for (const { name } of variants) {
output += `${INDENT}"${name}",\n`
}
output += `];\n`;
output += "];\n";
return output;
}

Expand Down

0 comments on commit c6c5e6c

Please sign in to comment.