-
Notifications
You must be signed in to change notification settings - Fork 0
/
Taskfile.yml
149 lines (130 loc) · 3.32 KB
/
Taskfile.yml
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# yaml-language-server: $schema=https://taskfile.dev/schema.json
version: '3'
silent: true
env:
CONTAINER_CLI: docker
BUILD_DIR: bin
GO111MODULE: on
vars:
GO: go
GOLINT: $BUILD_DIR/golint
GO_MODULE:
sh: GO111MODULE=on {{.GO}} list -m
GO_PKGS:
sh: echo "$(GO111MODULE=on {{.GO}} list ./...)" | tr '\n' ' '
GO_EXECUTABLE_EXTENSION: '{{if eq .GOOS "windows"}}.exe{{else}}{{end}}'
tasks:
default:
cmds: [ task -l ]
dep:
desc: Download go dependencies
cmds:
- task: log_info
vars: { msg: getting dependencies... }
- '{{.GO}} mod download'
vet:
desc: Vets code using `go vet`.
cmds:
- task: log_info
vars: { msg: running go vet... }
- '{{.GO}} vet {{.GO_PKGS}}'
fmt:
desc: Formats code using `go fmt`.
cmds:
- task: log_info
vars: { msg: running go fmt... }
- '{{.GO}} fmt {{.GO_PKGS}}'
race:
desc: Run go data race detector
deps:
- task: dep
cmds:
- task: log_info
vars: { msg: running go data race detector... }
- '{{.GO}} test -race -short {{.GO_PKGS}}'
msan:
desc: Run go memory sanitizer
deps:
- task: dep
cmds:
- task: log_info
vars: { msg: running go memory sanitizer... }
- '{{.GO}} test -msan -short {{.GO_PKGS}}'
lint:
desc: Run golint
deps:
- task: install_golint
cmds:
- task: log_info
vars: { msg: running golint... }
- '{{.GOLINT}} -set_exit_status {{.GO_PKGS}}'
install_golint:
desc: Installs golint
internal: true
deps:
- task: build_dir
cmds:
- task: log_info
vars: { msg: installing golint... }
- task: install_go_package
vars:
PACKAGE: golang.org/x/lint/golint@latest
GOBIN: $BUILD_DIR
install_go_package:
desc: Installs a go package
internal: true
env:
GO111MODULE: on
vars:
PACKAGE: '{{.PACKAGE | default ""}}'
GOBIN: '{{.GOBIN }}'
GOBIN_ABS: '{{.USER_WORKING_DIR}}/{{.GOBIN }}'
cmds:
- task: log_info
vars: { msg: 'installing package {{.PACKAGE}} to {{.GOBIN}}...' }
- 'GOBIN={{.GOBIN_ABS}} {{.GO}} install {{.PACKAGE}}'
build:
desc: Builds the executable
deps:
- task: dep
vars:
BINARY:
sh: 'echo {{.BUILD_DIR}}/$(basename {{.GO_MODULE}}){{.GO_EXECUTABLE_EXTENSION}}'
cmds:
- task: log_info
vars: { msg: 'building executable...' }
- 'CGO_ENABLED=0 {{.GO}} build -tags release -v -o {{.BINARY}} main.go'
generates:
- '{{.BINARY}}'
test:
desc: Runs tests with coverage
deps:
- task: build_dir
- task: fmt
- task: vet
vars:
COVERAGE_FILE: $BUILD_DIR/coverage.out
cmds:
- task: log_info
vars: { msg: running tests... }
- '{{.GO}} test {{.GO_PKGS}} -coverprofile {{.COVERAGE_FILE}}'
generates:
- '{{.COVERAGE_FILE}}'
clean:
desc: Cleanup everything.
cmds:
- task: log_info
vars: { msg: cleaning... }
- '{{.GO}} clean'
- rm -rf $BUILD_DIR
log_info:
internal: true
vars:
msg: '{{ .msg | default "info message" }}'
cmds:
- echo $(printf "\033[34;1m▶\033[0m") {{.msg}}
build_dir:
desc: Ensures that the build directory is present.
internal: true
cmds:
- mkdir -p $BUILD_DIR