Skip to content

feat: small solutions for running task os:sync-all #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 23, 2025

Conversation

westonplatter
Copy link
Member

@westonplatter westonplatter commented May 22, 2025

what

  • I ran into an issue where the process would fail if I had not already cloned the DEFAULT_MODULES repos. I added a graceful response where we git clone the repos for the user.
  • I wasn't able to run the sync process because there were existing git branches from a previous sync. To handle this, I added a global variable, DELETE_EXISTING_SYNC_BRANCH, defaulting to false (to keep existing workflow) so the process conditionally deletes the SYNC_BRANCH and creates a new SYNC_BRANCH.

Summary by CodeRabbit

  • New Features
    • Added an option to control whether existing sync branches are deleted when syncing repositories.
  • Enhancements
    • Improved handling of repository cloning and branch creation, including additional logging for clarity.
    • Updated the default module list to include a new module.

@westonplatter westonplatter requested a review from a team as a code owner May 22, 2025 20:19
@westonplatter westonplatter changed the title Feat/add more options to sync process feat: small solutions for running task os:sync-all May 22, 2025
Copy link

coderabbitai bot commented May 22, 2025

Walkthrough

The changes update the DEFAULT_MODULES variable in lib/os-modules/Taskfile.yaml, replacing terraform-postgres-automation with terraform-postgres-config-dbs-users-roles. A new variable, DELETE_EXISTING_SYNC_BRANCH, defaulting to false, is introduced in both the pull-and-branch and sync-all tasks. The pull-and-branch task is enhanced to check for the existence of the local repository directory and clone it from GitHub if missing. Branch creation logic is updated to conditionally handle existing branches based on the DELETE_EXISTING_SYNC_BRANCH flag, with additional logging added for process clarity.

Suggested reviewers

  • Gowiem

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
lib/os-modules/Taskfile.yaml (1)

77-81: Improve clone step portability and error handling.

  • echo -e isn’t standardized across shells—prefer printf.
  • Add set -euo pipefail (or || exit 1) so a failed git clone stops the process instead of causing later errors when cding into a missing directory.

Example diff:

- echo -e "\n\n🚀 Processing ---------------- $module \n"
+ printf "\n\n🚀 Processing ---------------- %s\n" "$module"

  if [ ! -d ../$module ]; then
-   echo "🧲 Cloning repository..."
+   printf "🧲 Cloning repository: %s\n" "$module"
-   git clone "[email protected]:masterpointio/$module.git" ../$module
+   git clone "[email protected]:masterpointio/$module.git" ../"$module" || exit 1
  fi
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between de411c2 and fdd94a4.

📒 Files selected for processing (1)
  • lib/os-modules/Taskfile.yaml (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.yaml`: You are well-versed in writing and reviewing YAML configurations for the Task tool (https://taskfile.dev/). Provide recommendations for clarity, maintainability, and a...

**/*.yaml: You are well-versed in writing and reviewing YAML configurations for the Task tool (https://taskfile.dev/).
Provide recommendations for clarity, maintainability, and adherence to Taskfile best practices, including usage of variables, environment blocks, and includes.
These configurations may also contain embedded Bash scripts or commands.
Demonstrate bash scripting best practices such as error handling, secure variable expansions, and clear documentation.

  • lib/os-modules/Taskfile.yaml
🔇 Additional comments (4)
lib/os-modules/Taskfile.yaml (4)

11-11: Module list update is correct.
Replacing terraform-postgres-automation with terraform-postgres-config-dbs-users-roles in DEFAULT_MODULES aligns with the new repository name and looks good.


84-84: Skip: Informational pull log.
This echo is purely informational and doesn’t require changes.


88-88: Skip: Branch creation announcement.
The log helps with clarity; no action needed here.


163-163: Verify DELETE_EXISTING_SYNC_BRANCH propagation in sync-all.
You’ve added DELETE_EXISTING_SYNC_BRANCH under sync-all, but Task’s variable scoping may not automatically pass it to the pull-and-branch subtask. Please confirm that this flag is honored downstream or explicitly pass it when invoking task: pull-and-branch.

Comment on lines +91 to +103
if git branch --list "{{.SYNC_BRANCH}}" | grep -q "{{.SYNC_BRANCH}}" && [ "{{.DELETE_EXISTING_SYNC_BRANCH}}" = "false" ]; then
echo "⏭️ Branch {{.SYNC_BRANCH}} already exists, skipping creation."

# If branch exists and delete option is turned on - delete and create new branch
elif git branch --list "{{.SYNC_BRANCH}}" | grep -q "{{.SYNC_BRANCH}}" && [ "{{.DELETE_EXISTING_SYNC_BRANCH}}" = "true" ]; then
echo "⏭️ Branch {{.SYNC_BRANCH}} already exists, deleting it."
git branch -D {{.SYNC_BRANCH}}
git checkout -b {{.SYNC_BRANCH}}

# If branch does not exist - create new branch
else
git checkout -b {{.SYNC_BRANCH}}
fi
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Use a more robust branch-existence check.
Relying on git branch --list | grep can match substrings or aliases. Instead, use:

git rev-parse --verify --quiet "refs/heads/{{.SYNC_BRANCH}}"

to detect exactly whether the branch exists. For example:

- if git branch --list "{{.SYNC_BRANCH}}" | grep -q "{{.SYNC_BRANCH}}"
+ if git rev-parse --verify --quiet "refs/heads/{{.SYNC_BRANCH}}"; then

Also consider handling remote branches (prune or delete them if needed) and ensuring any branch deletion errors abort the task.

🤖 Prompt for AI Agents
In lib/os-modules/Taskfile.yaml around lines 91 to 103, the current branch
existence check using 'git branch --list | grep' can produce false positives by
matching substrings. Replace this with 'git rev-parse --verify --quiet
"refs/heads/{{.SYNC_BRANCH}}"' to precisely check if the branch exists.
Additionally, enhance the script to handle remote branches by pruning or
deleting them if necessary, and ensure that any errors during branch deletion
cause the task to abort to prevent inconsistent states.

Comment on lines +70 to 71
DELETE_EXISTING_SYNC_BRANCH: "{{.DELETE_EXISTING_SYNC_BRANCH | default false}}"
cmds:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Promote DELETE_EXISTING_SYNC_BRANCH to global vars.
You’ve duplicated DELETE_EXISTING_SYNC_BRANCH in both pull-and-branch and sync-all. Extracting it into the top-level vars: block will DRY up this Taskfile and guarantee it’s available to all tasks and subtasks without redefinition.

🤖 Prompt for AI Agents
In lib/os-modules/Taskfile.yaml around lines 70 to 71, the variable
DELETE_EXISTING_SYNC_BRANCH is duplicated in both pull-and-branch and sync-all
tasks. To fix this, move the DELETE_EXISTING_SYNC_BRANCH definition from these
individual tasks into the top-level vars: block of the Taskfile. This will make
the variable globally available to all tasks and subtasks, eliminating
duplication and improving maintainability.

Copy link
Member

@gberenice gberenice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff!

@westonplatter westonplatter merged commit 0b2ddc3 into main May 23, 2025
2 checks passed
@westonplatter westonplatter deleted the feat/add-more-options-to-sync-process branch May 23, 2025 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants