Use artifact source IDs for archive promotion
This commit is contained in:
@@ -47,7 +47,7 @@ func validatePipeline(cfg *PipelineConfig) error {
|
||||
if err := validateSpool(cfg.Spool); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateArchive(cfg.Archive); err != nil {
|
||||
if err := validateArchive(cfg.Archive, cfg.Scriptorium); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateWhisperX(cfg.WhisperX); err != nil {
|
||||
@@ -104,28 +104,91 @@ func validateSpool(cfg SpoolConfig) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateArchive(cfg *ArchiveConfig) error {
|
||||
func validateArchive(cfg *ArchiveConfig, scriptorium *ScriptoriumConfig) error {
|
||||
if cfg == nil {
|
||||
return nil
|
||||
}
|
||||
seenDest := map[string]struct{}{}
|
||||
for i, item := range cfg.PromoteArtifacts {
|
||||
prefix := fmt.Sprintf("pipeline.archive.promote_artifacts[%d]", i)
|
||||
if strings.TrimSpace(item.From) == "" {
|
||||
return fmt.Errorf("%s.from is required", prefix)
|
||||
source := strings.TrimSpace(item.Source)
|
||||
if source == "" {
|
||||
return fmt.Errorf("%s.source is required", prefix)
|
||||
}
|
||||
if strings.TrimSpace(item.To) == "" {
|
||||
return fmt.Errorf("%s.to is required", prefix)
|
||||
if _, err := archiveSourceKnown(source, scriptorium); err != nil {
|
||||
return fmt.Errorf("%s.source %q is unsupported: %w", prefix, item.Source, err)
|
||||
}
|
||||
if err := validateRelativeSafePath(prefix+".from", item.From); err != nil {
|
||||
dest := strings.TrimSpace(item.Dest)
|
||||
if dest == "" {
|
||||
derivedDest, err := deriveArchivePromotionDest(source, scriptorium)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s.dest is required when destination cannot be derived from %q: %w", prefix, source, err)
|
||||
}
|
||||
dest = derivedDest
|
||||
cfg.PromoteArtifacts[i].Dest = derivedDest
|
||||
}
|
||||
if err := validateRelativeSafePath(prefix+".dest", dest); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateRelativeSafePath(prefix+".to", item.To); err != nil {
|
||||
return err
|
||||
normalizedDest := filepath.ToSlash(filepath.Clean(dest))
|
||||
if _, ok := seenDest[normalizedDest]; ok {
|
||||
return fmt.Errorf("%s.dest %q duplicates another archive promotion destination", prefix, dest)
|
||||
}
|
||||
seenDest[normalizedDest] = struct{}{}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func archiveSourceKnown(source string, scriptorium *ScriptoriumConfig) (string, error) {
|
||||
trimmed := strings.TrimSpace(source)
|
||||
switch trimmed {
|
||||
case "narratio.transcript.merged",
|
||||
"narratio.transcript.polished",
|
||||
"narratio.transcript.full",
|
||||
"narratio.transcript.trimmed",
|
||||
"narratio.bounds.session":
|
||||
return "", nil
|
||||
}
|
||||
matches := narratioArtifactSourceRE.FindStringSubmatch(trimmed)
|
||||
if len(matches) != 2 {
|
||||
return "", fmt.Errorf("must be a built-in source id or narratio.artifact.<name>")
|
||||
}
|
||||
artifactKey := matches[1]
|
||||
if scriptorium == nil || len(scriptorium.Artifacts) == 0 {
|
||||
return "", fmt.Errorf("configured artifact %q is not defined in pipeline.scriptorium.artifacts", artifactKey)
|
||||
}
|
||||
if _, ok := scriptorium.Artifacts[artifactKey]; !ok {
|
||||
return "", fmt.Errorf("configured artifact %q is not defined in pipeline.scriptorium.artifacts", artifactKey)
|
||||
}
|
||||
return artifactKey, nil
|
||||
}
|
||||
|
||||
func deriveArchivePromotionDest(source string, scriptorium *ScriptoriumConfig) (string, error) {
|
||||
trimmed := strings.TrimSpace(source)
|
||||
switch trimmed {
|
||||
case "narratio.transcript.merged":
|
||||
return PathTranscriptMerged, nil
|
||||
case "narratio.transcript.polished":
|
||||
return PathTranscriptProcessed, nil
|
||||
case "narratio.transcript.full":
|
||||
return PathTranscriptNormalized, nil
|
||||
case "narratio.transcript.trimmed":
|
||||
return PathTranscriptTrimmed, nil
|
||||
case "narratio.bounds.session":
|
||||
return filepath.ToSlash(filepath.Join(PathArtifactsDirSegment, "session_bounds.json")), nil
|
||||
}
|
||||
artifactKey, err := archiveSourceKnown(trimmed, scriptorium)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
artifactCfg := scriptorium.Artifacts[artifactKey]
|
||||
outputPath := strings.TrimSpace(artifactCfg.OutputPath)
|
||||
if outputPath == "" {
|
||||
return "", fmt.Errorf("pipeline.scriptorium.artifacts.%s.output_path is empty", artifactKey)
|
||||
}
|
||||
return outputPath, nil
|
||||
}
|
||||
|
||||
func validateSecrets(cfg *SecretsConfig) error {
|
||||
if cfg == nil {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user