Handles migration from legacy to modular workflows.
| 33 | |
| 34 | |
| 35 | class LegacyMigrator: |
| 36 | """Handles migration from legacy to modular workflows.""" |
| 37 | |
| 38 | def __init__(self, root_path: Path, dry_run: bool = False): |
| 39 | """Initialize the legacy migrator. |
| 40 | |
| 41 | Args: |
| 42 | root_path: Root path of the project |
| 43 | dry_run: Whether to run in dry-run mode |
| 44 | """ |
| 45 | self.root_path = root_path |
| 46 | self.dry_run = dry_run |
| 47 | self.workflows_dir = root_path / ".github" / "workflows" |
| 48 | self.backup_dir = root_path / ".github" / "workflows" / "legacy-backup" |
| 49 | self.migration_log = root_path / ".github" / "migration-log.json" |
| 50 | |
| 51 | # Migration steps |
| 52 | self.steps: List[MigrationStep] = [ |
| 53 | MigrationStep("backup_legacy", "Backup legacy workflow files", True), |
| 54 | MigrationStep("validate_modular", "Validate modular workflow files", True), |
| 55 | MigrationStep("check_dependencies", "Check script dependencies", True), |
| 56 | MigrationStep("test_modular", "Test modular workflows", True), |
| 57 | MigrationStep("update_branch_protection", "Update branch protection rules", False), |
| 58 | MigrationStep("disable_legacy", "Disable legacy workflows", True), |
| 59 | MigrationStep("cleanup", "Clean up migration artifacts", False), |
| 60 | ] |
| 61 | |
| 62 | def run_migration(self) -> bool: |
| 63 | """Run the complete migration process.""" |
| 64 | print("Starting Legacy Workflow Migration") |
| 65 | print("=" * 60) |
| 66 | |
| 67 | if self.dry_run: |
| 68 | print("[DRY RUN] MODE - No changes will be made") |
| 69 | print() |
| 70 | |
| 71 | # Load previous migration state if exists |
| 72 | self._load_migration_state() |
| 73 | |
| 74 | all_passed = True |
| 75 | |
| 76 | for step in self.steps: |
| 77 | if step.completed: |
| 78 | print(f"[SKIP] {step.name} (already completed)") |
| 79 | continue |
| 80 | |
| 81 | print(f"\nExecuting: {step.description}") |
| 82 | |
| 83 | try: |
| 84 | success = self._execute_step(step) |
| 85 | |
| 86 | if success: |
| 87 | step.completed = True |
| 88 | print(f"[PASS] {step.name}") |
| 89 | else: |
| 90 | print(f"[FAIL] {step.name}") |
| 91 | if step.error: |
| 92 | print(f" Error: {step.error}") |