From 964b872ee1f323c6f1dee1582a42315c9cc97574 Mon Sep 17 00:00:00 2001 From: Achintha Isuru Date: Fri, 6 Feb 2026 13:40:28 -0500 Subject: [PATCH] Add clean-branches make target and docs Document dataconnect environment options and add branch-cleaning tooling. Adds PROTECTED_BRANCHES.md listing protected branches (main, dev, demo/**). Updates Makefile help text to show ENV defaults for dataconnect targets, new bootstrap/backup/validation commands, and a tip about default ENV. Adds a new clean-branches .PHONY target in makefiles/tools.mk that validates the current branch, reads PROTECTED_BRANCHES.md, prompts for confirmation, switches to dev if necessary, and deletes non-protected local branches while reporting a summary. --- Makefile | 24 ++++++++++++++---------- PROTECTED_BRANCHES.md | 5 +++++ makefiles/tools.mk | 38 +++++++++++++++++++++++++++++++++++++- 3 files changed, 56 insertions(+), 11 deletions(-) create mode 100644 PROTECTED_BRANCHES.md diff --git a/Makefile b/Makefile index e6e35bbf..a54c9e9d 100644 --- a/Makefile +++ b/Makefile @@ -55,22 +55,25 @@ help: @echo "" @echo " šŸ—„ļø DATA CONNECT & BACKEND (backend/dataconnect)" @echo " ────────────────────────────────────────────────────────────────────" - @echo " make dataconnect-init Initialize Firebase Data Connect" - @echo " make dataconnect-deploy Deploy Data Connect schemas to Cloud SQL" - @echo " make dataconnect-sql-migrate Apply pending SQL migrations" - @echo " make dataconnect-generate-sdk Regenerate Data Connect client SDK" - @echo " make dataconnect-sync Full sync: deploy + migrate + generate SDK" - @echo " make dataconnect-seed Seed database with test data" - @echo " make dataconnect-clean Delete all data from Data Connect" - @echo " make dataconnect-test Test Data Connect deployment (dry-run)" - @echo " make dataconnect-enable-apis Enable required GCP APIs" - @echo " make dataconnect-bootstrap-db ONE-TIME: Full Cloud SQL + Data Connect setup" + @echo " make dataconnect-init Initialize Firebase Data Connect" + @echo " make dataconnect-deploy [ENV=dev] Deploy Data Connect schemas (dev/staging)" + @echo " make dataconnect-sql-migrate [ENV=dev] Apply pending SQL migrations" + @echo " make dataconnect-generate-sdk [ENV=dev] Regenerate Data Connect client SDK" + @echo " make dataconnect-sync [ENV=dev] Full sync: deploy + migrate + generate SDK" + @echo " make dataconnect-seed [ENV=dev] Seed database with test data" + @echo " make dataconnect-clean [ENV=dev] Delete all data from Data Connect" + @echo " make dataconnect-test [ENV=dev] Test Data Connect deployment (dry-run)" + @echo " make dataconnect-enable-apis [ENV=dev] Enable required GCP APIs" + @echo " make dataconnect-bootstrap-db ONE-TIME: Full Cloud SQL + Data Connect setup (dev)" + @echo " make dataconnect-bootstrap-validation-database ONE-TIME: Setup validation database" + @echo " make dataconnect-backup-dev-to-validation Backup dev database to validation" @echo "" @echo " šŸ› ļø DEVELOPMENT TOOLS" @echo " ────────────────────────────────────────────────────────────────────" @echo " make install-melos Install Melos globally (for mobile dev)" @echo " make install-git-hooks Install git pre-push hook (protect main/dev)" @echo " make sync-prototypes Sync prototypes from client-krow-poc repo" + @echo " make clean-branches Delete local branches (keeps main/dev/demo/**/protected)" @echo "" @echo " ā„¹ļø HELP" @echo " ────────────────────────────────────────────────────────────────────" @@ -79,4 +82,5 @@ help: @echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" @echo " šŸ’” Tip: Run 'make mobile-install' first for mobile development" @echo " šŸ’” Tip: Use 'make dataconnect-sync' after schema changes" + @echo " šŸ’” Tip: Default ENV=dev, use ENV=staging for staging environment" @echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" \ No newline at end of file diff --git a/PROTECTED_BRANCHES.md b/PROTECTED_BRANCHES.md new file mode 100644 index 00000000..89874a4a --- /dev/null +++ b/PROTECTED_BRANCHES.md @@ -0,0 +1,5 @@ +# Protected Branches + +- `main` +- `dev` +- `demo/**` diff --git a/makefiles/tools.mk b/makefiles/tools.mk index fefe0468..111433e2 100644 --- a/makefiles/tools.mk +++ b/makefiles/tools.mk @@ -1,6 +1,6 @@ # --- Development Tools --- -.PHONY: install-git-hooks sync-prototypes install-melos +.PHONY: install-git-hooks sync-prototypes install-melos clean-branches install-melos: @if ! command -v melos >/dev/null 2>&1; then \ @@ -18,3 +18,39 @@ install-git-hooks: sync-prototypes: @echo "--> Synchronizing prototypes from external repository..." @./scripts/sync-prototypes.sh + +clean-branches: + @echo "--> Cleaning up local branches (keeping protected branches)..." + @CURRENT_BRANCH=$$(git branch --show-current); \ + if [ "$$CURRENT_BRANCH" != "main" ] && [ "$$CURRENT_BRANCH" != "dev" ]; then \ + echo "āŒ Error: This command can only be run from 'main' or 'dev' branch."; \ + echo " Current branch: $$CURRENT_BRANCH"; \ + echo " Please checkout 'main' or 'dev' first."; \ + exit 1; \ + fi + @if [ ! -f "PROTECTED_BRANCHES.md" ]; then \ + echo "āš ļø PROTECTED_BRANCHES.md not found. Aborting."; \ + exit 1; \ + fi + @echo "\nProtected branches (will NOT be deleted):" + @grep -E '^- `[^`]+`' PROTECTED_BRANCHES.md | sed 's/^- `\(.*\)`/ - \1/' 2>/dev/null || true + @echo "\nāš ļø This will delete all other local branches." + @read -p "Are you sure? (y/N): " confirm && [ "$$confirm" = "y" ] || [ "$$confirm" = "Y" ] || (echo "Aborted." && exit 1) + @CURRENT_BRANCH=$$(git branch --show-current); \ + if [ "$$CURRENT_BRANCH" != "main" ] && [ "$$CURRENT_BRANCH" != "dev" ] && ! echo "$$CURRENT_BRANCH" | grep -q '^demo/'; then \ + echo "\nāš ļø You are on branch '$$CURRENT_BRANCH' which will be deleted."; \ + echo "Switching to 'dev' branch first..."; \ + git checkout dev || (echo "āŒ Failed to checkout dev branch" && exit 1); \ + fi + @echo "\nDeleting branches..." + @DELETED=0; SKIPPED=0; \ + for branch in $$(git branch | sed 's/^[* ] //' | grep -v '^main$$' | grep -v '^dev$$' | grep -v '^demo/'); do \ + if grep -qE "^- \`$$branch\`" PROTECTED_BRANCHES.md 2>/dev/null; then \ + echo " ā­ļø Skipping protected: $$branch"; \ + SKIPPED=$$((SKIPPED + 1)); \ + else \ + echo " šŸ—‘ļø Deleting: $$branch"; \ + git branch -D "$$branch" 2>/dev/null && DELETED=$$((DELETED + 1)) || echo " āš ļø Failed to delete $$branch"; \ + fi; \ + done; \ + echo "\nāœ… Done! Deleted $$DELETED branch(es), skipped $$SKIPPED protected branch(es)."