Skip to content

Commit

Permalink
(#6) Fail build if coverage is low
Browse files Browse the repository at this point in the history
  • Loading branch information
llorllale committed Feb 18, 2019
1 parent 2738cc2 commit 8761324
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ gitlint

" test coverage
coverage.txt
cov_check.txt

" PDD output file
puzzles.xml
1 change: 1 addition & 0 deletions .pdd
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
--exclude coverage.txt
--exclude .gitignore
--exclude go.sum
--exclude cov_check.txt
--rule min-words:20
--rule min-estimate:0
--rule max-estimate:0
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,18 @@ build:
go build -o gitlint cmd/go-gitlint/main.go

test:
go test -count=1 -race -cover -coverprofile=coverage.txt -covermode=atomic ./...
go test -count=1 -race -cover -coverprofile=coverage.txt -covermode=atomic ./... | tee cov_check.txt

coverage:
./check_coverage.sh

lint:
./bin/golangci-lint run

pdd:
pdd --file=puzzles.xml

checks: build lint pdd test
checks: build lint pdd test coverage

release:
./release.sh
33 changes: 33 additions & 0 deletions check_coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash
#
# Copyright 2019 George Aristy
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

let THRESHOLD=80

let exit_code=0

while read line; do
if [ "$(echo $line | grep coverage)" != "" ]; then
pkg=$(echo $line | sed 's/\s\+/ /g' | sed 's/%//' | cut -d ' ' -f 2)
cov=$(echo $line | sed 's/\s\+/ /g' | sed 's/%//' | cut -d ' ' -f 5)
if [ 1 -eq $(echo "$THRESHOLD > $cov" | bc) ]; then
echo "Coverage [$cov] for package [$pkg] is below threshold [$THRESHOLD]"
let exit_code++
fi
fi
done < ./cov_check.txt

exit $exit_code

0 comments on commit 8761324

Please sign in to comment.