diff --git a/internal/executor/artifact_export.go b/internal/executor/artifact_export.go index aa6fff2..28a639e 100644 --- a/internal/executor/artifact_export.go +++ b/internal/executor/artifact_export.go @@ -15,21 +15,20 @@ import ( ) // RegisterArtifacts registers workflow reports and state files as artifacts in the database -// runID is the integer Run.ID used as a foreign key for artifacts -func RegisterArtifacts(workflow *core.Workflow, execCtx *core.ExecutionContext, runID int64, logger *zap.Logger) error { +// and returns the collected artifact file paths. runID is the integer Run.ID used as a +// foreign key for artifacts. Path collection happens regardless of whether the database +// is available, so callers can always populate WorkflowResult.Artifacts. +func RegisterArtifacts(workflow *core.Workflow, execCtx *core.ExecutionContext, runID int64, logger *zap.Logger) ([]string, error) { db := database.GetDB() - if db == nil { - return nil - } - ctx := context.Background() templateEngine := template.NewEngine() + var paths []string // Get output path outputPath, ok := execCtx.GetVariable("Output") if !ok { logger.Debug("Output variable not set, skipping artifact registration") - return nil + return paths, nil } outputStr, _ := outputPath.(string) @@ -45,6 +44,11 @@ func RegisterArtifacts(workflow *core.Workflow, execCtx *core.ExecutionContext, ) continue } + paths = append(paths, renderedPath) + + if db == nil { + continue + } // Determine content type from report type contentType := mapReportTypeToContentType(report.Type) @@ -98,6 +102,11 @@ func RegisterArtifacts(workflow *core.Workflow, execCtx *core.ExecutionContext, // Register state files for _, stateFile := range database.DefaultStateFiles { statePath := filepath.Join(outputStr, stateFile.FileName) + paths = append(paths, statePath) + + if db == nil { + continue + } // Check if artifact already exists for this workspace + name var existingArtifact database.Artifact @@ -171,7 +180,7 @@ func RegisterArtifacts(workflow *core.Workflow, execCtx *core.ExecutionContext, } } - return nil + return paths, nil } // mapReportTypeToContentType converts workflow report type to database content type diff --git a/internal/executor/executor.go b/internal/executor/executor.go index a1f0e4a..ddef733 100644 --- a/internal/executor/executor.go +++ b/internal/executor/executor.go @@ -1466,9 +1466,11 @@ func (e *Executor) ExecuteModule(ctx context.Context, module *core.Workflow, par // Register artifacts (reports from workflow + state files) if !e.dryRun { - if err := RegisterArtifacts(module, execCtx, e.dbRunID, execCtx.Logger); err != nil { + paths, err := RegisterArtifacts(module, execCtx, e.dbRunID, execCtx.Logger) + if err != nil { execCtx.Logger.Warn("Failed to register artifacts", zap.Error(err)) } + result.Artifacts = paths } // Flush write coordinator at workflow completion @@ -2322,9 +2324,11 @@ func (e *Executor) ExecuteFlow(ctx context.Context, flow *core.Workflow, params // Register artifacts (reports from workflow + state files) if !e.dryRun { - if err := RegisterArtifacts(flow, execCtx, e.dbRunID, execCtx.Logger); err != nil { + paths, err := RegisterArtifacts(flow, execCtx, e.dbRunID, execCtx.Logger) + if err != nil { execCtx.Logger.Warn("Failed to register artifacts", zap.Error(err)) } + result.Artifacts = paths } // Flush write coordinator at workflow completion