Skip to content

Commit 0b2ddc3

Browse files
feat: small solutions for running task os:sync-all (#23)
## 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`. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## 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. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent de411c2 commit 0b2ddc3

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

lib/os-modules/Taskfile.yaml

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ vars:
88
terraform-github-teams \
99
terraform-github-organization \
1010
terraform-googleworkspace-users-groups-automation \
11-
terraform-postgres-automation \
11+
terraform-postgres-config-dbs-users-roles \
1212
terraform-secrets-helper \
1313
terraform-spacelift-automation \
1414
terraform-spacelift-aws-integrations \
@@ -67,19 +67,41 @@ tasks:
6767
6868
vars:
6969
MODULES: "{{if .CLI_ARGS}}{{.CLI_ARGS}}{{else}}{{.DEFAULT_MODULES}}{{end}}"
70+
DELETE_EXISTING_SYNC_BRANCH: "{{.DELETE_EXISTING_SYNC_BRANCH | default false}}"
7071
cmds:
7172
- |
7273
# Convert newlines to spaces and remove backslashes
7374
modules=$(echo "{{.MODULES}}" | tr '\n' ' ' | sed 's/\\//g')
7475
for module in $modules
7576
do
76-
echo "🚀 Processing ../$module..."
77+
echo -e "\n\n🚀 Processing ---------------- $module \n"
78+
if [ ! -d ../$module ]; then
79+
echo "🧲 Cloning repository..."
80+
git clone "[email protected]:masterpointio/$module.git" ../$module
81+
fi
7782
cd ../$module
78-
echo "⬇️ Pulling main branch..."
83+
84+
echo "⬇️ Pulling main branch..."
7985
git checkout main
8086
git pull origin main
81-
echo "🔄 Creating sync branch..."
82-
git checkout -b {{.SYNC_BRANCH}}
87+
88+
echo "🔄 Creating sync branch ..."
89+
90+
# If branch exists and delete option is turned off - skip creation
91+
if git branch --list "{{.SYNC_BRANCH}}" | grep -q "{{.SYNC_BRANCH}}" && [ "{{.DELETE_EXISTING_SYNC_BRANCH}}" = "false" ]; then
92+
echo "⏭️ Branch {{.SYNC_BRANCH}} already exists, skipping creation."
93+
94+
# If branch exists and delete option is turned on - delete and create new branch
95+
elif git branch --list "{{.SYNC_BRANCH}}" | grep -q "{{.SYNC_BRANCH}}" && [ "{{.DELETE_EXISTING_SYNC_BRANCH}}" = "true" ]; then
96+
echo "⏭️ Branch {{.SYNC_BRANCH}} already exists, deleting it."
97+
git branch -D {{.SYNC_BRANCH}}
98+
git checkout -b {{.SYNC_BRANCH}}
99+
100+
# If branch does not exist - create new branch
101+
else
102+
git checkout -b {{.SYNC_BRANCH}}
103+
fi
104+
83105
cd -
84106
done
85107
@@ -138,6 +160,7 @@ tasks:
138160
139161
vars:
140162
MODULES: "{{if .CLI_ARGS}}{{.CLI_ARGS}}{{else}}{{.DEFAULT_MODULES}}{{end}}"
163+
DELETE_EXISTING_SYNC_BRANCH: "{{.DELETE_EXISTING_SYNC_BRANCH | default false}}"
141164
cmds:
142165
- task: setup-template
143166
- task: pull-and-branch

0 commit comments

Comments
 (0)