Skip to content

Support multiple --cleanup-pattern values for stale branch cleanup #364

Description

@AlexSkrypnyk

Summary

--cleanup-stale (added in 1.6.0) can prune only a single branch glob per run. Deployments that push many branches under different prefixes - feature/*, bugfix/*, release/* - cannot prune more than one prefix in a single invocation, so stale branches under the other prefixes accumulate. This proposes making --cleanup-pattern repeatable so one run can target several patterns.

Details

Current behaviour

  • --cleanup-pattern is a single-value option (InputOption::VALUE_REQUIRED), so passing it more than once keeps only the last value.
  • ArtifactGitRepository::filterStaleBranches() accepts a single string $pattern, matched by matchesGlob(), which only translates * and ? into a regex (no alternation, no brace expansion).
  • Verified single-pattern behaviour on 1.6.0, the main branch, and the 1.7.0 draft.

The only way to cover several prefixes today is an overly broad * or */*. That is unsafe: matchesGlob() lets * span /, and only the just-pushed branch and the remote default branch are protected, so any other long-lived branch (develop, staging, a release branch) older than --cleanup-age would be deleted.

Proposed enhancement

  • Make --cleanup-pattern repeatable: InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, allowing it to be passed multiple times, e.g. --cleanup-pattern='feature/*' --cleanup-pattern='bugfix/*'.
  • Update filterStaleBranches() to accept array $patterns (or add a match-any helper) and treat a branch as eligible when it matches any of the patterns.
  • Validation: require at least one non-empty pattern when --cleanup-stale is set (keep the current "pattern required" guard, generalised to the array).
  • Update the showInfo() report line to list all configured patterns.
  • Update the --help text and the README cleanup section.
  • Extend tests: ArtifactCommandTest, ArtifactGitRepositoryTest, CleanupStaleBranchesTest (multiple patterns, overlapping matches/dedup, none-match, and protected branches still preserved).

Backward compatible: a single --cleanup-pattern keeps working unchanged.

Motivation

drevops/vortex issue #2696 wants to enable this cleanup for artifact deployments. Vortex pushes each source branch to a same-named destination branch, so a deployment repository accumulates feature/*, bugfix/*, and similar prefixes. Multi-pattern support lets Vortex prune all of them safely within the single deploy run instead of leaving all but one prefix to grow unbounded.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions