@@ -11,6 +11,7 @@ import (
1111 "errors"
1212 "fmt"
1313 "io"
14+ "io/ioutil"
1415 "log"
1516 "os"
1617 "os/exec"
@@ -373,25 +374,42 @@ type DiggerExecutor struct {
373374}
374375
375376type CommandRun interface {
376- Run (workingDir string , shell string , command string ) (string , string , error )
377+ Run (workingDir string , shell string , commands [] string ) (string , string , error )
377378}
378379
379380type CommandRunner struct {
380381}
381382
382- func (c CommandRunner ) Run (workingDir string , shell string , command string ) (string , string , error ) {
383+ func (c CommandRunner ) Run (workingDir string , shell string , commands []string ) (string , string , error ) {
384+ var args []string
383385 if shell == "" {
384386 shell = "bash"
387+ args = []string {"-eo" , "pipefail" }
385388 }
386- cmd := exec .Command (shell , "-c" , command )
389+
390+ scriptFile , err := ioutil .TempFile ("" , "run-script" )
391+ if err != nil {
392+ return "" , "" , fmt .Errorf ("error creating script file: %v" , err )
393+ }
394+ defer os .Remove (scriptFile .Name ())
395+
396+ for _ , command := range commands {
397+ _ , err := scriptFile .WriteString (command + "\n " )
398+ if err != nil {
399+ return "" , "" , fmt .Errorf ("error writing to script file: %v" , err )
400+ }
401+ }
402+ args = append (args , scriptFile .Name ())
403+
404+ cmd := exec .Command (shell , args ... )
387405 cmd .Dir = workingDir
388406
389407 var stdout , stderr bytes.Buffer
390408 mwout := io .MultiWriter (os .Stdout , & stdout )
391409 mwerr := io .MultiWriter (os .Stderr , & stderr )
392410 cmd .Stdout = mwout
393411 cmd .Stderr = mwerr
394- err : = cmd .Run ()
412+ err = cmd .Run ()
395413
396414 if err != nil {
397415 return stdout .String (), stderr .String (), fmt .Errorf ("error: %v" , err )
@@ -458,8 +476,13 @@ func (d DiggerExecutor) Plan(prNumber int) error {
458476 d .CIService .PublishComment (prNumber , comment )
459477 }
460478 if step .Action == "run" {
461- stdout , stderr , err := d .CommandRunner .Run (d .ProjectPath , step .Shell , step .Value )
462- log .Printf ("Running %v for **%v**\n %v%v" , step .Value , d .ProjectLock .LockId (), stdout , stderr )
479+ var commands []string
480+ if os .Getenv ("ACTIVATE_VENV" ) == "true" {
481+ commands = append (commands , fmt .Sprintf ("source %v/.venv/bin/activate" , os .Getenv ("GITHUB_WORKSPACE" )))
482+ }
483+ commands = append (commands , step .Value )
484+ log .Printf ("Running %v for **%v**\n " , step .Value , d .ProjectLock .LockId ())
485+ _ , _ , err := d .CommandRunner .Run (d .ProjectPath , step .Shell , commands )
463486 if err != nil {
464487 return fmt .Errorf ("error running command: %v" , err )
465488 }
@@ -522,8 +545,13 @@ func (d DiggerExecutor) Apply(prNumber int) error {
522545 }
523546 }
524547 if step .Action == "run" {
525- stdout , stderr , err := d .CommandRunner .Run (d .ProjectPath , step .Shell , step .Value )
526- log .Printf ("Running %v for **%v**\n %v%v" , step .Value , d .ProjectLock .LockId (), stdout , stderr )
548+ var commands []string
549+ if os .Getenv ("ACTIVATE_VENV" ) == "true" {
550+ commands = append (commands , fmt .Sprintf ("source %v/.venv/bin/activate" , os .Getenv ("GITHUB_WORKSPACE" )))
551+ }
552+ commands = append (commands , step .Value )
553+ log .Printf ("Running %v for **%v**\n " , step .Value , d .ProjectLock .LockId ())
554+ _ , _ , err := d .CommandRunner .Run (d .ProjectPath , step .Shell , commands )
527555 if err != nil {
528556 return fmt .Errorf ("error running command: %v" , err )
529557 }
0 commit comments