36 lines
1.0 KiB
Bash
36 lines
1.0 KiB
Bash
#!/bin/bash
|
|
|
|
# Check if correct number of arguments are provided
|
|
if [ "$#" -ne 2 ]; then
|
|
echo "Usage: $0 <repository_name> <branch_name>"
|
|
exit 1
|
|
fi
|
|
|
|
repository_name="$1"
|
|
branch_name=$(basename "$2")
|
|
|
|
BRANCHES_FOLDER="/html/branches"
|
|
DADI_STAGING_REPOSITORY="git_dadi-staging:AG-IT/KlDaDiSeite.git"
|
|
|
|
# Echo parameters
|
|
echo "Webhook recieved for repository: $repository_name and branch: $branch_name"
|
|
|
|
# Check if the branch directory exists
|
|
branch_dir="$BRANCHES_FOLDER/$(basename "$branch_name")"
|
|
if [ -d "$branch_dir" ]; then
|
|
echo "Directory $branch_dir exists, performing git pull..."
|
|
# Change directory to branch directory
|
|
cd "$branch_dir"
|
|
# Perform git pull
|
|
echo "Updating $branch_dir"
|
|
git pull origin "$(basename "$branch_name")"
|
|
else
|
|
echo "Directory $branch_dir does not exist, cloning branch..."
|
|
# Create branches directory if it doesn't exist
|
|
mkdir -p branches
|
|
# Clone the branch
|
|
git clone --depth 1 --branch "$branch_name" --single-branch "$DADI_STAGING_REPOSITORY" "$branch_dir"
|
|
# reinitialize index.html
|
|
./generate_index_html.sh
|
|
fi
|