@@ -3,6 +3,7 @@ package main
33import (
44 "errors"
55 "fmt"
6+ "io"
67 "os"
78 "os/exec"
89 "path/filepath"
@@ -35,7 +36,27 @@ func runBuilder(builder BuilderSpec, buildCtx *BuildContext, opDesc string, cmdT
3536 return errWd
3637 }
3738
38- printHeading (fmt .Sprintf ("%s/%s (%s)" , builder .Name , opDesc , builderCommandToHumanReadable (cmdToRun )))
39+ builderNameOpDesc := fmt .Sprintf ("%s/%s" , builder .Name , opDesc )
40+
41+ switch must (parseBuilderUsesType (builder .Uses )) {
42+ case builderUsesTypeImage :
43+ // the "$ docker run ..." later would do an implicit pull, but let's do an explicit pull
44+ // here in order to nicely put the download progress output in its own log line group
45+ if err := withLogLineGroup (fmt .Sprintf ("%s > pull" , builderNameOpDesc ), func () error {
46+ return dockerPullIfRequired (builderImageName (buildCtx .Bobfile , builder ))
47+ }); err != nil {
48+ return err
49+ }
50+ case builderUsesTypeDockerfile :
51+ // no-op (doesn't need a pull)
52+ default :
53+ panic ("unknown builderType" )
54+ }
55+
56+ // empty work just to emit a "starting" log group. this log group is important because if the
57+ // command-to-run itself doesn't create log groups (to which we could insert script name), then
58+ // script name won't be visible at all in none of the group names
59+ _ = withLogLineGroup (fmt .Sprintf ("%s > starting %s" , builderNameOpDesc , builderCommandToHumanReadable (cmdToRun )), func () error { return nil })
3960
4061 buildArgs := []string {
4162 "docker" ,
@@ -78,7 +99,23 @@ func runBuilder(builder BuilderSpec, buildCtx *BuildContext, opDesc string, cmdT
7899 }
79100
80101 //nolint:gosec // ok
81- buildCmd := passthroughStdoutAndStderr (exec .Command (buildArgs [0 ], buildArgs [1 :]... ))
102+ buildCmd := exec .Command (buildArgs [0 ], buildArgs [1 :]... )
103+ buildCmd .Stdout = newLineSplitterTee (io .Discard , func (line string ) {
104+ lineMaybeModified := func () string {
105+ // for each log line group, add "breadcrumb prefix" of builder / operation description.
106+ // example group name: "staticAnalysis" => "default/build > staticAnalysis"
107+ if strings .HasPrefix (line , "::group::" ) {
108+ originalGroupName := line [len ("::group::" ):]
109+
110+ return fmt .Sprintf ("::group::%s > %s" , builderNameOpDesc , originalGroupName )
111+ } else {
112+ return line // as-is
113+ }
114+ }()
115+
116+ _ , _ = os .Stdout .Write ([]byte (lineMaybeModified + "\n " )) // need to add newline back
117+ })
118+ buildCmd .Stderr = os .Stderr
82119
83120 if err := buildCmd .Run (); err != nil {
84121 return err
@@ -435,7 +472,7 @@ func buildEntry() *cobra.Command {
435472 Args : cobra .NoArgs ,
436473 Run : func (cmd * cobra.Command , args []string ) {
437474 osutil .ExitIfError (func () error {
438- if os . Getenv ( "GITHUB_ACTIONS" ) != "true" {
475+ if ! runningInGitHubActions () {
439476 return errors .New ("expecting GITHUB_ACTIONS=true" )
440477 }
441478
0 commit comments