Run processing from the prepared invocation
This commit is contained in:
@@ -38,9 +38,16 @@ type runtimePreparationError struct{ cause error }
|
||||
func (e *runtimePreparationError) Error() string { return e.cause.Error() }
|
||||
func (e *runtimePreparationError) Unwrap() error { return e.cause }
|
||||
|
||||
func loadProcessInputs(ctx context.Context, input processInput, mode commandkit.ReportingMode) (*processInputs, error) {
|
||||
func checkQuietDestination(input processInput, mode commandkit.ReportingMode) error {
|
||||
if mode == commandkit.ReportingModeQuiet && input.Output.Value == "" {
|
||||
return nil, fmt.Errorf("quiet processing requires an output file or /dev/null")
|
||||
return fmt.Errorf("quiet processing requires an output file or /dev/null")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func loadProcessInputs(ctx context.Context, input processInput, mode commandkit.ReportingMode) (*processInputs, error) {
|
||||
if err := checkQuietDestination(input, mode); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selection := ckconfig.Selection{Config: input.Config, Overlay: input.Overlay, Overrides: input.Overrides}
|
||||
acquired, err := acquireApplication(ctx, selection, acquisitionInput{GlossaryFiles: input.GlossaryFiles})
|
||||
@@ -81,13 +88,46 @@ func loadProcessInputs(ctx context.Context, input processInput, mode commandkit.
|
||||
|
||||
// preparedProcess groups the output resources and the facts needed for reports.
|
||||
type preparedProcess struct {
|
||||
Prepared *preparedOutput
|
||||
RunID string
|
||||
Started time.Time
|
||||
Prepared *preparedOutput
|
||||
Invocation *preparedInvocation
|
||||
RunID string
|
||||
Started time.Time
|
||||
}
|
||||
|
||||
func prepareProcess(ctx context.Context, input processInput, loaded *processInputs, stdout io.Writer) (*preparedProcess, error) {
|
||||
type preparedInvocation struct {
|
||||
Loaded *processInputs
|
||||
Plan *preflight.Plan
|
||||
Destinations *diagnostics.CheckedDestinations
|
||||
}
|
||||
|
||||
func prepareLocal(ctx context.Context, input processInput, loaded *processInputs, stdout io.Writer) (*preparedInvocation, error) {
|
||||
cfg := &loaded.Configuration.Config.Application
|
||||
checkedBackends := make(map[string]struct{})
|
||||
inspectProfile := func(ctx context.Context, id string) error {
|
||||
profile, err := loaded.Runtime.Engine.InspectProfile(ctx, id)
|
||||
if errors.Is(err, pk.ErrProfileNotFound) {
|
||||
return &preflight.SelectionError{Cause: err}
|
||||
}
|
||||
if err != nil || profile.Backend == nil {
|
||||
return err
|
||||
}
|
||||
backend := *profile.Backend
|
||||
if _, ok := checkedBackends[backend]; ok {
|
||||
return nil
|
||||
}
|
||||
_, err = loaded.Runtime.Engine.InspectBackend(ctx, backend)
|
||||
if errors.Is(err, pk.ErrBackendNotFound) {
|
||||
return &preflight.SelectionError{Cause: err}
|
||||
}
|
||||
if err == nil {
|
||||
checkedBackends[backend] = struct{}{}
|
||||
}
|
||||
return err
|
||||
}
|
||||
plan, err := preflight.BuildPlan(ctx, cfg, loaded.Source, inspectProfile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
reportDir := ""
|
||||
reportDirSet := false
|
||||
for _, override := range input.Overrides {
|
||||
@@ -104,6 +144,22 @@ func prepareProcess(ctx context.Context, input processInput, loaded *processInpu
|
||||
}
|
||||
}
|
||||
}
|
||||
checked, err := diagnostics.CheckOutput(diagnostics.OutputSelection{InputTranscriptPath: input.Transcript, TranscriptPath: input.Output.Value, ReportDir: reportDir, ReportingEnabled: cfg.Reporting.Enabled, ProtectedPaths: loaded.ProtectedPaths, Stdout: stdout})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := ctx.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &preparedInvocation{Loaded: loaded, Plan: plan, Destinations: checked}, nil
|
||||
}
|
||||
|
||||
func prepareProcess(ctx context.Context, input processInput, loaded *processInputs, stdout io.Writer) (*preparedProcess, error) {
|
||||
local, err := prepareLocal(ctx, input, loaded, stdout)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cfg := local.Plan.Config
|
||||
runID, err := generateRunID()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -136,38 +192,12 @@ func prepareProcess(ctx context.Context, input processInput, loaded *processInpu
|
||||
}
|
||||
debug = &debugInput{WorkDir: cfg.Diagnostics.WorkDir, RunID: runID, EffectiveConfig: effective.Bytes(), Metadata: diagnostics.InvocationMetadata{Operation: "process", TranscriptPath: input.Transcript, OutputPath: input.Output.Value, Overlay: input.Overlay.Value, ConfigVersion: &cfg.Version, RunID: runID, StartedAt: started}}
|
||||
}
|
||||
checkedBackends := make(map[string]struct{})
|
||||
inspectProfile := func(ctx context.Context, id string) error {
|
||||
profile, err := loaded.Runtime.Engine.InspectProfile(ctx, id)
|
||||
if errors.Is(err, pk.ErrProfileNotFound) {
|
||||
return &preflight.SelectionError{Cause: err}
|
||||
}
|
||||
if err != nil || profile.Backend == nil {
|
||||
return err
|
||||
}
|
||||
backend := *profile.Backend
|
||||
if _, ok := checkedBackends[backend]; ok {
|
||||
return nil
|
||||
}
|
||||
_, err = loaded.Runtime.Engine.InspectBackend(ctx, backend)
|
||||
if errors.Is(err, pk.ErrBackendNotFound) {
|
||||
return &preflight.SelectionError{Cause: err}
|
||||
}
|
||||
if err == nil {
|
||||
checkedBackends[backend] = struct{}{}
|
||||
}
|
||||
return err
|
||||
}
|
||||
plan, err := preflight.BuildPlan(ctx, cfg, loaded.Source, inspectProfile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
prepared, err := prepareOutput(ctx, plan, diagnostics.OutputSelection{InputTranscriptPath: input.Transcript, TranscriptPath: input.Output.Value, ReportDir: reportDir, ReportingEnabled: cfg.Reporting.Enabled, ProtectedPaths: loaded.ProtectedPaths, Stdout: stdout}, initial, failed, debug)
|
||||
prepared, err := prepareOutput(ctx, local.Destinations, initial, failed, debug)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
prepared.Warnings = append(warnings, prepared.Warnings...)
|
||||
return &preparedProcess{Prepared: prepared, RunID: runID, Started: started}, nil
|
||||
return &preparedProcess{Prepared: prepared, Invocation: local, RunID: runID, Started: started}, nil
|
||||
}
|
||||
|
||||
func generateRunID() (string, error) {
|
||||
|
||||
Reference in New Issue
Block a user