-
Notifications
You must be signed in to change notification settings - Fork 0
/
dcover
executable file
·44 lines (35 loc) · 1.12 KB
/
dcover
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env bash
# dcover checks the coverage impact of merging the current Go monorepo branch
# into main.
#
# Uses colordiff: https://formulae.brew.sh/formula/colordiff
#
# Example:
# git checkout featurebranch
# dcover
set -e
tmp_dir=$(mktemp -d -t dcover)
# Get feature (current) branch name.
head=$(git rev-parse --abbrev-ref HEAD)
# Get main branch name.
main=$(mainbranch)
if [ "$head" = "$main" ]; then
blog error "mainbranch returns $main; run dcover on a feature branch."
exit
fi
# Profile main branch.
blog info "Profiling $main..."
git checkout "$main"
go test -coverprofile "$tmp_dir/main.out" ./...
mainCover=$(go tool cover -func="$tmp_dir/main.out" | tr -s '\t')
# Profile feature branch.
blog info "Profiling $head..."
git checkout "$head"
go test -coverprofile "$tmp_dir/branch.out" ./...
branchCover=$(go tool cover -func="$tmp_dir/branch.out" | tr -s '\t')
# An improved version would iterate over the tabular data and output comparisons
# package-by-package.
echo # Spacing.
blog info "Coverage impact of $head:"
colordiff --ignore-space-change <(echo "$mainCover") <(echo "$branchCover")
rm -rf "$tmp_dir"