retention: explicit run-history and artifact retention

Add `pipelines retention report` (strictly read-only) and
`pipelines retention apply` (explicit, approval-gated removal) with an age
and/or count policy, protected-run rules, atomic single-transaction removal
and honest database space reclaim. Nothing prunes automatically.
This commit is contained in:
2026-10-17 15:45:46 +01:00
parent b2e920a150
commit 14175eba70
15 changed files with 2127 additions and 12 deletions
+19
View File
@@ -40,6 +40,9 @@ type options struct {
output string
conflict string
kind string
db, artifacts, olderThan string
keep int
keepSet bool
all bool
json, source, noOpen, yes, allow, createOnly, force, wait bool
version, expected, limit int
@@ -151,6 +154,19 @@ func (a App) flags(command string) (*flag.FlagSet, *options) {
f.DurationVar(&o.waitTimeout, "wait-timeout", 0, "Client limit for --wait (0 waits until the run ends); independent of --timeout")
case "cancel", "draft-delete":
f.BoolVar(&o.yes, "yes", false, "Confirm this action without an interactive prompt")
case "retention":
f.StringVar(&o.db, "db", "", "Existing database path (default: standard data directory)")
f.StringVar(&o.artifacts, "artifacts", "", "Artifacts root (default: artifacts/ beside --db)")
f.StringVar(&o.olderThan, "older-than", "", "Select runs created before this rolling UTC duration ago (e.g. 720h, 30d, 12w)")
f.Func("keep", "Keep the newest N runs; older runs are selected (0 selects every eligible run)", func(value string) error {
n, err := strconv.Atoi(strings.TrimSpace(value))
if err != nil {
return fmt.Errorf("--keep requires an integer count")
}
o.keep, o.keepSet = n, true
return nil
})
f.BoolVar(&o.yes, "yes", false, "Approve removal without an interactive prompt (apply only)")
case "decide":
f.StringVar(&o.option, "option", "", "Option key to choose among the waiting stage's edges (required)")
f.StringVar(&o.feedback, "feedback", "", "Optional free-text feedback recorded with the decision")
@@ -389,6 +405,9 @@ func (a App) Run(ctx context.Context, args []string) error {
_, err := fmt.Fprintln(a.Out, "Deleted draft:", pos[0])
return err
}
if command == "retention" {
return a.retention(ctx, o, pos)
}
if command != "drafts" && os.Getenv("PIPELINES_URL") == "" {
explicit := false
f.Visit(func(value *flag.Flag) {