Testing git runner

This commit is contained in:
Václav Valíček (YCNet) 2018-02-22 22:09:11 +01:00
parent 3b757304f7
commit 8c4f64cf96
No known key found for this signature in database
GPG Key ID: 7CF44871CEA75938
5 changed files with 142 additions and 0 deletions

29
checker/detector-lib-cfg Normal file
View File

@ -0,0 +1,29 @@
#!/bin/bash
# check if varriable is set
[ -n "$CONFIG_DIR" ] || die "ConfigDir is not set - exit!"
function detectorRunCapable(){
if [ -f $CONFIG_DIR/detector.cfg ]
then
return 0
else
return 1
fi
}
function detectorLoadConfig(){
# load config
source $CONFIG_DIR/detector.cfg
# create cache dirs
DET_DIR=$CCLONE_CACHE/detector
DET_TAGS=$DET_DIR/tags
DET_BRANCHES=$DET_DIR/branches
[ -d $DET_TAGS ] || mkdir -p $DET_TAGS
[ -d $DET_BRANCHES ] || mkdir -p $DET_BRANCHES
}

37
checker/detector-lib-git Normal file
View File

@ -0,0 +1,37 @@
#!/bin/bash
function detectorSum(){
local dir=$1
[ -f $dir/FETCH_HEAD ] || touch $dir/FETCH_HEAD
# use md5sum - it is in busybox
cat $dir/FETCH_HEAD | md5sum | cut -f1 -d' '
}
function detectorSumPersist(){
detectorSum $1 > $CCLONE_CACHE/detectorSum
}
function detectorCheckFetchHead(){
# check if repo fetch_head changed, if so, return 1
local dir=$1
[ -f $CCLONE_CACHE/detectorSum ] || touch $CCLONE_CACHE/detectorSum
newSum=$(detectorSum $dir)
oldSum=$(cat $CCLONE_CACHE/detectorSum)
if [ "x$oldSum" = "x$newSum" ]
then
return 0
else
return 1
fi
}
function gitListTags(){
local dir=$1
git --no-paginate --git-dir="$dir" tag -l
}

11
checker/notify-commit Executable file
View File

@ -0,0 +1,11 @@
#!/bin/bash
# notify on commit push
#
# Parameters (via env)
#
# COMMIT - hash of commit
# COMMIT_AUTHOR - author of commit
# COMMIT_BRANCH - name of branch
# PROJECT_NAME - project name specified in cloner.cfg
echo "Commit: ($COMMIT: (AUTHOR=$COMMIT_AUTHOR; BRANCH=$COMMIT_BRANCH), Project: $PROJECT_NAME)"

11
checker/notify-tag Executable file
View File

@ -0,0 +1,11 @@
#!/bin/bash
# notify on tag push (new tag or change)
#
# Parameters (via env)
#
# TAG_HASH - hash of tagged commit
# TAG_NAME - tag label
# TAG_AUTHOR - who authored the tag - if available
# PROJECT_NAME - name of project specified in cloner.cfg
echo "TAG: (Name=$TAG_NAME; AUTHOR=$TAG_AUTHOR; SHA: $TAG_HASH), PROJECT: $PROJECT_NAME"

View File

@ -7,6 +7,7 @@ mydir=$(dirname $(realpath $0))
source $mydir/cloner-lib-general source $mydir/cloner-lib-general
source $mydir/cloner-lib-auth source $mydir/cloner-lib-auth
source $mydir/cloner-lib-cfg source $mydir/cloner-lib-cfg
source $mydir/detector-lib-cfg
# interval - in minutes # interval - in minutes
@ -46,4 +47,57 @@ fi
date +"%s" > $stampfile date +"%s" > $stampfile
# 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
# tags that changed or was pushed as new
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
# TAG_AUTHOR
git --git-dir $repodir log $newsha -1 --pretty=format:"%an"
fi
done
# save hash to keep things clear
#detectorSumPersist $repodir