repo-cloner/checker/run-checker

115 lines
2.2 KiB
Plaintext
Raw Normal View History

#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
# source libs
mydir=$(dirname $(realpath $0))
source $mydir/cloner-lib-general
source $mydir/cloner-lib-auth
source $mydir/cloner-lib-cfg
2018-02-22 22:09:11 +01:00
source $mydir/detector-lib-cfg
# interval - in minutes
interval=${cloner_interval:-0}
stampfile=$CCLONE_CACHE/last-check-time
# does it exist - if not, sync
[ -d $CCLONE_CACHE ] || mkdir $CCLONE_CACHE
[ -f $stampfile ] || echo 0 > $stampfile
now=$(date +"%s")
last=$(cat $stampfile)
diff=$(($now - $last))
mindiff=$(($interval * 60))
unset now last
if [ $diff -lt $mindiff ]
then
echo "Limit not reached - not syncing now"
exit 0
fi
# check and clone repo
submodules=${cloner_submodules:-0}
depth=${cloner_submodule_depth:-}
export HOME=$CCLONE_CACHE
prepareGitAuth $CONFIG_DIR
# without submodule support
if [ ! "x$submodules" = "x1" ]
then
mirror-main-repo $repo
else
mirror-recursive $repo $depth
fi
date +"%s" > $stampfile
2018-02-22 22:09:11 +01:00
# if detector is not enabled, quit quietly
if ! detectorRunCapable
then
exit 0
fi
source $mydir/detector-lib-git
detectorLoadConfig
repodir=$(gen-mirror-path $repo)
if detectorCheckFetchHead $repodir
then
# nothing changed, just die
exit 0
fi
# now, the fun begins!
# first, solve commits
# solve tags - remove nonexistent refs
find $DET_TAGS -type f | sort | while read tagname
do
tag=$(basename $tagname)
if ! git --git-dir $repodir tag -l | grep -q "^$tag$"
then
echo "Removing tag: $tag (was [$(cat $tagname)])"
rm $tagname
fi
done
2018-02-23 11:42:13 +01:00
# tags that changed or were pushed as new
2018-02-22 22:09:11 +01:00
git --git-dir $repodir tag -l | while read tagname
do
[ -f $DET_TAGS/$tagname ] || touch $DET_TAGS/$tagname
oldsha=$(cat $DET_TAGS/$tagname)
newsha=$(git --git-dir $repodir show-ref $tagname | cut -d' ' -f1)
if ! [ "$oldsha" = "$newsha" ]
then
# TAG_HASH = $newsha
2018-02-23 11:42:13 +01:00
# TAG_NAME = $tagname
2018-02-22 22:09:11 +01:00
# TAG_AUTHOR
2018-02-23 11:42:13 +01:00
author=$(git --git-dir $repodir log $newsha -1 --pretty=format:"%an <%ae>")
# PROJECT_NAME = $cloner_project_name
# call the notify script
set +e
env TAG_HASH="$newsha" \
TAG_NAME="$tagname" \
TAG_AUTHOR="$author" \
PROJECT_NAME="$cloner_project_name" \
notify-tag
rc=$?
[ $rc -eq 0 ] || echo "Notify $tagname: return code = $rc"
set -e
2018-02-22 22:09:11 +01:00
fi
done
# save hash to keep things clear
#detectorSumPersist $repodir