@@ -6,10 +6,12 @@ import (
6
6
"io"
7
7
"os"
8
8
"os/exec"
9
+ "path"
9
10
"strings"
10
11
"sync"
11
12
12
13
"github.com/function61/turbobob/pkg/bobfile"
14
+ "github.com/function61/turbobob/pkg/dockertag"
13
15
)
14
16
15
17
func passthroughStdoutAndStderr (cmd * exec.Cmd ) * exec.Cmd {
@@ -117,3 +119,38 @@ func firstNonEmpty(a, b string) string {
117
119
return b
118
120
}
119
121
}
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