From 35556e030676fa458d7ec7c7c23d741da37a7c44 Mon Sep 17 00:00:00 2001 From: Ahmed Rehan Date: Thu, 12 Feb 2026 00:38:24 +0500 Subject: [PATCH] feat: add cleanup of stale skills before re-sync sync_microsoft_skills.py now reads docs/microsoft-skills-attribution.json to identify previously synced skill directories and removes them before re-populating. This handles upstream renames, removals, and moves without leaving orphaned skill directories. --- scripts/sync_microsoft_skills.py | 40 +++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/scripts/sync_microsoft_skills.py b/scripts/sync_microsoft_skills.py index a0bc93bf..47cee38b 100644 --- a/scripts/sync_microsoft_skills.py +++ b/scripts/sync_microsoft_skills.py @@ -16,6 +16,7 @@ MS_REPO = "https://github.com/microsoft/skills.git" REPO_ROOT = Path(__file__).parent.parent TARGET_DIR = REPO_ROOT / "skills" DOCS_DIR = REPO_ROOT / "docs" +ATTRIBUTION_FILE = DOCS_DIR / "microsoft-skills-attribution.json" def clone_repo(temp_dir: Path): @@ -27,6 +28,37 @@ def clone_repo(temp_dir: Path): ) +def cleanup_previous_sync(): + """Remove skill directories from a previous sync using the attribution manifest.""" + if not ATTRIBUTION_FILE.exists(): + print(" ℹ️ No previous attribution file found — skipping cleanup.") + return 0 + + try: + with open(ATTRIBUTION_FILE) as f: + attribution = json.load(f) + except (json.JSONDecodeError, OSError) as e: + print(f" ⚠️ Could not read attribution file: {e}") + return 0 + + previous_skills = attribution.get("skills", []) + removed_count = 0 + + for skill in previous_skills: + flat_name = skill.get("flat_name", "") + if not flat_name: + continue + + skill_dir = TARGET_DIR / flat_name + if skill_dir.exists() and skill_dir.is_dir(): + shutil.rmtree(skill_dir) + removed_count += 1 + + print( + f" 🗑️ Removed {removed_count} previously synced skill directories.") + return removed_count + + def extract_skill_name(skill_md_path: Path) -> str | None: """Extract the 'name' field from SKILL.md YAML frontmatter.""" try: @@ -253,6 +285,9 @@ def main(): TARGET_DIR.mkdir(parents=True, exist_ok=True) + print("\n🧹 Cleaning up previous sync...") + cleanup_previous_sync() + print("\n🔗 Resolving symlinks and flattening into skills//...") count, metadata = sync_skills_flat(temp_path, TARGET_DIR) @@ -276,9 +311,8 @@ def main(): print(f" Languages: {', '.join(sorted(languages))}") print("\n📋 Next steps:") - print("1. Delete old skills/official/ directory (if it exists)") - print("2. Run: npm run build") - print("3. Commit changes and create PR") + print("1. Run: npm run build") + print("2. Commit changes and create PR") except Exception as e: print(f"\n❌ Error: {e}")