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.
This commit is contained in:
Achintha Isuru
2026-02-06 13:40:28 -05:00
parent 543d800635
commit 964b872ee1
3 changed files with 56 additions and 11 deletions

View File

@@ -55,22 +55,25 @@ help:
@echo "" @echo ""
@echo " 🗄️ DATA CONNECT & BACKEND (backend/dataconnect)" @echo " 🗄️ DATA CONNECT & BACKEND (backend/dataconnect)"
@echo " ────────────────────────────────────────────────────────────────────" @echo " ────────────────────────────────────────────────────────────────────"
@echo " make dataconnect-init Initialize Firebase Data Connect" @echo " make dataconnect-init Initialize Firebase Data Connect"
@echo " make dataconnect-deploy Deploy Data Connect schemas to Cloud SQL" @echo " make dataconnect-deploy [ENV=dev] Deploy Data Connect schemas (dev/staging)"
@echo " make dataconnect-sql-migrate Apply pending SQL migrations" @echo " make dataconnect-sql-migrate [ENV=dev] Apply pending SQL migrations"
@echo " make dataconnect-generate-sdk Regenerate Data Connect client SDK" @echo " make dataconnect-generate-sdk [ENV=dev] Regenerate Data Connect client SDK"
@echo " make dataconnect-sync Full sync: deploy + migrate + generate SDK" @echo " make dataconnect-sync [ENV=dev] Full sync: deploy + migrate + generate SDK"
@echo " make dataconnect-seed Seed database with test data" @echo " make dataconnect-seed [ENV=dev] Seed database with test data"
@echo " make dataconnect-clean Delete all data from Data Connect" @echo " make dataconnect-clean [ENV=dev] Delete all data from Data Connect"
@echo " make dataconnect-test Test Data Connect deployment (dry-run)" @echo " make dataconnect-test [ENV=dev] Test Data Connect deployment (dry-run)"
@echo " make dataconnect-enable-apis Enable required GCP APIs" @echo " make dataconnect-enable-apis [ENV=dev] Enable required GCP APIs"
@echo " make dataconnect-bootstrap-db ONE-TIME: Full Cloud SQL + Data Connect setup" @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 ""
@echo " 🛠️ DEVELOPMENT TOOLS" @echo " 🛠️ DEVELOPMENT TOOLS"
@echo " ────────────────────────────────────────────────────────────────────" @echo " ────────────────────────────────────────────────────────────────────"
@echo " make install-melos Install Melos globally (for mobile dev)" @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 install-git-hooks Install git pre-push hook (protect main/dev)"
@echo " make sync-prototypes Sync prototypes from client-krow-poc repo" @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 ""
@echo " HELP" @echo " HELP"
@echo " ────────────────────────────────────────────────────────────────────" @echo " ────────────────────────────────────────────────────────────────────"
@@ -79,4 +82,5 @@ help:
@echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" @echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
@echo " 💡 Tip: Run 'make mobile-install' first for mobile development" @echo " 💡 Tip: Run 'make mobile-install' first for mobile development"
@echo " 💡 Tip: Use 'make dataconnect-sync' after schema changes" @echo " 💡 Tip: Use 'make dataconnect-sync' after schema changes"
@echo " 💡 Tip: Default ENV=dev, use ENV=staging for staging environment"
@echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" @echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"

5
PROTECTED_BRANCHES.md Normal file
View File

@@ -0,0 +1,5 @@
# Protected Branches
- `main`
- `dev`
- `demo/**`

View File

@@ -1,6 +1,6 @@
# --- Development Tools --- # --- Development Tools ---
.PHONY: install-git-hooks sync-prototypes install-melos .PHONY: install-git-hooks sync-prototypes install-melos clean-branches
install-melos: install-melos:
@if ! command -v melos >/dev/null 2>&1; then \ @if ! command -v melos >/dev/null 2>&1; then \
@@ -18,3 +18,39 @@ install-git-hooks:
sync-prototypes: sync-prototypes:
@echo "--> Synchronizing prototypes from external repository..." @echo "--> Synchronizing prototypes from external repository..."
@./scripts/sync-prototypes.sh @./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)."