@@ -13,6 +13,7 @@ import (
1313
1414 "github.com/cockroachdb/errors"
1515 "github.com/hashicorp/go-multierror"
16+
1617 batcheslib "github.com/sourcegraph/sourcegraph/lib/batches"
1718 "github.com/sourcegraph/sourcegraph/lib/batches/git"
1819 "github.com/sourcegraph/sourcegraph/lib/batches/template"
@@ -64,27 +65,27 @@ type executionOpts struct {
6465
6566 tempDir string
6667
67- logger log.TaskLogger
68- reportProgress func (string )
68+ logger log.TaskLogger
6969
70- newUiStdoutWriter func (context.Context , * Task , int ) io.WriteCloser
71- newUiStderrWriter func (context.Context , * Task , int ) io.WriteCloser
70+ ui StepsExecutionUI
7271}
7372
7473func runSteps (ctx context.Context , opts * executionOpts ) (result executionResult , stepResults []stepExecutionResult , err error ) {
75- opts .reportProgress ( "Downloading archive" )
74+ opts .ui . ArchiveDownloadStarted ( )
7675 err = opts .task .Archive .Ensure (ctx )
7776 if err != nil {
7877 return executionResult {}, nil , errors .Wrap (err , "fetching repo" )
7978 }
8079 defer opts .task .Archive .Close ()
80+ opts .ui .ArchiveDownloadFinished ()
8181
82- opts .reportProgress ( "Initializing workspace" )
82+ opts .ui . WorkspaceInitializationStarted ( )
8383 workspace , err := opts .wc .Create (ctx , opts .task .Repository , opts .task .Steps , opts .task .Archive )
8484 if err != nil {
8585 return executionResult {}, nil , errors .Wrap (err , "creating workspace" )
8686 }
8787 defer workspace .Close (ctx )
88+ opts .ui .WorkspaceInitializationFinished ()
8889
8990 var (
9091 execResult = executionResult {
@@ -118,12 +119,7 @@ func runSteps(ctx context.Context, opts *executionOpts) (result executionResult,
118119 return execResult , stepResults , nil
119120 }
120121
121- switch startStep {
122- case 1 :
123- opts .reportProgress ("Skipping step 1. Found cached result." )
124- default :
125- opts .reportProgress (fmt .Sprintf ("Skipping steps 1 to %d. Found cached results." , startStep ))
126- }
122+ opts .ui .SkippingStepsUpto (startStep )
127123 }
128124
129125 for i := startStep ; i < len (opts .task .Steps ); i ++ {
@@ -157,9 +153,10 @@ func runSteps(ctx context.Context, opts *executionOpts) (result executionResult,
157153 return execResult , nil , errors .Wrap (err , "evaluating step condition" )
158154 }
159155 if ! cond {
160- opts .reportProgress ( fmt . Sprintf ( "Skipping step %d" , i + 1 ) )
156+ opts .ui . StepSkipped ( i + 1 )
161157 continue
162158 }
159+
163160 // We need to grab the digest for the exact image we're using.
164161 img , err := opts .ensureImage (ctx , step .Container )
165162 if err != nil {
@@ -204,14 +201,18 @@ func runSteps(ctx context.Context, opts *executionOpts) (result executionResult,
204201 }
205202 stepResults = append (stepResults , stepResult )
206203 previousStepResult = result
204+
205+ opts .ui .StepFinished (i + 1 , stepResult .Diff , result .Files , stepResult .Outputs )
207206 }
208207
209- opts .reportProgress ( "Calculating diff" )
208+ opts .ui . CalculatingDiffStarted ( )
210209 diffOut , err := workspace .Diff (ctx )
211210 if err != nil {
212211 return execResult , nil , errors .Wrap (err , "git diff failed" )
213212 }
214213
214+ opts .ui .CalculatingDiffFinished ()
215+
215216 execResult .Diff = string (diffOut )
216217 execResult .ChangedFiles = previousStepResult .Files
217218
@@ -232,7 +233,7 @@ func executeSingleStep(
232233 // ----------
233234 // PREPARATION
234235 // ----------
235- opts .reportProgress ( fmt . Sprintf ( "Preparing step %d" , i + 1 ) )
236+ opts .ui . StepPreparing ( i + 1 )
236237
237238 cidFile , cleanup , err := createCidFile (ctx , opts .tempDir , util .SlugForRepo (opts .task .Repository .Name , opts .task .Repository .Rev ()))
238239 if err != nil {
@@ -274,7 +275,7 @@ func executeSingleStep(
274275 // ----------
275276 // EXECUTION
276277 // ----------
277- opts .reportProgress ( runScript )
278+ opts .ui . StepStarted ( i + 1 , runScript )
278279
279280 workspaceOpts , err := workspace .DockerRunOpts (ctx , workDir )
280281 if err != nil {
@@ -316,8 +317,8 @@ func executeSingleStep(
316317
317318 writerCtx , writerCancel := context .WithCancel (ctx )
318319 defer writerCancel ()
319- uiStdoutWriter := opts .newUiStdoutWriter (writerCtx , opts .task , i )
320- uiStderrWriter := opts .newUiStderrWriter (writerCtx , opts .task , i )
320+ uiStdoutWriter := opts .ui . StepStdoutWriter (writerCtx , opts .task , i )
321+ uiStderrWriter := opts .ui . StepStderrWriter (writerCtx , opts .task , i )
321322 defer func () {
322323 uiStdoutWriter .Close ()
323324 uiStderrWriter .Close ()
0 commit comments