-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathTaskfile.yml
184 lines (163 loc) · 4.93 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
version: '3'
env:
GOPATH:
sh: go env GOPATH
VERSION: 0.2
COMMIT_ID:
sh: git describe --tags --always # or: git log -n 1 --format=%h
GOOS:
sh: go env GOOS
GOARCH:
sh: go env GOARCH
LD_FLAGS_WINDOWS: -H=windowsgui
LD_FLAGS_EXTRA: '{{if eq OS "windows"}} {{.LD_FLAGS_WINDOWS}} {{else}} {{end}}'
output: prefixed
tasks:
go_build:
env:
GO111MODULE: on
CGO_ENABLED: 1
cmds:
#- go vet
- rm -f target/batchai.0*
- go clean -cache
- GOOS={{.GOOS}} GOARCH={{.GOARCH}} CGO_ENABLED=0 go build -trimpath -ldflags '-extldflags "-static" -s -w -X main.Version={{.VERSION}} -X main.CommitId={{.COMMIT_ID}} {{.LD_FLAGS_EXTRA}}' -o target/batchai.{{.GOOS}}-{{.GOARCH}}{{.exeExt}} ./cmd/batchai/main.go
mockgen:
cmds:
- task: rm
vars:
TARGET: pkg/{{.MOCK_PKG_DEST}}/{{.MOCK_DEST_FILE}}
- mockgen -destination pkg/{{.MOCK_PKG_DEST}}/{{.MOCK_DEST_FILE}} -package test --build_flags=--mod=mod {{.PROJECT_PKG}}/pkg/{{.MOCK_PKG_SRC}} {{.MOCK_INTERFACE}}
rm:
cmds:
- echo $PATH
- '{{if eq OS "windows"}} powershell Remove-Item {{.TARGET}} -Force -Recurse {{else}} rm -rf {{.TARGET}} {{end}}'
cp:
cmds:
- '{{if eq OS "windows"}} powershell Copy-Item {{.SRC}} {{.TARGET}} -Recurse {{else}} cp -rf {{.SRC}} {{.TARGET}} {{end}}'
init:
desc: init env, including install dependent tools
cmds:
# for linux only
# apt-get install gcc libgtk-3-dev libayatana-appindicator3-dev
- go install github.com/golang/mock/mockgen@v1.6.0
- go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54.2
- go install honnef.co/go/tools/cmd/staticcheck@v0.4.6
- go install mvdan.cc/gofumpt@v0.5.0
- go install github.com/dmarkham/enumer@v1.5.8
- go install github.com/nicksnyder/go-i18n/v2/goi18n@v2.2.1
- go install github.com/rakyll/statik@v0.1.7
mod:
desc: Downloads and tidy Go modules
cmds:
- go mod download
- go mod tidy
- go mod vendor
lint:
desc: Runs golangci-lint
sources:
- './**/*.go'
cmds:
- staticcheck ./...
- golangci-lint run
gen:
desc: run statik etc. to embed resource into generated go source files
cmds:
- statik -src=./res/static -dest=./res -f -include=* -ns=res
#- enumer -gqlgen -json -sql -text -yaml -output pkg/plugin/plugin_kind_generated.go -trimprefix PLUGIN_KIND_ -transform whitespace -transform upper -type PluginKind pkg/plugin/plugin.go
#- task: mockgen
# vars:
# MOCK_DEST_FILE: controller_mock_test.go
# MOCK_PKG_SRC: hosts
# MOCK_PKG_DEST: ui
# MOCK_INTERFACE: Controller
- task: format
clean:
desc: clean target directory
cmds:
- task: rm
vars:
TARGET: target
format:
cmds:
- gofumpt -l -w .
build:
desc: build for development
cmds:
- task: format
- task: go_build
darwin:
desc: release for MacOS
cmds:
- task: go_build
vars:
GOARCH: amd64
GOOS: darwin
- task: go_build
vars:
GOARCH: arm64
GOOS: darwin
linux:
desc: release for linux
cmds:
- task: go_build
vars:
GOARCH: amd64
GOOS: linux
#- upx -9 -k -v target/batchai.linux-amd64
- sudo cp target/batchai.linux-amd64 /usr/bin/batchai
windows:
desc: release for windows
cmds:
- task: go_build
vars:
GOARCH: amd64
GOOS: windows
exeExt: .exe
#- upx -9 -k -v target/batchai.windows-amd64.exe
- task: go_build
vars:
GOARCH: arm64
GOOS: windows
exeExt: .exe
release:
cmds:
- task: clean
- task: gen
- task: build
- task: linux
- task: windows
- task: darwin
run:
cmds:
- task: build
- target/batchai.{{.GOOS}}-{{.GOARCH}}{{exeExt}}
test:
desc: run test cases then create coverage report (./coverage.html)
cmds:
- go test ./... -covermode=count -coverprofile=coverage.out gcflags=all=-l -timeout 30s
- go tool cover -html=./coverage.out -o ./coverage.html
report:
desc: running goreportcard-cli (not yet working)
cmds:
- # gometalinter
- # #https://github.com/alecthomas/gometalinter/releases/tag/v3.0.0
- # curl -L https://git.io/vp6lP | sh
-
- # brew tap alecthomas/homebrew-tap
- # brew install gometalinter
- #
- # go install github.com/gojp/goreportcard/cmd/goreportcard-cli@latest
- #goreportcard-cli -v
- goreportcard-cli
scc:
cmds:
- scc --exclude-dir .git --exclude-dir .task --exclude-dir .vscode --exclude-dir . --exclude-dir target --exclude-dir test --exclude-dir vendor
all:
desc: clean, generating, then build
deps: [clean, gen, test, build]
cmds:
- task: clean
- task: gen
- task: test
- task: build