这是indexloc提供的服务,不要输入任何密码
Skip to content

fix: output line with --output-logs=new-only should reflect actual behavior #982

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

Merged
merged 10 commits into from
Apr 7, 2022
33 changes: 16 additions & 17 deletions cli/internal/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions cli/scripts/e2e/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ function runSmokeTests<T>(

assert.ok(
sinceCommandSecondRunOutput.includes(
`b:build: cache hit, replaying output ${getHashFromOutput(
`b:build: cache hit, suppressing output ${getHashFromOutput(
sinceCommandSecondRunOutput,
"b#build"
)}`
Expand All @@ -290,7 +290,7 @@ function runSmokeTests<T>(

assert.ok(
sinceCommandSecondRunOutput.includes(
`a:test: cache hit, replaying output ${getHashFromOutput(
`a:test: cache hit, suppressing output ${getHashFromOutput(
sinceCommandSecondRunOutput,
"a#test"
)}`
Expand Down