Skip to content

Commit c815b62

Browse files
nblair2GhostofGoes
authored andcommitted
chore: change scorch info output to json
1 parent 289a552 commit c815b62

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

src/go/api/scorch/app.go

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"os"
1111
"os/exec"
1212
"path/filepath"
13-
"strings"
1413
"time"
1514

1615
"phenix/api/scorch/scorchexe"
@@ -343,34 +342,37 @@ func (this Scorch) recordInfo(runID int, runDir string, md store.ConfigMetadata,
343342
return fmt.Errorf("getting minimega version: %w", err)
344343
}
345344

346-
info := []string{
347-
"Experiment Name: %s",
348-
"Experiment Tags: %s",
349-
"Scorch Run Name: %s",
350-
"Start Time: %s",
351-
"End Time: %s",
352-
"Phenix Version: %s %s %s",
353-
"Minimega Version: %s",
354-
}
355-
356-
body := fmt.Sprintf(
357-
strings.Join(info, "\n"),
358-
md.Name,
359-
md.Annotations["phenix.workflow/tags"],
360-
this.md.RunName(runID),
361-
startTime.Format(time.RFC3339),
362-
time.Now().UTC().Format(time.RFC3339),
363-
version.Commit, version.Tag, version.Date,
364-
mmVersion,
365-
)
345+
info := map[string]any{
346+
"experiment": map[string]string{
347+
"name": md.Name,
348+
"tags": md.Annotations["phenix.workflow/tags"],
349+
},
350+
"run": map[string]any{
351+
"name": this.md.RunName(runID),
352+
"index": runID,
353+
},
354+
"start": startTime.Format(time.RFC3339),
355+
"end": time.Now().UTC().Format(time.RFC3339),
356+
"phenix_version": map[string]string{
357+
"commit": version.Commit,
358+
"tag": version.Tag,
359+
"date": version.Date,
360+
},
361+
"minimega_version": mmVersion,
362+
}
366363

367-
fileName := fmt.Sprintf("info-scorch-run-%d_%s.txt", runID, startTime.Format("2006-01-02T15-04-05Z0700"))
364+
fileName := fmt.Sprintf("%s-scorch-run-%d-%s.json", md.Name, runID, startTime.Format("2006-01-02T15-04-05Z0700"))
368365

369366
if err := os.MkdirAll(runDir, 0755); err != nil {
370367
return fmt.Errorf("creating %s directory for scorch run %d: %w", runDir, runID, err)
371368
}
372369

373-
if err := os.WriteFile(filepath.Join(runDir, fileName), []byte(body), 0644); err != nil {
370+
body, err := json.MarshalIndent(info, "", " ")
371+
if err != nil {
372+
return fmt.Errorf("marshalling scorch run info: %w", err)
373+
}
374+
375+
if err := os.WriteFile(filepath.Join(runDir, fileName), body, 0644); err != nil {
374376
return fmt.Errorf("writing scorch information file (%s): %w", fileName, err)
375377
}
376378

0 commit comments

Comments
 (0)