Skip to content

Commit 0fa420e

Browse files
committed
deploy client: write GitHub step summary
1 parent 178879f commit 0fa420e

File tree

2 files changed

+52
-12
lines changed

2 files changed

+52
-12
lines changed

pkg/deployclient/deployclient.go

+42-12
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8+
"os"
89
"strings"
910
"time"
1011

@@ -191,18 +192,6 @@ func (d *Deployer) Deploy(ctx context.Context, cfg *Config, deployRequest *pb.De
191192
deployRequest.ID = deployStatus.GetRequest().GetID()
192193
telemetry.AddDeploymentRequestSpanAttributes(span, deployStatus.GetRequest())
193194
telemetry.AddDeploymentRequestSpanAttributes(requestSpan, deployStatus.GetRequest())
194-
traceID := telemetry.TraceID(requestContext)
195-
196-
urlPrefix := "https://" + strings.Split(cfg.DeployServerURL, ":")[0]
197-
log.Infof("Deployment information:")
198-
log.Infof("---")
199-
log.Infof("id...........: %s", deployRequest.GetID())
200-
if len(traceID) > 0 {
201-
log.Infof("tracing......: %s", cfg.TracingDashboardURL+traceID)
202-
}
203-
log.Infof("debug logs...: %s", logproxy.MakeURL(urlPrefix, deployRequest.GetID(), deployRequest.GetTime().AsTime(), deployRequest.Cluster))
204-
log.Infof("deadline.....: %s", deployRequest.GetDeadline().AsTime().Local())
205-
log.Infof("---")
206195

207196
return nil
208197
}
@@ -217,12 +206,48 @@ func (d *Deployer) Deploy(ctx context.Context, cfg *Config, deployRequest *pb.De
217206
return err
218207
}
219208

209+
traceID := telemetry.TraceID(ctx)
210+
211+
// Print information to standard output
212+
urlPrefix := "https://" + strings.Split(cfg.DeployServerURL, ":")[0]
213+
log.Infof("Deployment information:")
214+
log.Infof("---")
215+
log.Infof("id...........: %s", deployRequest.GetID())
216+
log.Infof("tracing......: %s", cfg.TracingDashboardURL+traceID)
217+
log.Infof("debug logs...: %s", logproxy.MakeURL(urlPrefix, deployRequest.GetID(), deployRequest.GetTime().AsTime(), deployRequest.Cluster))
218+
log.Infof("deadline.....: %s", deployRequest.GetDeadline().AsTime().Local())
219+
log.Infof("---")
220+
221+
// If running in GitHub actions, print a markdown summary
222+
summaryFile, err := os.OpenFile(os.Getenv("GITHUB_STEP_SUMMARY"), os.O_APPEND|os.O_WRONLY, 0644)
223+
summary := func(format string, a ...any) {
224+
if summaryFile == nil {
225+
return
226+
}
227+
_, _ = fmt.Fprintf(summaryFile, format+"\n", a...)
228+
}
229+
finalStatus := func(st *pb.DeploymentStatus) {
230+
summary("* Finished at: %s", st.Timestamp())
231+
summary("%c Final status: *%s* / %s", deployStatus.GetState().StatusEmoji(), deployStatus.GetState(), deployStatus.GetMessage())
232+
}
233+
if err == nil {
234+
defer summaryFile.Close()
235+
}
236+
237+
summary("# 🚀 NAIS deploy")
238+
summary("* Detailed trace: [%s](%s)", traceID, cfg.TracingDashboardURL+traceID)
239+
summary("* Request ID: %s", deployRequest.GetID())
240+
summary("* Started at: %s", time.Now().Local())
241+
summary("* Deadline: %s", deployRequest.GetDeadline().AsTime().Local())
242+
220243
if deployStatus.GetState().Finished() {
244+
finalStatus(deployStatus)
221245
logDeployStatus(deployStatus)
222246
return ErrorStatus(deployStatus)
223247
}
224248

225249
if !cfg.Wait {
250+
finalStatus(deployStatus)
226251
logDeployStatus(deployStatus)
227252
return nil
228253
}
@@ -243,6 +268,7 @@ func (d *Deployer) Deploy(ctx context.Context, cfg *Config, deployRequest *pb.De
243268
return err
244269
})
245270
if err != nil {
271+
summary("❌ lost connection to NAIS deploy", deployStatus.GetState(), deployStatus.GetMessage())
246272
return ErrorWrap(ExitUnavailable, err)
247273
}
248274

@@ -254,6 +280,7 @@ func (d *Deployer) Deploy(ctx context.Context, cfg *Config, deployRequest *pb.De
254280
log.Warnf(formatGrpcError(err))
255281
break
256282
} else {
283+
summary("❌ lost connection to NAIS deploy", deployStatus.GetState(), deployStatus.GetMessage())
257284
return Errorf(ExitUnavailable, formatGrpcError(err))
258285
}
259286
}
@@ -262,14 +289,17 @@ func (d *Deployer) Deploy(ctx context.Context, cfg *Config, deployRequest *pb.De
262289
log.Warnf("NAIS deploy has been restarted. Re-sending deployment request...")
263290
err = sendDeploymentRequest()
264291
if err != nil {
292+
summary("❌ lost connection to NAIS deploy", deployStatus.GetState(), deployStatus.GetMessage())
265293
return err
266294
}
267295
} else if deployStatus.GetState().Finished() {
296+
finalStatus(deployStatus)
268297
return ErrorStatus(deployStatus)
269298
}
270299
}
271300
}
272301

302+
summary("❌ timeout", deployStatus.GetState(), deployStatus.GetMessage())
273303
return Errorf(ExitTimeout, "deployment timed out: %w", ctx.Err())
274304
}
275305

pkg/pb/status.go

+10
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ func (x DeploymentState) IsError() bool {
2828
return true
2929
}
3030

31+
func (x DeploymentState) StatusEmoji() rune {
32+
if x.IsError() {
33+
return '❌'
34+
}
35+
if x.Finished() {
36+
return '✅'
37+
}
38+
return '❓'
39+
}
40+
3141
func NewErrorStatus(req *DeploymentRequest, err error) *DeploymentStatus {
3242
return &DeploymentStatus{
3343
Request: req,

0 commit comments

Comments
 (0)