Integrate cleanup into pipeline execution

This commit is contained in:
2026-09-05 15:27:08 +00:00
parent 8d9eb5cc40
commit adc60aa588
25 changed files with 405 additions and 1013 deletions

View File

@@ -1,35 +1,6 @@
package app
import (
"context"
"errors"
"fmt"
"time"
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
)
func finalizeInvocation(runtime *invocationRuntime) (*RunSummary, error) {
if containsStage(runtime.executed, "publish") {
if err := runPostPublishCleanup(
runtime.ctx,
runtime.env,
runtime.manifestPath,
runtime.manifest,
runtime.executed,
runtime.dependencies.removeScopedDir,
); err != nil {
return nil, persistPostPublishCleanupFailure(
runtime.ctx,
runtime.manifestStore,
runtime.manifestPath,
runtime.manifest,
fmt.Errorf("post-publish cleanup incomplete: %w", err),
runtime.dependencies.now(),
)
}
}
return &RunSummary{
SessionID: runtime.identity.SessionID,
RunID: runtime.identity.RunID,
@@ -39,24 +10,3 @@ func finalizeInvocation(runtime *invocationRuntime) (*RunSummary, error) {
Skipped: runtime.skipped,
}, nil
}
func persistPostPublishCleanupFailure(
ctx context.Context,
sessionStore manifest.Store,
sessionManifestPath string,
sessionManifest *manifest.Manifest,
operationErr error,
at time.Time,
) error {
if operationErr == nil {
return nil
}
if sessionManifest != nil {
sessionManifest.RecordFailure(at, operationErr.Error())
}
// Cleanup may have deliberately removed the selected run directory. The
// committed remote snapshot remains authoritative, while the session
// manifest records the outstanding local cleanup for the next invocation.
sessionErr := sessionStore.Save(ctx, sessionManifestPath, sessionManifest)
return errors.Join(operationErr, wrapTerminalPersistenceError("save terminal session manifest", sessionErr))
}