improve clone and pull scripts
This commit is contained in:
parent
c97e8f0eb8
commit
e63c5e5882
|
|
@ -2,6 +2,7 @@
|
||||||
__pycache__/
|
__pycache__/
|
||||||
*.py[cod]
|
*.py[cod]
|
||||||
*$py.class
|
*$py.class
|
||||||
|
.history
|
||||||
|
|
||||||
# C extensions
|
# C extensions
|
||||||
*.so
|
*.so
|
||||||
|
|
@ -114,8 +115,6 @@ venv.bak/
|
||||||
# Rope project settings
|
# Rope project settings
|
||||||
.ropeproject
|
.ropeproject
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# mypy
|
# mypy
|
||||||
.mypy_cache/
|
.mypy_cache/
|
||||||
.dmypy.json
|
.dmypy.json
|
||||||
|
|
|
||||||
55
clone.sh
55
clone.sh
|
|
@ -4,6 +4,9 @@
|
||||||
USERNAME=$1
|
USERNAME=$1
|
||||||
TOKEN=$2
|
TOKEN=$2
|
||||||
|
|
||||||
|
# Retry limit for failed clone attempts
|
||||||
|
RETRY_LIMIT=3
|
||||||
|
|
||||||
# Branch types and their corresponding directories
|
# Branch types and their corresponding directories
|
||||||
declare -A branch_dirs=(
|
declare -A branch_dirs=(
|
||||||
["dev"]="test"
|
["dev"]="test"
|
||||||
|
|
@ -72,6 +75,33 @@ branches=(
|
||||||
"master_openeducat_erp-14.0.1.0"
|
"master_openeducat_erp-14.0.1.0"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Error log file
|
||||||
|
error_log="clone_error_log.txt" > "$error_log" # Clear log file at the start
|
||||||
|
|
||||||
|
# Clone branch function with retry mechanism
|
||||||
|
clone_branch() {
|
||||||
|
local branch=$1
|
||||||
|
local full_path=$2
|
||||||
|
local attempt=1
|
||||||
|
|
||||||
|
while [ $attempt -le $RETRY_LIMIT ]; do
|
||||||
|
echo "Cloning $branch into $full_path (Attempt $attempt/$RETRY_LIMIT)..."
|
||||||
|
git clone --depth=1 -b "$branch" "https://$USERNAME:$TOKEN@github.com/expsa/odex25-standard-modules.git" "$full_path"
|
||||||
|
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo "Successfully cloned $branch into $full_path"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
echo "Failed to clone $branch (Attempt $attempt)."
|
||||||
|
attempt=$((attempt + 1))
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# If the retry limit is reached, log the failure
|
||||||
|
echo "Failed to clone $branch after $RETRY_LIMIT attempts." >> "$error_log"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
# Loop through each branch
|
# Loop through each branch
|
||||||
for branch in "${branches[@]}"; do
|
for branch in "${branches[@]}"; do
|
||||||
# Extract the prefix (dev, preprod, master) and the branch name
|
# Extract the prefix (dev, preprod, master) and the branch name
|
||||||
|
|
@ -84,17 +114,22 @@ for branch in "${branches[@]}"; do
|
||||||
# Full path for the folder inside the corresponding directory
|
# Full path for the folder inside the corresponding directory
|
||||||
full_path="$base_dir/$folder_name"
|
full_path="$base_dir/$folder_name"
|
||||||
|
|
||||||
|
# Skip cloning if the folder already exists
|
||||||
|
if [ -d "$full_path" ]; then
|
||||||
|
echo "Skipping $branch: already cloned in $full_path"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
# Create the directory if it doesn't exist
|
# Create the directory if it doesn't exist
|
||||||
mkdir -p "$full_path"
|
mkdir -p "$full_path"
|
||||||
|
|
||||||
# Clone the specific branch into the designated folder using token-based authentication
|
# Clone the specific branch with error handling
|
||||||
git clone --depth=1 -b "$branch" "https://$USERNAME:$TOKEN@github.com/expsa/odex25-standard-modules.git" "$full_path"
|
clone_branch "$branch" "$full_path"
|
||||||
|
|
||||||
# Check if the clone was successful
|
|
||||||
if [ $? -eq 0 ]; then
|
|
||||||
echo "Successfully cloned $branch into $full_path"
|
|
||||||
else
|
|
||||||
echo "Failed to clone $branch"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Check if any errors were logged
|
||||||
|
if [ -s "$error_log" ]; then
|
||||||
|
echo "Some branches failed to clone. Check $error_log for details."
|
||||||
|
else
|
||||||
|
echo "All branches cloned successfully."
|
||||||
|
fi
|
||||||
|
|
|
||||||
67
pull.sh
67
pull.sh
|
|
@ -3,6 +3,9 @@
|
||||||
# Branch to process (test, preprod, master)
|
# Branch to process (test, preprod, master)
|
||||||
BRANCH=$1
|
BRANCH=$1
|
||||||
|
|
||||||
|
# Retry limit for failed pull attempts
|
||||||
|
RETRY_LIMIT=3
|
||||||
|
|
||||||
# Branch types and their corresponding directories
|
# Branch types and their corresponding directories
|
||||||
declare -A branch_dirs=(
|
declare -A branch_dirs=(
|
||||||
["dev"]="test"
|
["dev"]="test"
|
||||||
|
|
@ -71,6 +74,40 @@ branches=(
|
||||||
"master_openeducat_erp-14.0.1.0"
|
"master_openeducat_erp-14.0.1.0"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Error log file
|
||||||
|
error_log="pull_error_log.txt" > "$error_log" # Clear log file at the start
|
||||||
|
|
||||||
|
# Function to pull code with retries
|
||||||
|
pull_branch() {
|
||||||
|
local branch=$1
|
||||||
|
local full_path=$2
|
||||||
|
local attempt=1
|
||||||
|
|
||||||
|
while [ $attempt -le $RETRY_LIMIT ]; do
|
||||||
|
echo "Pulling $branch into $full_path (Attempt $attempt/$RETRY_LIMIT)..."
|
||||||
|
|
||||||
|
# Navigate to the directory and pull the latest changes
|
||||||
|
cd "$full_path" || { echo "Failed to access $full_path"; exit 1; }
|
||||||
|
git pull origin "$branch"
|
||||||
|
local pull_status=$?
|
||||||
|
|
||||||
|
# Return to the previous directory
|
||||||
|
cd - || exit 1
|
||||||
|
|
||||||
|
if [ $pull_status -eq 0 ]; then
|
||||||
|
echo "Successfully pulled $branch into $full_path"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
echo "Failed to pull $branch (Attempt $attempt)."
|
||||||
|
attempt=$((attempt + 1))
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# If retry limit is reached, log the failure
|
||||||
|
echo "Failed to pull $branch after $RETRY_LIMIT attempts." >> "$error_log"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
# Loop through each branch
|
# Loop through each branch
|
||||||
for branch in "${branches[@]}"; do
|
for branch in "${branches[@]}"; do
|
||||||
prefix="${branch%%_*}"
|
prefix="${branch%%_*}"
|
||||||
|
|
@ -80,24 +117,20 @@ for branch in "${branches[@]}"; do
|
||||||
folder_name="${branch#*_}"
|
folder_name="${branch#*_}"
|
||||||
full_path="$BRANCH/$folder_name"
|
full_path="$BRANCH/$folder_name"
|
||||||
|
|
||||||
# Create the directory if it doesn't exist
|
# Skip the branch if the directory does not exist
|
||||||
mkdir -p "$full_path"
|
if [ ! -d "$full_path" ]; then
|
||||||
|
echo "Skipping $branch: $full_path does not exist"
|
||||||
# Navigate to the directory
|
continue
|
||||||
cd "$full_path" || { echo "Failed to access $full_path"; exit 1; }
|
|
||||||
|
|
||||||
# Pull the latest changes
|
|
||||||
git pull origin "$branch"
|
|
||||||
|
|
||||||
# Check if the pull was successful
|
|
||||||
if [ $? -eq 0 ]; then
|
|
||||||
echo "Successfully pulled $branch into $full_path"
|
|
||||||
else
|
|
||||||
echo "Failed to pull $branch"
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Return to the previous directory
|
# Pull the branch with error handling
|
||||||
cd - > /dev/null
|
pull_branch "$branch" "$full_path"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Check if any errors were logged
|
||||||
|
if [ -s "$error_log" ]; then
|
||||||
|
echo "Some branches failed to pull. Check $error_log for details."
|
||||||
|
else
|
||||||
|
echo "All branches pulled successfully."
|
||||||
|
fi
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue