Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(turborepo): added specific symbol for cache hit #8869

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions crates/turborepo-lib/src/task_graph/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,8 @@ impl ExecContext {
// If the task resulted in an error, do not group in order to better highlight
// the error.
let is_error = matches!(result, Ok(ExecOutcome::Task { .. }));
let logs = match output_client.finish(is_error) {
let is_cache_hit = matches!(result, Ok(ExecOutcome::Success(SuccessOutcome::CacheHit)));
let logs = match output_client.finish(is_error, is_cache_hit) {
Ok(logs) => logs,
Err(e) => {
telemetry.track_error(TrackedErrors::DaemonFailedToMarkOutputsAsCached);
Expand Down Expand Up @@ -1136,11 +1137,11 @@ impl<W: Write> CacheOutput for TaskCacheOutput<W> {

/// Struct for displaying information about task
impl<W: Write> TaskOutput<W> {
pub fn finish(self, use_error: bool) -> std::io::Result<Option<Vec<u8>>> {
pub fn finish(self, use_error: bool, is_cache_hit: bool) -> std::io::Result<Option<Vec<u8>>> {
match self {
TaskOutput::Direct(client) => client.finish(use_error),
TaskOutput::UI(client) if use_error => Ok(Some(client.failed())),
TaskOutput::UI(client) => Ok(Some(client.succeeded())),
TaskOutput::UI(client) => Ok(Some(client.succeeded(is_cache_hit))),
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/turborepo-ui/src/tui/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub enum Event {
pub enum TaskResult {
Success,
Failure,
CacheHit,
}

#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
Expand Down
8 changes: 6 additions & 2 deletions crates/turborepo-ui/src/tui/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,12 @@ impl TuiTask {
}

/// Mark the task as finished
pub fn succeeded(&self) -> Vec<u8> {
self.finish(TaskResult::Success)
pub fn succeeded(&self, is_cache_hit: bool) -> Vec<u8> {
if is_cache_hit {
self.finish(TaskResult::CacheHit)
} else {
self.finish(TaskResult::Success)
}
}

/// Mark the task as finished
Expand Down
23 changes: 18 additions & 5 deletions crates/turborepo-ui/src/tui/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,26 @@ impl<'b> TaskTable<'b> {

fn finished_rows(&self) -> impl Iterator<Item = Row> + '_ {
self.tasks_by_type.finished.iter().map(move |task| {
let name = if matches!(task.result(), TaskResult::CacheHit) {
Cell::new(Text::styled(task.name(), Style::default().italic()))
} else {
Cell::new(task.name())
};

Row::new(vec![
Cell::new(task.name()),
Cell::new(match task.result() {
name,
match task.result() {
// matches Next.js (and many other CLI tools) https://github.com/vercel/next.js/blob/1a04d94aaec943d3cce93487fea3b8c8f8898f31/packages/next/src/build/output/log.ts
TaskResult::Success => Text::styled("✓", Style::default().green().bold()),
TaskResult::Failure => Text::styled("⨯", Style::default().red().bold()),
}),
TaskResult::Success => {
Cell::new(Text::styled("✓", Style::default().green().bold()))
}
TaskResult::CacheHit => {
Cell::new(Text::styled("⊙", Style::default().magenta()))
}
TaskResult::Failure => {
Cell::new(Text::styled("⨯", Style::default().red().bold()))
}
},
])
})
}
Expand Down
Loading