diff --git a/cli/internal/run/run.go b/cli/internal/run/run.go index 01954ba159c20..307b8ca4aa1b4 100644 --- a/cli/internal/run/run.go +++ b/cli/internal/run/run.go @@ -796,26 +796,18 @@ func (c *RunCommand) executeDryRun(engine *core.Scheduler, g *completeGraph, rs } // Replay logs will try to replay logs back to the stdout -func replayLogs(logger hclog.Logger, prefixUi cli.Ui, runOptions *RunOptions, logFileName, hash string, wg *sync.WaitGroup, silent bool, outputLogsMode LogsMode) { +func replayLogs(logger hclog.Logger, output cli.Ui, runOptions *RunOptions, logFileName, hash string, wg *sync.WaitGroup) { defer wg.Done() logger.Debug("start replaying logs") f, err := os.Open(filepath.Join(runOptions.cwd, logFileName)) - if err != nil && !silent { - prefixUi.Warn(fmt.Sprintf("error reading logs: %v", err)) + if err != nil { + output.Warn(fmt.Sprintf("error reading logs: %v", err)) logger.Error(fmt.Sprintf("error reading logs: %v", err.Error())) } defer f.Close() - if outputLogsMode != NoLogs { - scan := bufio.NewScanner(f) - if outputLogsMode == HashLogs { - //Writing to Stdout only the "cache hit, replaying output" line - scan.Scan() - prefixUi.Output(string(scan.Bytes())) - } else { - for scan.Scan() { - prefixUi.Output(string(scan.Bytes())) //Writing to Stdout - } - } + scan := bufio.NewScanner(f) + for scan.Scan() { + output.Output(string(scan.Bytes())) //Writing to Stdout } logger.Debug("finish replaying logs") } @@ -912,9 +904,16 @@ func (e *execContext) exec(pt *packageTask) error { if err != nil { targetUi.Error(fmt.Sprintf("error fetching from cache: %s", err)) } else if hit { - if e.rs.Opts.stream && fs.FileExists(filepath.Join(e.rs.Opts.cwd, logFileName)) { - e.logReplayWaitGroup.Add(1) - go replayLogs(targetLogger, e.ui, e.rs.Opts, logFileName, hash, &e.logReplayWaitGroup, false, e.rs.Opts.cacheHitLogsMode) + switch e.rs.Opts.cacheHitLogsMode { + case HashLogs: + targetUi.Output(fmt.Sprintf("cache hit, suppressing output %s", ui.Dim(hash))) + case FullLogs: + if e.rs.Opts.stream && fs.FileExists(filepath.Join(e.rs.Opts.cwd, logFileName)) { + e.logReplayWaitGroup.Add(1) + go replayLogs(targetLogger, e.ui, e.rs.Opts, logFileName, hash, &e.logReplayWaitGroup) + } + default: + // NoLogs, do not output anything } targetLogger.Debug("done", "status", "complete", "duration", time.Since(cmdTime)) tracer(TargetCached, nil) diff --git a/cli/scripts/e2e/e2e.ts b/cli/scripts/e2e/e2e.ts index 1ed3b901efe8a..ec1c902e68f6d 100644 --- a/cli/scripts/e2e/e2e.ts +++ b/cli/scripts/e2e/e2e.ts @@ -280,7 +280,7 @@ function runSmokeTests( assert.ok( sinceCommandSecondRunOutput.includes( - `b:build: cache hit, replaying output ${getHashFromOutput( + `b:build: cache hit, suppressing output ${getHashFromOutput( sinceCommandSecondRunOutput, "b#build" )}` @@ -290,7 +290,7 @@ function runSmokeTests( assert.ok( sinceCommandSecondRunOutput.includes( - `a:test: cache hit, replaying output ${getHashFromOutput( + `a:test: cache hit, suppressing output ${getHashFromOutput( sinceCommandSecondRunOutput, "a#test" )}`