Clone
2
automation-repo-cleanup.-
Jonathan Miller edited this page 2026-05-11 21:56:19 +00:00

Home

moko-platform

Repository Cleanup

Two tools for cleaning up governed repositories: a PHP CLI script for bulk operations and a Gitea Actions workflow for recurring per-repo maintenance.

Workflow: repository-cleanup.yml

Recurring maintenance workflow synced to all governed repos. Runs automatically on the 1st and 15th of each month at 6:00 AM UTC (1:00 AM CDT), and on manual dispatch.

Schedule vs Manual

Task Schedule (1st + 15th) Manual Dispatch
Delete retired workflows Always Always
Version drift detection Always Always
Create custom workflow dir Always Always
Label reset Off (safe default) Toggle (default: off)
Branch cleanup On Toggle (default: on)
Workflow run cleanup On Toggle (default: on)
Log cleanup (>30 days) On Toggle (default: on)
Issue template fix On Toggle (default: on)
Doc index rebuild On Toggle (default: on)

What Each Task Does

Delete retired workflows — Hardwired, always runs. Removes 25 workflow files that have been superseded or retired from moko-platform. Prevents old workflows from running.

Version drift detection — Scans all .php, .md, and .yml files for VERSION: fields and compares against the README.md version. Reports any mismatches in the step summary.

Create custom workflow directory — Creates .gitea/workflows/custom/ with a README if it doesn't exist. Custom workflows in this directory are never overwritten or deleted by sync.

Label reset — Deletes ALL existing labels and recreates the standard 58-label set. Only runs when explicitly toggled on manual dispatch (never on schedule).

Branch cleanup — Deletes old chore/sync-mokostandards-* branches (keeps only the current versioned branch). Closes any open PRs on deleted branches.

Workflow run cleanup — Deletes cancelled and stale workflow runs from the Actions tab.

Log cleanup — Deletes workflow run logs older than 30 days.

Doc index rebuild — Generates index.md for each docs/ subdirectory listing all markdown files.

Custom Workflows

Repos can have their own workflows that won't be touched by moko-platform sync or cleanup:

.github/
├── workflows/
│   ├── deploy-dev.yml           ← Synced from moko-platform (overwritten on sync)
│   ├── auto-release.yml         ← Synced from moko-platform (overwritten on sync)
│   ├── repository-cleanup.yml   ← Synced from moko-platform (overwritten on sync)
│   └── custom/                  ← SAFE — never touched by sync or cleanup
│       ├── README.md
│       ├── my-custom-ci.yml
│       └── slack-notify.yml

The custom/ directory is auto-created by the cleanup workflow if it doesn't exist.

Authorization

  • Schedule: Always authorized (runs as gitea-actions[bot])
  • Manual dispatch: jmiller and gitea-actions[bot] always authorized; others need admin/maintain role

CLI Script: repo_cleanup.php

Scans governed repositories and deletes stale sync branches, closes superseded PRs, and optionally closes resolved tracking issues.

# Preview cleanup (dry run)
php api/automation/repo_cleanup.php --dry-run

# Clean up all repos
php api/automation/repo_cleanup.php --yes

# Also close tracking issues where the linked PR is merged
php api/automation/repo_cleanup.php --yes --close-issues

# Clean a specific repo
php api/automation/repo_cleanup.php --repos MokoCRM --yes

Options

Flag Description
--org GitHub organization (default: MokoConsulting)
--repos Specific repos to clean (space-separated)
--close-issues Close tracking issues where the linked PR has been merged
--skip-archived Skip archived repositories
--dry-run Preview without making changes
--yes Auto-confirm prompts
--json Output results as JSON

Repo: moko-platform · moko-platform wiki

Field Value
Minimum Version 04.07.00
Platform all
Applies To All repositories
Revision Date Author Description
1.0 2026-05-08 Moko Consulting Initial version