Add independent native run report delivery
This commit is contained in:
@@ -2,7 +2,6 @@ package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
@@ -17,7 +16,6 @@ import (
|
||||
appconfig "gitea.maximumdirect.net/eric/scriptorium/internal/config"
|
||||
"gitea.maximumdirect.net/eric/scriptorium/internal/defaults"
|
||||
renderformat "gitea.maximumdirect.net/eric/scriptorium/internal/format"
|
||||
executionreport "gitea.maximumdirect.net/eric/scriptorium/internal/report"
|
||||
"go.maximumdirect.net/commandkit"
|
||||
"go.maximumdirect.net/configkit"
|
||||
"go.maximumdirect.net/promptkit"
|
||||
@@ -144,53 +142,6 @@ func runCommand(args []string, stdout, stderr io.Writer) int {
|
||||
return executeRun(cfg, req, engine.Run, stdout, stderr)
|
||||
}
|
||||
|
||||
func executeRun(cfg *runConfig, req promptkit.RunRequest, run func(context.Context, promptkit.RunRequest) (*promptkit.RunResult, error), stdout, stderr io.Writer) int {
|
||||
var collector *executionreport.Collector
|
||||
if cfg.executionReportPath != "" {
|
||||
collector = executionreport.NewCollector()
|
||||
req.Observer = collector.Observe
|
||||
}
|
||||
req.OperationTimeout = cfg.runTimeout
|
||||
res, runErr := run(context.Background(), req)
|
||||
if runErr != nil {
|
||||
if errors.Is(runErr, promptkit.ErrOperationTimeout) {
|
||||
fmt.Fprintln(stderr, "run error: execution deadline exceeded")
|
||||
} else {
|
||||
fmt.Fprintln(stderr, runErrorMessage(runErr))
|
||||
}
|
||||
}
|
||||
|
||||
outputFailed := false
|
||||
if runErr == nil {
|
||||
if err := writeOutput(stdout, cfg.outputPath, res.Artifact.Body); err != nil {
|
||||
fmt.Fprintf(stderr, "output write error: %v\n", err)
|
||||
outputFailed = true
|
||||
}
|
||||
}
|
||||
reportFailed := false
|
||||
if collector != nil {
|
||||
if value := collector.Snapshot(); value == nil {
|
||||
fmt.Fprintln(stderr, "execution report not produced: no terminal observation")
|
||||
} else if err := writeExecutionReport(cfg.executionReportPath, value); err != nil {
|
||||
fmt.Fprintf(stderr, "execution report write error: %v\n", err)
|
||||
reportFailed = true
|
||||
}
|
||||
}
|
||||
if runErr != nil || outputFailed || reportFailed {
|
||||
return ExitRuntimeError
|
||||
}
|
||||
|
||||
printSummary(stderr, res)
|
||||
return determineExitCode(nil, res)
|
||||
}
|
||||
|
||||
func writeExecutionReport(path string, value *executionreport.Execution) error {
|
||||
data, err := json.Marshal(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(path, append(data, '\n'), 0644)
|
||||
}
|
||||
|
||||
func renderCommand(args []string, stdout, stderr io.Writer) int {
|
||||
cfg, err := parseRenderArgs(args)
|
||||
|
||||
Reference in New Issue
Block a user