@@ -6,10 +6,12 @@ import (
66 "io"
77 "os"
88 "os/exec"
9+ "path"
910 "strings"
1011 "sync"
1112
1213 "github.com/function61/turbobob/pkg/bobfile"
14+ "github.com/function61/turbobob/pkg/dockertag"
1315)
1416
1517func passthroughStdoutAndStderr (cmd * exec.Cmd ) * exec.Cmd {
@@ -117,3 +119,38 @@ func firstNonEmpty(a, b string) string {
117119 return b
118120 }
119121}
122+
123+ // write image tags as Markdown to GitHub actions's workflow summary so it's easy from their UI to spot
124+ // which images were published as result of the build.
125+ func githubStepSummaryWriteImages (stepSummaryFilename string , images []imageBuildOutput ) error {
126+ withErr := func (err error ) error { return fmt .Errorf ("githubStepSummaryWriteImages: %w" , err ) }
127+
128+ stepSummaryFile , err := os .OpenFile (stepSummaryFilename , os .O_APPEND | os .O_WRONLY | os .O_CREATE , 0600 )
129+ if err != nil {
130+ return withErr (err )
131+ }
132+ defer stepSummaryFile .Close ()
133+
134+ return githubStepSummaryWriteImagesWithWriter (stepSummaryFile , images )
135+ }
136+
137+ func githubStepSummaryWriteImagesWithWriter (stepSummaryFile io.Writer , images []imageBuildOutput ) error {
138+ lines := []string {}
139+ for _ , image := range images {
140+ parsed := dockertag .Parse (image .tag )
141+ if parsed == nil {
142+ return fmt .Errorf ("failed to parse docker tag: %s" , image .tag )
143+ }
144+
145+ // "fn61/varasto" => "varasto"
146+ imageBasename := path .Base (parsed .Repository )
147+
148+ lines = append (lines , "## Image: " + imageBasename , "" , "```" , image .tag , "```" , "" , "" )
149+ }
150+
151+ if _ , err := stepSummaryFile .Write ([]byte (strings .Join (lines , "\n " ))); err != nil {
152+ return err
153+ }
154+
155+ return nil
156+ }
0 commit comments