Recongition of new commits for CI
This commit is contained in:
parent
4b44a745e4
commit
8aee30f8d2
20
checker/detector-lib-general
Normal file
20
checker/detector-lib-general
Normal file
|
@ -0,0 +1,20 @@
|
|||
#!/bin/bash
|
||||
|
||||
function detectorCheckCommit(){
|
||||
sha=$1
|
||||
history=$DET_DIR/detectorExecuted
|
||||
[ -f $history ] || touch $history
|
||||
|
||||
if grep -q $sha $history
|
||||
then
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
function detectorSaveCommit(){
|
||||
sha=$1
|
||||
history=$DET_DIR/detectorExecuted
|
||||
echo $sha >> $history
|
||||
}
|
|
@ -32,6 +32,21 @@ function detectorCheckFetchHead(){
|
|||
|
||||
function gitListTags(){
|
||||
local dir=$1
|
||||
git --no-paginate --git-dir="$dir" tag -l
|
||||
git --git-dir="$dir" tag -l | cat
|
||||
|
||||
}
|
||||
|
||||
function gitListBranches(){
|
||||
local dir=$1
|
||||
git --git-dir="$dir" for-each-ref --format='%(refname:short)' refs/heads/
|
||||
}
|
||||
|
||||
|
||||
function gitPrefBranches(){
|
||||
local dir=$1
|
||||
gitListBranches $1 | grep master || true
|
||||
gitListBranches $1 | grep upstream || true
|
||||
gitListBranches $1 | sort | grep -vE 'master|upstream'
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -56,6 +56,7 @@ then
|
|||
fi
|
||||
|
||||
source $mydir/detector-lib-git
|
||||
source $mydir/detector-lib-general
|
||||
|
||||
detectorLoadConfig
|
||||
|
||||
|
@ -67,15 +68,61 @@ then
|
|||
exit 0
|
||||
fi
|
||||
|
||||
# now, the fun begins!
|
||||
|
||||
# first, solve commits
|
||||
# branches that were deleted or merged
|
||||
find $DET_BRANCHES -type f | sort | while read branchpath
|
||||
do
|
||||
branch=$(basename $branchpath)
|
||||
if ! gitListBranches $repodir | grep -q "^$branch$"
|
||||
then
|
||||
echo "Unexistent branch <$branch>!!"
|
||||
# rm it, should be merget etc...
|
||||
rm $DET_BRANCHES/$branch
|
||||
fi
|
||||
done
|
||||
|
||||
# new branches or new commits in curent branches
|
||||
# firstly list master branch, to make first commits in it
|
||||
gitPrefBranches $repodir | while read branch
|
||||
do
|
||||
[ -f $DET_BRANCHES/$branch ] || touch $DET_BRANCHES/$branch
|
||||
oldsha=$(cat $DET_BRANCHES/$branch)
|
||||
newsha=$(git --git-dir $repodir show-ref --heads $branch | cut -d' ' -f1)
|
||||
[ -z "$oldsha" ] || oldsha=$oldsha..
|
||||
# walk through every commit in branch (since last change)
|
||||
for commitId in $(git --no-pager --git-dir $repodir log --reverse --format="%H" $oldsha$branch)
|
||||
do
|
||||
if detectorCheckCommit $commitId
|
||||
then
|
||||
# commit was not processed - start
|
||||
# COMMIT = $commitId
|
||||
# COMMIT_AUTHOR = $author
|
||||
author=$(git --git-dir $repodir log $commitId -1 --format="%an <%ae>")
|
||||
# BRANCH = $branch
|
||||
# PORJECT_NAME = $cloner_project_name
|
||||
|
||||
set +e
|
||||
env COMMIT="$commitId" \
|
||||
COMMIT_AUTHOR="$author" \
|
||||
COMMIT_BRANCH="$branch" \
|
||||
PROJECT_NAME="$cloner_project_name" \
|
||||
notify-commit
|
||||
rc=$?
|
||||
[ $rc -eq 0 ] || echo "Notify $branch/$commitId: return code = $rc"
|
||||
set -e
|
||||
detectorSaveCommit $commitId
|
||||
fi
|
||||
|
||||
done
|
||||
echo $newsha > $DET_BRANCHES/$branch
|
||||
done
|
||||
|
||||
|
||||
# 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$"
|
||||
if ! gitListTags $repodir | grep -q "^$tag$"
|
||||
then
|
||||
echo "Removing tag: $tag (was [$(cat $tagname)])"
|
||||
rm $tagname
|
||||
|
@ -83,11 +130,11 @@ do
|
|||
done
|
||||
|
||||
# tags that changed or were pushed as new
|
||||
git --git-dir $repodir tag -l | while read tagname
|
||||
gitListTags $repodir | 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)
|
||||
newsha=$(git --git-dir $repodir show-ref --tags $tagname | cut -d' ' -f1)
|
||||
if ! [ "$oldsha" = "$newsha" ]
|
||||
then
|
||||
# TAG_HASH = $newsha
|
||||
|
@ -107,6 +154,7 @@ do
|
|||
[ $rc -eq 0 ] || echo "Notify $tagname: return code = $rc"
|
||||
set -e
|
||||
fi
|
||||
echo $newsha > $DET_TAGS/$tagname
|
||||
done
|
||||
|
||||
# save hash to keep things clear
|
||||
|
|
Loading…
Reference in New Issue
Block a user