Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Improve Bash script based on feedback #185

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions script/coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,37 @@ set -o errexit
set -o pipefail

main() {
local fail=0
_cd_into_top_level
_generate_coverage_files
_generate_coverage_files || fail=1
if [ "$fail" -eq 1 ]; then
echo "There was an error while generating coverage files."
exit 1
fi
_combine_coverage_reports
}

_cd_into_top_level() {
cd "$(git rev-parse --show-toplevel)"
local top_level_dir
top_level_dir="$(git rev-parse --show-toplevel)"
cd "$top_level_dir" || {
echo "Unable to change to project root directory." >&2
exit 1
}
}

_generate_coverage_files() {
for dir in $(find . -maxdepth 10 -not -path './.git*' -not -path '*/vendor/*' -not -path '*/mocks/*' -type d); do
if ls $dir/*.go &>/dev/null ; then
go test -covermode=count -coverprofile=$dir/profile.coverprofile $dir || fail=1
local dir fail=0
while IFS= read -r -d '' dir; do
if ls "$dir"/*.go &>/dev/null; then
go test -covermode=count -coverprofile="$dir/profile.coverprofile" "$dir" || fail=1
fi
done
done < <(find . -maxdepth 10 -not -path './.git*' -not -path '*/vendor/*' -not -path '*/mocks/*' -type d -print0)
return "$fail"
}


_combine_coverage_reports() {
gover
}

main "$@"
main "$@"