hs.hsadmin.ng/bin/git-pull-and-if-origin-changed-run-tests
2024-09-26 14:09:44 +02:00

35 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
# waits for commits on any branch on origin, checks it out and builds it
# Configuration: Set the remote repository name and check interval
BUILD_CMD="gw-test" # Placeholder for the build command
while true; do
echo "Checking for new commits on any branch ..."
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`
if [ -n "$branch_with_new_commits" ]; then
echo "checking out branch: $branch_with_new_commits"
echo "git checkout -b \"$branch_with_new_commits\" \"origin/$branch_with_new_commits\""
git checkout -b "$branch_with_new_commits" "origin/$branch_with_new_commits"
echo "building ..."
eval "$BUILD_CMD"
fi
# wait 10s with a little animation
echo -e -n " waiting for changes (/) ..."
sleep 2
echo -e -n "\r\033[K waiting for changes (-) ..."
sleep 2
echo -e -n "\r\033[K waiting for changes (\) ..."
sleep 2
echo -e -n "\r\033[K waiting for changes (|) ..."
sleep 2
echo -e -n "\r\033[K waiting for changes ( ) ... "
sleep 2
echo -e -n "\r\033[K checking for changes"
done