Skip to content

Commit

Permalink
fix: update morpheus module config to use proper device mappings for …
Browse files Browse the repository at this point in the history
…NVMe EBS volumes
  • Loading branch information
arnol377 committed Feb 12, 2025
1 parent 1c24ab7 commit de45061
Showing 1 changed file with 121 additions and 0 deletions.
121 changes: 121 additions & 0 deletions scripts/sync-repos.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit de45061

Please sign in to comment.