Collect previous history for artifact prerequisites
This commit is contained in:
@@ -378,7 +378,10 @@ func buildPreviousCacheRestoreActions(
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
requirements := artifacts.CollectPreviousArtifactRequirements(cfg.ConcreteArtifacts(), effective)
|
||||
requirements, err := artifacts.CollectPreviousArtifactRequirements(cfg.ConcreteArtifacts(), effective)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(requirements) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -510,9 +510,9 @@ func manifestPathFor(cfg *config.Config) string {
|
||||
)
|
||||
}
|
||||
|
||||
func needsObjectStoreForRun(cfg *config.Config, stages []stage.Stage, effectiveSets ...artifacts.EffectiveArtifactSet) bool {
|
||||
func needsObjectStoreForRun(cfg *config.Config, stages []stage.Stage, effectiveSets ...artifacts.EffectiveArtifactSet) (bool, error) {
|
||||
if cfg == nil || cfg.Pipeline == nil || cfg.Session == nil {
|
||||
return false
|
||||
return false, nil
|
||||
}
|
||||
effective := artifacts.EffectiveArtifactSet{}
|
||||
if len(effectiveSets) > 0 {
|
||||
@@ -525,7 +525,7 @@ func needsObjectStoreForRun(cfg *config.Config, stages []stage.Stage, effectiveS
|
||||
nil,
|
||||
)
|
||||
if err != nil {
|
||||
return false
|
||||
return false, err
|
||||
}
|
||||
}
|
||||
stageRequested := func(name string) bool {
|
||||
@@ -538,27 +538,30 @@ func needsObjectStoreForRun(cfg *config.Config, stages []stage.Stage, effectiveS
|
||||
}
|
||||
|
||||
if cfg.Session.Inputs.AudioS3 != nil && stageRequested("prepare") {
|
||||
return true
|
||||
return true, nil
|
||||
}
|
||||
if stageRequested("prepare") {
|
||||
requirements := artifacts.CollectPreviousArtifactRequirements(configuredScriptoriumArtifacts(cfg), effective)
|
||||
requirements, err := artifacts.CollectPreviousArtifactRequirements(configuredScriptoriumArtifacts(cfg), effective)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if len(requirements) > 0 && strings.TrimSpace(cfg.Session.PreviousSessionID) != "" {
|
||||
return true
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
if !stageRequested("publish") {
|
||||
return false
|
||||
return false, nil
|
||||
}
|
||||
if cfg.Pipeline.Publish == nil {
|
||||
return false
|
||||
return false, nil
|
||||
}
|
||||
if cfg.Pipeline.Publish.Enabled != nil && !*cfg.Pipeline.Publish.Enabled {
|
||||
return false
|
||||
return false, nil
|
||||
}
|
||||
if cfg.Pipeline.Publish.UploadRun != nil && !*cfg.Pipeline.Publish.UploadRun {
|
||||
return false
|
||||
return false, nil
|
||||
}
|
||||
return true
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func needsNotariusForRun(cfg *config.Config, stages []stage.Stage) bool {
|
||||
|
||||
@@ -56,7 +56,11 @@ func composeInvocation(runtime *invocationRuntime, stages []stage.Stage) error {
|
||||
if err := runtime.ctx.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
if env.ObjectStore == nil && needsObjectStoreForRun(env.Config, stages, runtime.effectiveArtifacts) {
|
||||
needStore, err := needsObjectStoreForRun(env.Config, stages, runtime.effectiveArtifacts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if env.ObjectStore == nil && needStore {
|
||||
objectStore, err := dependencies.newObjectStore(runtime.ctx, env.Config)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -455,7 +455,6 @@ func TestNeedsObjectStoreForRunPrepareWithPreviousRequirements(t *testing.T) {
|
||||
Scriptorium: &config.ScriptoriumConfig{
|
||||
Artifacts: map[string]config.ScriptoriumArtifactConfig{
|
||||
"session_recap": {
|
||||
Enabled: true,
|
||||
Inputs: map[string]config.ScriptoriumInputConfig{
|
||||
"previous_recap": {
|
||||
Source: "narratio.previous_session.artifact.session_recap",
|
||||
@@ -471,8 +470,12 @@ func TestNeedsObjectStoreForRunPrepareWithPreviousRequirements(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
cfg.Pipeline.Scriptorium.Artifacts["child"] = config.ScriptoriumArtifactConfig{Enabled: true, DependsOn: []string{"session_recap"}}
|
||||
cfg.ArtifactCatalog = &config.ArtifactCatalog{Artifacts: cfg.Pipeline.Scriptorium.Artifacts}
|
||||
got := needsObjectStoreForRun(cfg, []stage.Stage{countingStage{name: "prepare", runs: new(int)}})
|
||||
got, err := needsObjectStoreForRun(cfg, []stage.Stage{countingStage{name: "prepare", runs: new(int)}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got != tt.want {
|
||||
t.Fatalf("needsObjectStoreForRun() = %v, want %v", got, tt.want)
|
||||
}
|
||||
@@ -1553,3 +1556,27 @@ func projectedTestPlayers(t *testing.T, party *config.CanonicalParty) []byte {
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
func TestNeedsObjectStoreRespectsSelectedPrerequisites(t *testing.T) {
|
||||
definitions := map[string]config.ScriptoriumArtifactConfig{
|
||||
"child": {Enabled: true, DependsOn: []string{"parent"}},
|
||||
"parent": {Inputs: map[string]config.ScriptoriumInputConfig{"history": {Source: "narratio.previous_session.artifact.history", Required: true}}},
|
||||
"other": {Enabled: true},
|
||||
}
|
||||
cfg := &config.Config{Pipeline: &config.PipelineConfig{Scriptorium: &config.ScriptoriumConfig{Artifacts: definitions}}, Session: &config.SessionConfig{PreviousSessionID: "previous"}, ArtifactCatalog: &config.ArtifactCatalog{Artifacts: definitions}}
|
||||
for _, tc := range []struct {
|
||||
selected string
|
||||
want bool
|
||||
}{{"child", true}, {"other", false}} {
|
||||
t.Run(tc.selected, func(t *testing.T) {
|
||||
effective, err := artifacts.ResolveEffectiveArtifactSet(artifacts.ConfiguredArtifactDefinitions(definitions), []string{tc.selected})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got, err := needsObjectStoreForRun(cfg, []stage.Stage{countingStage{name: "prepare", runs: new(int)}}, effective)
|
||||
if err != nil || got != tc.want {
|
||||
t.Fatalf("store needed = %v, error = %v", got, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,7 +222,12 @@ func inspectSessionState(ctx context.Context, cfg *config.Config, status, remote
|
||||
effective, err := resolveEffectiveArtifacts(cfg, nil)
|
||||
fail("artifacts", err)
|
||||
if err == nil {
|
||||
previous := inspectPreviousArtifactReadiness(ctx, cfg, store, artifacts.CollectPreviousArtifactRequirements(configuredScriptoriumArtifacts(cfg), effective))
|
||||
requirements, collectErr := artifacts.CollectPreviousArtifactRequirements(configuredScriptoriumArtifacts(cfg), effective)
|
||||
fail("artifacts", collectErr)
|
||||
if collectErr != nil {
|
||||
return report, resultErr
|
||||
}
|
||||
previous := inspectPreviousArtifactReadiness(ctx, cfg, store, requirements)
|
||||
fail("previous", previous.Err)
|
||||
for _, requirement := range previous.Requirements {
|
||||
state := "ready"
|
||||
|
||||
Reference in New Issue
Block a user