From 0630e7d258766f239a6e64b8607e3cce7d055ed7 Mon Sep 17 00:00:00 2001 From: Adriel007 Date: Tue, 16 Apr 2024 22:16:00 -0300 Subject: [PATCH 1/2] feat: Improve Bash script based on feedback This commit enhances the Bash script according to provided feedback: - Improved error handling by initializing the 'fail' variable before usage. - Replaced 'find' with a 'while' loop to handle directory paths with spaces. - Added validation after changing to the project's root directory. - Updated documentation to reflect the changes made. Further enhancements, such as command and Go installation validation checks, are recommended. --- script/coverage.sh | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/script/coverage.sh b/script/coverage.sh index a40d4ae37..b02b5cadc 100755 --- a/script/coverage.sh +++ b/script/coverage.sh @@ -4,24 +4,35 @@ 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 } From 54eeeb6167dc89a9bac9d130489aa7434cc8c165 Mon Sep 17 00:00:00 2001 From: Adriel007 Date: Tue, 23 Apr 2024 07:38:07 -0300 Subject: [PATCH 2/2] Travis CI Removed --- script/coverage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/coverage.sh b/script/coverage.sh index b02b5cadc..98f6a6210 100755 --- a/script/coverage.sh +++ b/script/coverage.sh @@ -37,4 +37,4 @@ _combine_coverage_reports() { gover } -main "$@" \ No newline at end of file +main "$@"