Skip to content

Commit

Permalink
Merge pull request #223 from talset/master
Browse files Browse the repository at this point in the history
[check] Allow triggering with tag updates
  • Loading branch information
vito committed Dec 11, 2018
2 parents 7255ec1 + 4212b5e commit 885d86e
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 38 deletions.
18 changes: 14 additions & 4 deletions assets/check
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,26 @@ lines_including_and_after() {
sed -ne "/$escaped_string/,$ p"
}

get_commit(){
for tag in $*; do
commit=$(git rev-list -n 1 $tag)
jq -n '{ref: $tag, commit: $commit}' --arg tag $tag --arg commit $commit
done
}

if [ -n "$tag_filter" ]; then
{
if [ -n "$ref" ] && [ -n "$branch" ]; then
git tag --list "$tag_filter" --sort=creatordate --contains $ref
tags=$(git tag --list "$tag_filter" --sort=creatordate --contains $ref)
get_commit $tags
elif [ -n "$ref" ]; then
git tag --list "$tag_filter" --list --sort=creatordate | lines_including_and_after $ref
tags=$(git tag --list "$tag_filter" --sort=creatordate | lines_including_and_after $ref)
get_commit $tags
else
git tag --list "$tag_filter" --sort=creatordate | tail -1
tag=$(git tag --list "$tag_filter" --sort=creatordate | tail -1)
get_commit $tag
fi
} | jq -R '.' | jq -s "map({ref: .})" >&3
} | jq -s "map(.)" >&3
else
{
set -f
Expand Down
4 changes: 2 additions & 2 deletions assets/in
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fi

branchflag=""
if [ -n "$branch" ]; then
branchflag="--single-branch --branch $branch"
branchflag="--branch $branch"
fi

depthflag=""
Expand All @@ -73,7 +73,7 @@ if [ -n "$tag_filter" ]; then
tagflag="--tags"
fi

git clone $depthflag $uri $branchflag $destination $tagflag
git clone --single-branch $depthflag $uri $branchflag $destination $tagflag

cd $destination

Expand Down
63 changes: 32 additions & 31 deletions test/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -423,16 +423,16 @@ it_can_check_with_tag_filter() {
local ref2=$(make_annotated_tag $repo "1.0-staging" "tag 1")
local ref3=$(make_commit $repo)
local ref4=$(make_annotated_tag $repo "1.0-production" "tag 2")
local ref5=$(make_commit $repo)
local ref6=$(make_annotated_tag $repo "2.0-staging" "tag 3")
local ref7=$(make_commit $repo)
local ref8=$(make_annotated_tag $repo "2.0-production" "tag 4")
local ref9=$(make_commit $repo)

local ref5=$(make_annotated_tag $repo "2.0-staging" "tag 3")
local ref6=$(make_commit $repo)
local ref7=$(make_annotated_tag $repo "2.0-staging" "tag 5")
local ref8=$(make_commit $repo)
local ref9=$(make_annotated_tag $repo "2.0-production" "tag 4")
local ref10=$(make_commit $repo)

check_uri_with_tag_filter $repo "*-staging" | jq -e '
. == [{ref: "2.0-staging"}]
'
check_uri_with_tag_filter $repo "*-staging" | jq -e "
. == [{ref: \"2.0-staging\", commit: \"$ref6\"}]
"
}

it_can_check_with_tag_filter_with_cursor() {
Expand All @@ -452,9 +452,9 @@ it_can_check_with_tag_filter_with_cursor() {
local ref13=$(make_commit $repo)

x=$(check_uri_with_tag_filter_from $repo "*-staging" "2.0-staging")
check_uri_with_tag_filter_from $repo "*-staging" "2.0-staging" | jq -e '
. == [{ref: "2.0-staging"}, {ref: "3.0-staging"}]
'
check_uri_with_tag_filter_from $repo "*-staging" "2.0-staging" | jq -e "
. == [{ref: \"2.0-staging\", commit: \"$ref5\"}, {ref: \"3.0-staging\", commit: \"$ref9\"}]
"
}

it_can_check_with_tag_filter_over_all_branches() {
Expand All @@ -473,9 +473,9 @@ it_can_check_with_tag_filter_over_all_branches() {
local ref12=$(make_annotated_tag $repo "3.0-production" "tag 6")
local ref13=$(make_commit_to_branch $repo branch-a)

check_uri_with_tag_filter $repo "*-staging" | jq -e '
. == [{ref: "3.0-staging"}]
'
check_uri_with_tag_filter $repo "*-staging" | jq -e "
. == [{ref: \"3.0-staging\", commit: \"$ref9\"}]
"
}

it_can_check_with_tag_filter_over_all_branches_with_cursor() {
Expand All @@ -484,19 +484,20 @@ it_can_check_with_tag_filter_over_all_branches_with_cursor() {
local ref2=$(make_annotated_tag $repo "1.0-staging" "a tag")
local ref3=$(make_commit_to_branch $repo branch-a)
local ref4=$(make_annotated_tag $repo "1.0-production" "another tag")
local ref5=$(make_commit_to_branch $repo branch-a)
local ref6=$(make_annotated_tag $repo "2.0-staging" "tag 3")
local ref7=$(make_commit_to_branch $repo branch-a)
local ref8=$(make_annotated_tag $repo "2.0-production" "tag 4")
local ref9=$(make_commit_to_branch $repo branch-a)
local ref10=$(make_annotated_tag $repo "3.0-staging" "tag 5")
local ref11=$(make_commit_to_branch $repo branch-a)
local ref12=$(make_annotated_tag $repo "3.0-production" "tag 6")
local ref13=$(make_commit_to_branch $repo branch-a)

check_uri_with_tag_filter_from $repo "*-staging" "2.0-staging" | jq -e '
. == [{ref: "2.0-staging"}, {ref: "3.0-staging"}]
'
local ref5=$(make_annotated_tag $repo "2.0-staging" "tag 3")
local ref6=$(make_commit_to_branch $repo branch-a)
local ref7=$(make_annotated_tag $repo "2.0-staging" "tag 3")
local ref8=$(make_commit_to_branch $repo branch-a)
local ref9=$(make_annotated_tag $repo "2.0-production" "tag 4")
local ref10=$(make_commit_to_branch $repo branch-a)
local ref11=$(make_annotated_tag $repo "3.0-staging" "tag 5")
local ref12=$(make_commit_to_branch $repo branch-a)
local ref13=$(make_annotated_tag $repo "3.0-production" "tag 6")
local ref14=$(make_commit_to_branch $repo branch-a)

check_uri_with_tag_filter_from $repo "*-staging" "2.0-staging" | jq -e "
. == [{ref: \"2.0-staging\", commit: \"$ref6\"}, {ref: \"3.0-staging\", commit: \"$ref10\"}]
"
}

it_can_check_with_tag_filter_with_bogus_ref() {
Expand All @@ -512,9 +513,9 @@ it_can_check_with_tag_filter_with_bogus_ref() {
local ref9=$(make_commit $repo)


check_uri_with_tag_filter_from $repo "*-staging" "bogus-ref" | jq -e '
. == [{ref: "2.0-staging"}]
'
check_uri_with_tag_filter_from $repo "*-staging" "bogus-ref" | jq -e "
. == [{ref: \"2.0-staging\", commit: \"$ref5\"}]
"
}

it_can_check_and_set_git_config() {
Expand Down
2 changes: 1 addition & 1 deletion test/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ make_annotated_tag() {
local tag=$2
local msg=$3

git -C $repo tag -a "$tag" -m "$msg"
git -C $repo tag -f -a "$tag" -m "$msg"

git -C $repo describe --tags --abbrev=0
}
Expand Down

0 comments on commit 885d86e

Please sign in to comment.