forked from chef/go-libs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.studiorc
72 lines (63 loc) · 1.92 KB
/
.studiorc
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
#
# This is the place where you can extend the funcitonality of the studio
hab pkg install chef/studio-common >/dev/null
source "$(hab pkg path chef/studio-common)/bin/studio-common"
# switch all go commands to use the vendor/ directory
export GOFLAGS="-mod=vendor"
cover_dir="coverage"
coverage_out="$cover_dir/coverage.raw"
coverage_txt="$cover_dir/coverage.txt"
coverage_html="$cover_dir/coverage.html"
# updates one or more Go dependencies
function update_deps() {
install_if_missing core/go go
install_if_missing core/git git
( cd /src || return 1
GOFLAGS="" go get -u "$@"
go mod vendor
)
}
# run unit tests
function unit_tests() {
install_if_missing core/go go
install_if_missing core/gcc gcc
install_if_missing core/git git
log_line "Running unit tests"
( cd /src || return 1
mkdir -p $cover_dir
GO_PACKAGES=$(go list ./...)
go test \
-coverprofile=$coverage_out \
-covermode=atomic $GO_PACKAGES || return 1
)
}
document "gocode_generation" <<DOC
Run 'go generate' for code generation
DOC
function gocode_generation() {
install_if_missing core/go go
( cd /src || return 1
go generate ./...
)
}
# run unit tests plus code coverage analysis
function code_coverage() {
( cd /src || return 1
mkdir -p $cover_dir
unit_tests || return 1
log_line "Generating coverage profile information for each function ($(yellow /src/$coverage_txt))"
go tool cover -func=$coverage_out -o $coverage_txt
cat $coverage_txt
log_line "Generate HTML representation of coverage profile"
go tool cover -html=$coverage_out -o $coverage_html
log_line "HTML output written to '$(yellow /src/$coverage_html)' (open file with a web browser)"
)
}
# run an example of a go program that leverages the featflag go library
function featflag_run_example() {
install_if_missing core/go go
( cd /src || return 1
go run github.com/chef/go-libs/featflag/example
)
}