@@ -17,6 +17,7 @@ import (
1717 batcheslib "github.com/sourcegraph/sourcegraph/lib/batches"
1818 "github.com/sourcegraph/src-cli/internal/batches/git"
1919 "github.com/sourcegraph/src-cli/internal/batches/log"
20+ "github.com/sourcegraph/src-cli/internal/batches/template"
2021 "github.com/sourcegraph/src-cli/internal/batches/workspace"
2122
2223 yamlv3 "gopkg.in/yaml.v3"
@@ -33,7 +34,7 @@ type stepExecutionResult struct {
3334 Outputs map [string ]interface {} `json:"outputs"`
3435 // PreviousStepResult is the StepResult of the step before Step, if Step !=
3536 // 0.
36- PreviousStepResult StepResult `json:"previousStepResult"`
37+ PreviousStepResult template. StepResult `json:"previousStepResult"`
3738}
3839
3940type executionResult struct {
@@ -86,7 +87,7 @@ func runSteps(ctx context.Context, opts *executionOpts) (result executionResult,
8687 Outputs : make (map [string ]interface {}),
8788 Path : opts .task .Path ,
8889 }
89- previousStepResult StepResult
90+ previousStepResult template. StepResult
9091 startStep int
9192 )
9293
@@ -122,11 +123,11 @@ func runSteps(ctx context.Context, opts *executionOpts) (result executionResult,
122123 for i := startStep ; i < len (opts .task .Steps ); i ++ {
123124 step := opts .task .Steps [i ]
124125
125- stepContext := StepContext {
126+ stepContext := template. StepContext {
126127 BatchChange : * opts .task .BatchChangeAttributes ,
127128 Repository : * opts .task .Repository ,
128129 Outputs : execResult .Outputs ,
129- Steps : StepsContext {
130+ Steps : template. StepsContext {
130131 Path : execResult .Path ,
131132 Changes : previousStepResult .Files ,
132133 },
@@ -145,7 +146,7 @@ func runSteps(ctx context.Context, opts *executionOpts) (result executionResult,
145146 }
146147 }
147148
148- cond , err := evalStepCondition (step .IfCondition (), & stepContext )
149+ cond , err := template . EvalStepCondition (step .IfCondition (), & stepContext )
149150 if err != nil {
150151 return execResult , nil , errors .Wrap (err , "evaluating step condition" )
151152 }
@@ -172,7 +173,7 @@ func runSteps(ctx context.Context, opts *executionOpts) (result executionResult,
172173 return execResult , nil , errors .Wrap (err , "getting changed files in step" )
173174 }
174175
175- result := StepResult {Files : changes , Stdout : & stdoutBuffer , Stderr : & stderrBuffer }
176+ result := template. StepResult {Files : changes , Stdout : & stdoutBuffer , Stderr : & stderrBuffer }
176177
177178 // Set stepContext.Step to current step's results before rendering outputs
178179 stepContext .Step = result
@@ -220,7 +221,7 @@ func executeSingleStep(
220221 i int ,
221222 step batcheslib.Step ,
222223 imageDigest string ,
223- stepContext * StepContext ,
224+ stepContext * template. StepContext ,
224225) (bytes.Buffer , bytes.Buffer , error ) {
225226 // ----------
226227 // PREPARATION
@@ -259,7 +260,7 @@ func executeSingleStep(
259260 }
260261
261262 // Render the step.Env variables as templates.
262- env , err := renderStepMap (stepEnv , stepContext )
263+ env , err := template . RenderStepMap (stepEnv , stepContext )
263264 if err != nil {
264265 return bytes.Buffer {}, bytes.Buffer {}, errors .Wrap (err , "parsing step environment" )
265266 }
@@ -334,11 +335,11 @@ func executeSingleStep(
334335 return stdoutBuffer , stderrBuffer , nil
335336}
336337
337- func setOutputs (stepOutputs batcheslib.Outputs , global map [string ]interface {}, stepCtx * StepContext ) error {
338+ func setOutputs (stepOutputs batcheslib.Outputs , global map [string ]interface {}, stepCtx * template. StepContext ) error {
338339 for name , output := range stepOutputs {
339340 var value bytes.Buffer
340341
341- if err := renderStepTemplate ("outputs-" + name , output .Value , & value , stepCtx ); err != nil {
342+ if err := template . RenderStepTemplate ("outputs-" + name , output .Value , & value , stepCtx ); err != nil {
342343 return errors .Wrap (err , "parsing step run" )
343344 }
344345
@@ -414,9 +415,9 @@ func probeImageForShell(ctx context.Context, image string) (shell, tempfile stri
414415
415416// createFilesToMount creates temporary files with the contents of Step.Files
416417// that are to be mounted into the container that executes the step.
417- func createFilesToMount (tempDir string , step batcheslib.Step , stepContext * StepContext ) (map [string ]* os.File , func (), error ) {
418+ func createFilesToMount (tempDir string , step batcheslib.Step , stepContext * template. StepContext ) (map [string ]* os.File , func (), error ) {
418419 // Parse and render the step.Files.
419- files , err := renderStepMap (step .Files , stepContext )
420+ files , err := template . RenderStepMap (step .Files , stepContext )
420421 if err != nil {
421422 return nil , nil , errors .Wrap (err , "parsing step files" )
422423 }
@@ -455,7 +456,7 @@ func createFilesToMount(tempDir string, step batcheslib.Step, stepContext *StepC
455456// createRunScriptFile creates a temporary file and renders stepRun into it.
456457//
457458// It returns the location of the file, its content, a function to cleanup the file and possible errors.
458- func createRunScriptFile (ctx context.Context , tempDir string , stepRun string , stepCtx * StepContext ) (string , string , func (), error ) {
459+ func createRunScriptFile (ctx context.Context , tempDir string , stepRun string , stepCtx * template. StepContext ) (string , string , func (), error ) {
459460 // Set up a temporary file on the host filesystem to contain the
460461 // script.
461462 runScriptFile , err := ioutil .TempFile (tempDir , "" )
@@ -468,7 +469,7 @@ func createRunScriptFile(ctx context.Context, tempDir string, stepRun string, st
468469 // temp file we just created.
469470 var runScript bytes.Buffer
470471 out := io .MultiWriter (& runScript , runScriptFile )
471- if err := renderStepTemplate ("step-run" , stepRun , out , stepCtx ); err != nil {
472+ if err := template . RenderStepTemplate ("step-run" , stepRun , out , stepCtx ); err != nil {
472473 return "" , "" , nil , errors .Wrap (err , "parsing step run" )
473474 }
474475
0 commit comments