Complete pipeline preflight verification

This commit is contained in:
2026-11-28 04:45:29 +00:00
parent d5056d77b6
commit c08e5ab670
9 changed files with 114 additions and 29 deletions

View File

@@ -1,7 +1,9 @@
package cli
import (
"errors"
"fmt"
"os"
"text/template"
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
@@ -12,11 +14,12 @@ import (
)
type preflightScope struct {
Pipeline string `json:"pipeline,omitempty" yaml:"pipeline,omitempty"`
Path string `json:"path,omitempty" yaml:"path,omitempty"`
Profile string `json:"profile,omitempty" yaml:"profile,omitempty"`
Backend string `json:"backend,omitempty" yaml:"backend,omitempty"`
Bindings []preflight.BindingScope `json:"bindings,omitempty" yaml:"bindings,omitempty"`
Pipeline string `json:"pipeline,omitempty" yaml:"pipeline,omitempty"`
Path string `json:"path,omitempty" yaml:"path,omitempty"`
Reference string `json:"reference,omitempty" yaml:"reference,omitempty"`
Profile string `json:"profile,omitempty" yaml:"profile,omitempty"`
Backend string `json:"backend,omitempty" yaml:"backend,omitempty"`
Bindings []preflight.BindingScope `json:"bindings,omitempty" yaml:"bindings,omitempty"`
}
type preflightCheck struct {
@@ -118,20 +121,29 @@ func executePreflight(invocation commandkit.Invocation, input pipelineRunInput,
}
add("selection", preflightScope{Pipeline: input.PipelineID}, "passed", "Pipeline selection and resources are valid.")
local, failure := preparePipelineInvocation(loaded, selected, input)
if failure != nil {
add("preparation", preflightScope{Pipeline: input.PipelineID}, "failed", failure.Explanation.Message)
return finish(*failure)
}
for _, diagnostic := range local.diagnostics {
for _, sample := range diagnostic.Samples {
message := sample.Message
if diagnostic.Disposition == contracts.DiagnosticDispositionWarning {
report.Checks = append(report.Checks, preflightCheck{ID: "reference", Scope: preflightScope{Path: sample.Scope}, Result: "warning", Code: diagnostic.ReasonCode, Message: message})
report.Checks = append(report.Checks, preflightCheck{ID: "reference", Scope: preflightScope{Reference: sample.Scope}, Result: "warning", Code: diagnostic.ReasonCode, Message: message})
} else {
_ = invocation.Reporter().Info(message)
}
}
}
if failure != nil {
scope := preflightScope{Pipeline: input.PipelineID}
if local.failureTarget == "input" {
scope.Path = input.InputFile.Value
} else if local.failureTarget == "references" {
var pathErr *os.PathError
if errors.As(failure.Cause, &pathErr) {
scope.Path = pathErr.Path
}
}
add(local.failureTarget, scope, "failed", failure.Explanation.Message)
return finish(*failure)
}
add("preparation", preflightScope{Pipeline: input.PipelineID}, "passed", "References and modules are prepared.")
if _, err := local.prepared.ParseSource(ctx, contracts.ParseRequest{Path: input.InputFile.Value, Raw: local.raw}); err != nil {
add("input", preflightScope{Path: input.InputFile.Value}, "failed", err.Error())
@@ -153,9 +165,18 @@ func executePreflight(invocation commandkit.Invocation, input pipelineRunInput,
}
targets, err := preflight.DiscoverTargets(ctx, selected.effective.ResolvedPipeline, selected.catalog, selected.engine)
if err != nil {
add("targets", preflightScope{Pipeline: input.PipelineID}, "failed", err.Error())
scope := preflightScope{Pipeline: input.PipelineID}
var targetErr *preflight.TargetError
if errors.As(err, &targetErr) {
scope.Bindings = []preflight.BindingScope{targetErr.Scope}
}
add("targets", scope, "failed", err.Error())
return finish(pipelineResourceFailure(err))
}
if err := capture.WriteJSON("targets.json", targets); err != nil {
add("debug", preflightScope{Path: capture.Path()}, "failed", err.Error())
return finish(commandkit.Failure(err.Error()).WithCause(err))
}
evidence := newRunEvidenceRecorder(capture, loaded.result)
evidenceIndex := 0
observations, err := preflight.RunSmokeChecksObserved(ctx, selected.engine, targets, input.Overrides.Execution.Execution, input.Overrides.Execution.TransientRetries, func(observation preflight.SmokeObservation) error {
@@ -181,7 +202,11 @@ func executePreflight(invocation commandkit.Invocation, input pipelineRunInput,
}
if err != nil {
if !failedCheck {
add("debug", preflightScope{Path: capture.Path()}, "failed", err.Error())
if capture.Err() != nil {
add("debug", preflightScope{Path: capture.Path()}, "failed", err.Error())
} else {
add("diagnostics", preflightScope{Pipeline: input.PipelineID}, "failed", err.Error())
}
}
return finish(commandkit.Failure(err.Error()).WithCause(err))
}