From de450614c8a35729aa94058068a95abce72c21d0 Mon Sep 17 00:00:00 2001 From: arnol377 Date: Wed, 12 Feb 2025 12:42:36 -0500 Subject: [PATCH] fix: update morpheus module config to use proper device mappings for NVMe EBS volumes --- scripts/sync-repos.py | 121 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100755 scripts/sync-repos.py diff --git a/scripts/sync-repos.py b/scripts/sync-repos.py new file mode 100755 index 0000000..fb349c2 --- /dev/null +++ b/scripts/sync-repos.py @@ -0,0 +1,121 @@ +#!/usr/bin/env python3 +import os +import sys +import subprocess +from typing import Dict, Optional + +# Base directory containing all repositories +BASE_DIR = "/home/a/arnol377/git" + +# Repository configurations with their commit messages +REPOS: Dict[str, Dict[str, str]] = { + "aws-image-pipeline": { + "message": "fix: update morpheus module config to use proper device mappings for NVMe EBS volumes", + "branch": "main" + }, + "image-pipeline-ansible-playbooks": { + "message": "fix: update volume mounting to handle NVMe device mapping and add enhanced error checking", + "branch": "main" + }, + "linux-image-pipeline": { + "message": "fix: update packer configuration to properly handle root volume and NVMe device mappings", + "branch": "main" + } +} + +def run_command(cmd: list[str], cwd: Optional[str] = None) -> tuple[int, str, str]: + """Run a shell command and return the exit code, stdout, and stderr.""" + try: + process = subprocess.Popen( + cmd, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + cwd=cwd, + text=True + ) + stdout, stderr = process.communicate() + return process.returncode, stdout, stderr + except Exception as e: + return 1, "", str(e) + +def sync_repo(repo_name: str, config: dict) -> bool: + """Sync (pull/push) a single repository.""" + repo_path = os.path.join(BASE_DIR, repo_name) + if not os.path.isdir(repo_path): + print(f"Error: Directory {repo_path} does not exist") + return False + + print(f"\nProcessing {repo_name}...") + + # Pull from both remotes + for remote in ["origin", "hpw"]: + print(f"Pulling from {remote}...") + code, out, err = run_command( + ["git", "pull", remote, config["branch"]], + repo_path + ) + if code != 0: + print(f"Warning: Failed to pull from {remote}") + print(f"Error: {err}") + + # Check for changes + code, out, err = run_command(["git", "status", "--porcelain"], repo_path) + if code != 0: + print(f"Error checking git status: {err}") + return False + + if out.strip(): + print(f"Changes detected in {repo_name}, committing...") + + # Add all changes + code, out, err = run_command(["git", "add", "."], repo_path) + if code != 0: + print(f"Error adding files: {err}") + return False + + # Commit changes + code, out, err = run_command( + ["git", "commit", "-m", config["message"]], + repo_path + ) + if code != 0: + print(f"Error committing changes: {err}") + return False + + # Push to both remotes + for remote in ["hpw", "origin"]: + print(f"Pushing to {remote}...") + code, out, err = run_command( + ["git", "push", remote, config["branch"]], + repo_path + ) + if code != 0: + print(f"Warning: Failed to push to {remote}") + print(f"Error: {err}") + else: + print(f"No changes to commit in {repo_name}") + + return True + +def main(): + """Main function to sync all repositories.""" + success = True + + # Process each repository + for repo_name, config in REPOS.items(): + try: + if not sync_repo(repo_name, config): + success = False + except Exception as e: + print(f"Error processing {repo_name}: {e}") + success = False + + if success: + print("\nAll repositories processed successfully!") + sys.exit(0) + else: + print("\nSome repositories failed to process") + sys.exit(1) + +if __name__ == "__main__": + main() \ No newline at end of file