wait for branch with new commit

This commit is contained in:
Michael Hoennig 2024-09-26 13:59:13 +02:00
parent c2ea66a87f
commit e7558cdbe8

View File

@ -1,40 +1,20 @@
#!/bin/bash #!/bin/bash
# waits for commits on any branch on origin, pulls and build it # waits for commits on any branch on origin, checks it out and builds it
# Configuration: Set the remote repository name and check interval # Configuration: Set the remote repository name and check interval
BUILD_CMD="gw-test" # Placeholder for the build command BUILD_CMD="gw-test" # Placeholder for the build command
# Fetch the latest updates from the origin
git fetch origin
# Keep track of local branches at the start
local_branches=$(git branch -r | sed 's/origin\///')
while true; do while true; do
echo "Checking for new branches..." echo "Checking for new commits on any branch ..."
# Fetch the latest updates from the origin
git fetch origin git fetch origin
branch_with_new_commits=`git fetch origin >/dev/null; git for-each-ref --format='%(refname:short) %(upstream:track)' refs/heads | grep '\[behind' | cut -d'[' -f1 | head -n1`
# List the remote branches after fetching and compare with local branches if [ -n "$branch_with_new_commits" ]; then
new_branches=$(git branch -r | sed 's/origin\///' | grep -Fxv "$local_branches") echo "checking out branch: $branch_with_new_commits"
git checkout -b "$branch_with_new_commits" "origin/$branch_with_new_commits"
if [ -n "$new_branches" ]; then echo "building ..."
for branch in $new_branches; do eval "$BUILD_CMD"
echo "New branch detected: $branch"
# Check out the new branch locally
git checkout -b "$branch" "origin/$branch"
# Placeholder for build process (replace $BUILD_CMD with actual build steps)
echo "Building branch $branch..."
# eval "$BUILD_CMD"
# Update the local branch list
local_branches="$local_branches $branch"
done
else
echo "No new branches found."
fi fi
# wait 10s with a little animation # wait 10s with a little animation