Skip to content

Commit

Permalink
[CLD-7696]check if gitops repo exists; get repo latest changes
Browse files Browse the repository at this point in the history
  • Loading branch information
andrleite committed Sep 12, 2024
1 parent 7190c4b commit 9eca24b
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions aws/eks-customer/scripts/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,24 @@ function escape_string() {
echo "$escaped"
}

function while_repo_exists() { #This is to avoid github race condition errors when we have multiple clusters.
# while ls . | grep -E 'gitops-sre-.*'; do
# echo "Waiting for gitops-sre dir to be removed"
# sleep 5
# done
while true; do
if ls "." | grep -E "gitops-sre-.*"; then
echo "Directory matching the pattern exists."
sleep 3
else
echo "No matching directory found. Retrying..."
break
fi
done
}

function clone_repo() {
sleep $((5 + RANDOM % 50)) # Random sleep
echo "Cloning repo $GIT_REPO_URL"
if [ -z "$GIT_REPO_URL" ]; then
echo "Git URL is empty"
Expand All @@ -21,22 +38,18 @@ function clone_repo() {
git clone $GIT_REPO_URL $gitops_sre_dir
}

function while_repo_exists() { #This is to avoid github race condition errors when we have multiple clusters.
while ls -d "gitops-sre-*" 1> /dev/null 2>&1; do
echo "Waiting for gitops-sre dir to be removed"
sleep 5
done
}

function stage_changes() {
echo "Staging changes"

file_path=$1

repo_path=$(dirname $file_path)
file_name=$(basename $file_path)
current_dir=$(pwd)

cd $repo_path || exit
echo "Pulling latest changes"
git pull origin main
git add "$file_name"
cd $current_dir || exit
}
Expand Down

0 comments on commit 9eca24b

Please sign in to comment.