Skip to content

Commit aa40fc2

Browse files
authored
fix(cli): use github reporter in github actions env (#9120)
1 parent 4fb55cf commit aa40fc2

32 files changed

Lines changed: 553 additions & 504 deletions

.changeset/cool-snails-wave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Fixed [#9109](https://github.com/biomejs/biome/issues/9109), where the GitHub reporter wasn't correctly enabled when `biome ci` runs on GitHub Actions.

Cargo.lock

Lines changed: 42 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/biome_cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ biome_json_parser = { workspace = true }
8888
directories = { workspace = true }
8989
insta = { workspace = true }
9090
regex = { workspace = true }
91+
serial_test = "3.3.1"
9192
tokio = { workspace = true, features = ["io-util"] }
9293

9394
[target.'cfg(all(target_family="unix", not(all(target_arch = "aarch64", target_env = "musl"))))'.dependencies]

crates/biome_cli/src/commands/ci.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::CliDiagnostic;
22
use crate::changed::get_changed_files;
3-
use crate::cli_options::CliOptions;
3+
use crate::cli_options::{CliOptions, CliReporter, CliReporterKind};
44
use crate::runner::execution::{AnalyzerSelectors, Execution, ExecutionEnvironment, VcsTargeted};
55
use crate::runner::impls::commands::traversal::{LoadEditorConfig, TraversalCommand};
66
use crate::runner::impls::executions::summary_verb::SummaryVerbExecution;
@@ -44,7 +44,7 @@ pub(crate) struct CiCommandPayload {
4444

4545
struct CiExecution {
4646
/// Whether the CI is running in a specific environment, e.g. GitHub, GitLab, etc.
47-
_environment: Option<ExecutionEnvironment>,
47+
environment: Option<ExecutionEnvironment>,
4848
/// A flag to know vcs integrated options such as `--staged` or `--changed` are enabled
4949
vcs_targeted: VcsTargeted,
5050
/// Whether assist diagnostics should be promoted to error, and fail the CLI
@@ -115,6 +115,15 @@ impl Execution for CiExecution {
115115
fn summary_phrase(&self, files: usize, duration: &Duration) -> MarkupBuf {
116116
SummaryVerbExecution.summary_verb("Checked", files, duration)
117117
}
118+
119+
fn environment_to_reporter(&self) -> Option<CliReporter> {
120+
self.environment.map(|e| match e {
121+
ExecutionEnvironment::GitHub => CliReporter {
122+
kind: CliReporterKind::GitHub,
123+
destination: None,
124+
},
125+
})
126+
}
118127
}
119128

120129
impl LoadEditorConfig for CiCommandPayload {
@@ -143,13 +152,19 @@ impl TraversalCommand for CiCommandPayload {
143152
_console: &mut dyn Console,
144153
_workspace: &dyn Workspace,
145154
) -> Result<Box<dyn Execution>, CliDiagnostic> {
146-
// Ref: https://docs.github.com/actions/learn-github-actions/variables#default-environment-variables
147-
let is_github = std::env::var("GITHUB_ACTIONS")
148-
.ok()
149-
.is_some_and(|value| value == "true");
155+
// This is funny, but we need to disable this at the moment, otherwise
156+
// all our tests that run `biome ci` IN OUR CI, will get false positives. Call it CI-ception
157+
let is_github = if cfg!(debug_assertions) {
158+
false
159+
} else {
160+
// Ref: https://docs.github.com/actions/learn-github-actions/variables#default-environment-variables
161+
std::env::var("GITHUB_ACTIONS")
162+
.ok()
163+
.is_some_and(|value| value == "true")
164+
};
150165

151166
Ok(Box::new(CiExecution {
152-
_environment: if is_github {
167+
environment: if is_github {
153168
Some(ExecutionEnvironment::GitHub)
154169
} else {
155170
None

crates/biome_cli/src/runner/execution.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::cli_options::CliOptions;
1+
use crate::cli_options::{CliOptions, CliReporter};
22
use biome_configuration::analyzer::AnalyzerSelector;
33
use biome_console::MarkupBuf;
44
use biome_diagnostics::Category;
@@ -161,6 +161,11 @@ pub(crate) trait Execution: Send + Sync + std::panic::RefUnwindSafe {
161161

162162
/// Used when printing summary
163163
fn summary_phrase(&self, files: usize, duration: &Duration) -> MarkupBuf;
164+
165+
/// Uses additional reporters based on the environment execution
166+
fn environment_to_reporter(&self) -> Option<CliReporter> {
167+
None
168+
}
164169
}
165170

166171
#[derive(Debug, Default, Clone)]

crates/biome_cli/src/runner/finalizer.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ pub trait Finalizer {
2929

3030
pub(crate) struct FinalizePayload<'a, I> {
3131
pub(crate) fs: &'a dyn FileSystem,
32-
pub(crate) workspace: &'a dyn Workspace,
3332
pub(crate) scan_duration: Option<Duration>,
3433
pub(crate) console: &'a mut dyn Console,
3534
pub(crate) cli_options: &'a CliOptions,

0 commit comments

Comments
 (0)