diff --git a/scripts/README.md b/scripts/README.md index e29dee3..160e53d 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -1,40 +1,59 @@ # Repository Sync Script -This script automates the process of committing and pushing changes across multiple image pipeline repositories. +This Python script automates the process of syncing (pulling and pushing) changes across multiple image pipeline repositories. ## Usage ```bash -./scripts/sync-repos.sh +./scripts/sync-repos.py ``` The script will: -1. Look for changes in each repository -2. Commit changes with predefined commit messages -3. Push to both 'hpw' and 'origin' remotes +1. Pull latest changes from both 'hpw' and 'origin' remotes for each repository +2. Look for local changes in each repository +3. If changes exist, commit them with predefined messages +4. Always attempt to push to both 'hpw' and 'origin' remotes (even if there are no local changes) + +This ensures that: +- Local changes are committed and pushed +- Remote changes are pulled down +- Local branch stays in sync with both remotes +- Changes from one remote are propagated to the other ## Prerequisites +- Python 3.6+ - Git repositories must be cloned in the same parent directory - Both 'hpw' and 'origin' remotes must be configured - Script must be run from the aws-image-pipeline directory - Appropriate git credentials/SSH keys must be configured -## Modifying Commit Messages - -To update the commit messages, edit the `REPOS` array in the script. Each repository has an associated commit message: - -```bash -declare -A REPOS=( - ["aws-image-pipeline"]="your commit message here" - ["image-pipeline-ansible-playbooks"]="your commit message here" - ["linux-image-pipeline"]="your commit message here" -) +## Modifying Repository Configuration + +To update the repositories and their commit messages, edit the `REPOS` dictionary in the script: + +```python +REPOS = { + "aws-image-pipeline": { + "message": "your commit message here", + "branch": "main" + }, + "image-pipeline-ansible-playbooks": { + "message": "your commit message here", + "branch": "main" + }, + "linux-image-pipeline": { + "message": "your commit message here", + "branch": "main" + } +} ``` ## Error Handling The script will: -- Continue even if one repository fails -- Report failures to push to either remote -- Skip repositories with no changes \ No newline at end of file +- Continue processing even if one repository fails +- Report failures for both pull and push operations +- Skip repositories with no changes +- Exit with status code 1 if any repository fails to process +- Provide detailed error messages from git operations \ No newline at end of file diff --git a/scripts/sync-repos.py b/scripts/sync-repos.py index fb349c2..436afcf 100755 --- a/scripts/sync-repos.py +++ b/scripts/sync-repos.py @@ -82,18 +82,18 @@ def sync_repo(repo_name: str, config: dict) -> bool: 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: + # Always try to push to both remotes, even if no local changes + 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: + # Only warn if the error indicates nothing to push + if "Everything up-to-date" not in err: print(f"Warning: Failed to push to {remote}") print(f"Error: {err}") - else: - print(f"No changes to commit in {repo_name}") return True