check submodule updates when task.subupdates is set

This commit is contained in:
southerntofu 2020-09-16 14:42:21 +02:00
parent d41c474275
commit fcb60d97b9
1 changed files with 60 additions and 41 deletions

View File

@ -87,10 +87,10 @@ if [ ! -z $LOG ] && [ "$LOG" != "" ]; then
fi fi
run() { run() {
p_name="$1" p_name="$1"
i18n_task="$p_name" info run i18n_task="$p_name" info run
# Run in background and redirect output to $p_name.log # Run in background and redirect output to $p_name.log
#(GITBUILDCONF="$CONFDIR" GITBUILDDIR="$BASEDIR" nohup $BASEDIR/$p_name $p_name > $BASEDIR/$p_name.log 2>&1) & #(GITBUILDCONF="$CONFDIR" GITBUILDDIR="$BASEDIR" nohup $BASEDIR/$p_name $p_name > $BASEDIR/$p_name.log 2>&1) &
GITBUILDCONF="$CONFDIR" GITBUILDDIR="$BASEDIR" $BASEDIR/$p_name $p_name > $BASEDIR/$p_name.log 2>&1 GITBUILDCONF="$CONFDIR" GITBUILDDIR="$BASEDIR" $BASEDIR/$p_name $p_name > $BASEDIR/$p_name.log 2>&1
} }
@ -111,15 +111,15 @@ for arg in "$@"; do
FOUND_BASEDIR=0 FOUND_BASEDIR=0
elif [[ "$arg" = "-f" ]] || [[ "$arg" = "--force" ]]; then elif [[ "$arg" = "-f" ]] || [[ "$arg" = "--force" ]]; then
info force_flag info force_flag
FORCE=1 FORCE=1
elif [[ "$arg" = "-b" ]] || [[ "$arg" = "--basedir" ]]; then elif [[ "$arg" = "-b" ]] || [[ "$arg" = "--basedir" ]]; then
FOUND_BASEDIR=1 FOUND_BASEDIR=1
# Maybe it's a task name and we find a corresponding source? # Maybe it's a task name and we find a corresponding source?
# TODO: Support source-less tasks https://tildegit.org/southerntofu/git-build.sh/issues/8 # TODO: Support source-less tasks https://tildegit.org/southerntofu/git-build.sh/issues/8
elif [ -f $BASEDIR/$arg.source ]; then elif [ -f $BASEDIR/$arg.source ]; then
export i18n_task="$arg" export i18n_task="$arg"
debug found_task debug found_task
PROJECTS+=("$arg") PROJECTS+=("$arg")
# Maybe it's a repo URL and we find a corresponding task? # Maybe it's a repo URL and we find a corresponding task?
elif matches="$(grep --files-with-matches --word-regexp "$arg" $BASEDIR/*.source)"; then elif matches="$(grep --files-with-matches --word-regexp "$arg" $BASEDIR/*.source)"; then
# Iterate over the files found to extract the task name # Iterate over the files found to extract the task name
@ -136,7 +136,7 @@ for arg in "$@"; do
export i18n_arg="$arg" export i18n_arg="$arg"
error unknown_arg error unknown_arg
exit 1 exit 1
fi fi
done done
# Still the default BASEDIR, if it doesn't exist we create it as a convenience # Still the default BASEDIR, if it doesn't exist we create it as a convenience
@ -152,13 +152,13 @@ echo "$BASHPID" > $BASEDIR/.LOCK
if [[ ${#PROJECTS[*]} = 0 ]]; then if [[ ${#PROJECTS[*]} = 0 ]]; then
info no_task info no_task
# TODO: sourceless tasks # TODO: sourceless tasks
for file in $BASEDIR/*.source; do for file in $BASEDIR/*.source; do
# Extract the project name from path # Extract the project name from path
task="$(basename $file .source)" task="$(basename $file .source)"
export i18n_task="$task" export i18n_task="$task"
debug found_task debug found_task
PROJECTS+=("$task") PROJECTS+=("$task")
done done
fi fi
@ -175,7 +175,7 @@ for p_name in ${PROJECTS[*]}; do
# For translations # For translations
export i18n_task="$p_name" export i18n_task="$p_name"
debug start_proc debug start_proc
# Check if task should run on host # Check if task should run on host
if [ -f $BASEDIR/$p_name.hosts ]; then if [ -f $BASEDIR/$p_name.hosts ]; then
if ! grep "^\s*$HOSTNAME\s*$" $BASEDIR/$p_name.hosts > /dev/null; then if ! grep "^\s*$HOSTNAME\s*$" $BASEDIR/$p_name.hosts > /dev/null; then
# The task is specifically configured for different hosts, ignore # The task is specifically configured for different hosts, ignore
@ -189,9 +189,9 @@ for p_name in ${PROJECTS[*]}; do
info host_ignored info host_ignored
continue continue
fi fi
info process info process
# checkout a specific branch/commit # checkout a specific branch/commit
if [ -f $BASEDIR/$p_name.checkout ]; then if [ -f $BASEDIR/$p_name.checkout ]; then
p_branch="$(cat $BASEDIR/$p_name.checkout)" p_branch="$(cat $BASEDIR/$p_name.checkout)"
export i18n_branch="$p_branch" export i18n_branch="$p_branch"
info to_branch info to_branch
@ -201,48 +201,67 @@ for p_name in ${PROJECTS[*]}; do
export i18n_branch="$p_branch" export i18n_branch="$p_branch"
debug default_branch debug default_branch
fi fi
p_dir="$BASEDIR/.$p_name" p_dir="$BASEDIR/.$p_name"
if [ ! -d $p_dir ]; then if [ ! -d $p_dir ]; then
source="$(cat $BASEDIR/$p_name.source)" source="$(cat $BASEDIR/$p_name.source)"
export i18n_source="$source" export i18n_source="$source"
info clone info clone
# Don't forget the git submodules! # Don't forget the git submodules!
if ! git clone --recursive "$source" "$p_dir"; then if ! git clone --recursive "$source" "$p_dir"; then
error clone_failed error clone_failed
exit 1 exit 1
fi fi
cd $p_dir cd $p_dir
if [[ "$p_branch" != "master" ]]; then if [[ "$p_branch" != "master" ]]; then
debug checkout debug checkout
if ! git checkout "$p_branch"; then if ! git checkout "$p_branch"; then
error checkout_failed error checkout_failed
exit 1 exit 1
fi fi
fi fi
run $p_name run $p_name
# Skip to the next task! # Skip to the next task!
continue continue
fi fi
debug already_cloned debug already_cloned
cd "$p_dir" cd "$p_dir"
# Refresh remote before comparing with local # Refresh remote before comparing with local
git fetch --quiet origin if ! git fetch --quiet origin; then
git diff --quiet remotes/origin/$p_branch error pull_failed
if [[ $? != 0 ]]; then exit 1
info pull fi
# Update all submodules, for now only when the main repo changed (TODO) git diff --quiet remotes/origin/$p_branch
if ! git pull --quiet --recurse-submodules; then if [[ $? != 0 ]]; then
info pull
if ! git pull --quiet; then #--recurse-submodules; then
error pull_failed error pull_failed
exit 1 exit 1
fi fi
run $p_name run $p_name
# If no update was found, we can still force rebuild with -f/--force # If no update was found, we can still force rebuild with -f/--force
elif [[ $FORCE = 1 ]]; then elif [[ $FORCE = 1 ]]; then
debug forcing debug forcing
run $p_name run $p_name
else else
debug no_update # No update on the primary branch, but maybe there's a submodule update?
fi if [ -f $BASEDIR/$p_name.subupdates ]; then
git submodule foreach --recursive 'if ! git fetch --quiet origin; then\
error pull_failed\
exit 1\
fi\
git diff --quiet remotes/origin/$(git rev-parse --abbrev-ref HEAD)\
if [[ $? != 0 ]]; then\
info pull\
if ! git pull --quiet; then\
error pull_failed\
exit 1\
fi\
fi'
run $p_name
else
debug no_update
fi
fi
done done
# Check the PID in lockfile is still ours, we don't want # Check the PID in lockfile is still ours, we don't want