Share read-only planning and analysis closure
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||
@@ -103,71 +102,22 @@ func buildSessionPlan(ctx context.Context, cfg *config.Config, input *executionI
|
||||
return nil, fmt.Errorf("plan: %w", err)
|
||||
}
|
||||
store := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root)
|
||||
model, err := cloneManifestForPlan(m, cfg)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("plan: clone session state: %w", err)
|
||||
projection, err := projectSelectedWork(ctx, cfg, input.plan, input.Force.Value, selectedArtifacts, effective, store, m)
|
||||
if projection == nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
stages := input.plan.Stages()
|
||||
stageEnv := &stage.Env{
|
||||
Config: cfg, SelectedArtifactKeys: append([]string(nil), selectedArtifacts...),
|
||||
EffectiveArtifacts: effective, ArtifactStore: store, Force: input.Force.Value,
|
||||
}
|
||||
|
||||
report := &sessionPlanReport{Campaign: config.CampaignID(cfg.Campaign), SessionID: cfg.Session.SessionID, Stages: []plannedStage{}, Publication: []plannedPublication{}}
|
||||
for _, selectedStage := range stages {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return report, err
|
||||
}
|
||||
semanticConfig, err := currentStageSemanticConfig(selectedStage, stageEnv)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("plan: fingerprint semantic configuration for stage %q: %w", selectedStage.Name(), err)
|
||||
}
|
||||
decision := decideStageExecution(recordedStageStatus(model, selectedStage.Name()), input.Force.Value, nil)
|
||||
var validation *stage.ResumeValidation
|
||||
if decision.action == stageActionSkip {
|
||||
checked, validationErr := evaluateStageResume(ctx, selectedStage, stageEnv, model, semanticConfig)
|
||||
if validationErr != nil {
|
||||
return nil, fmt.Errorf("plan: validate resume for stage %q: %w", selectedStage.Name(), validationErr)
|
||||
}
|
||||
validation = checked
|
||||
decision = decideStageExecution(recordedStageStatus(model, selectedStage.Name()), input.Force.Value, checked)
|
||||
}
|
||||
if _, err := applyPreExecutionDecision(model, selectedStage.Name(), decision, time.Now().UTC()); err != nil {
|
||||
return nil, fmt.Errorf("plan: model resume invalidation for stage %q: %w", selectedStage.Name(), err)
|
||||
}
|
||||
if decision.action == stageActionRun && selectedStage.Name() == "analyze" {
|
||||
if validator, ok := selectedStage.(stage.ResumeValidator); ok {
|
||||
checked, validationErr := validator.ValidateResume(ctx, stageEnv, model)
|
||||
if validationErr != nil {
|
||||
return nil, fmt.Errorf("plan: validate resume for stage %q: %w", selectedStage.Name(), validationErr)
|
||||
}
|
||||
checked = checked.Normalized()
|
||||
validation = &checked
|
||||
}
|
||||
}
|
||||
reason := decision.selectedStaleReason
|
||||
if reason == "" {
|
||||
switch {
|
||||
case input.Force.Value:
|
||||
reason = "forced"
|
||||
case decision.action == stageActionSkip:
|
||||
reason = "recorded result is reusable"
|
||||
default:
|
||||
reason = "no reusable successful result"
|
||||
}
|
||||
}
|
||||
entry := plannedStage{Name: selectedStage.Name(), Action: string(decision.action), Reason: reason}
|
||||
if validation != nil && validation.Analyze != nil {
|
||||
entry.Analysis = analysisPlanReport(validation.Analyze)
|
||||
for _, item := range projection.Stages {
|
||||
entry := plannedStage{Name: item.Name, Action: string(item.Decision.action), Reason: item.Reason}
|
||||
if item.Analysis != nil {
|
||||
entry.Analysis = analysisPlanReport(item.Analysis)
|
||||
}
|
||||
report.Stages = append(report.Stages, entry)
|
||||
if decision.action == stageActionRun {
|
||||
if err := modelPlannedStageRun(model, selectedStage, cfg, decision, semanticConfig); err != nil {
|
||||
return nil, fmt.Errorf("plan: model stage %q: %w", selectedStage.Name(), err)
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return report, err
|
||||
}
|
||||
model := projection.Model
|
||||
if input.plan.Contains("publish") && cfg.Pipeline.Publish != nil && (cfg.Pipeline.Publish.Enabled == nil || *cfg.Pipeline.Publish.Enabled) {
|
||||
catalog, err := buildHelperArtifactCatalog(cfg, model)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user