forked from valkyrie-fnd/valkyrie-stubs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTaskfile.yml
216 lines (189 loc) · 5.49 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
version: '3'
# include .env files using dotenv
dotenv: ['.env', '.env.local']
# When doing interpolation of variables, Task will look for the below.
# They are listed below in order of importance (i.e. most important first):
#
# * Variables declared in the task definition
# * Variables given while calling a task from another (See Calling another task above)
# * Variables of the included Taskfile (when the task is included)
# * Variables of the inclusion of the Taskfile (when the task is included)
# * Global variables (those declared in the vars: option in the Taskfile)
# * Environment variables
vars:
NAME: valkyrie-stubs
BUILD_DIR: build
VERSION:
sh: bash .github/tools/version.sh
BUILD_CMD: CGO_ENABLED=0 go build -ldflags="-w -s -X main.appVersion={{.VERSION}}"
# workaround to use built-in windows commands
SHELL: '{{if eq .OS "Windows_NT"}}powershell{{end}}'
# https://taskfile.dev/usage/#watch-tasks
interval: '500ms'
tasks:
default:
desc: default task
cmds: # run the task sequentially
- task: tidy
- task: gen
- task: lint
- task: test
tidy:
desc: tidy module
sources:
- ./go.mod
generates:
- ./go.sum
cmds:
- go mod tidy
generate:
desc: generate code
aliases:
- gen
sources:
- ./**/generate.go
generates:
- ./**/*.gen.go
cmds:
- go generate ./...
lint:
desc: run linters configured by .golangci.yml
aliases:
- lint-go
sources:
- ./**/*.go
- go.mod
cmds:
- golangci-lint run
preconditions:
- sh: "command -v golangci-lint"
msg: "Please install golangci-lint first: https://golangci-lint.run/usage/install/"
lint:yaml:
desc: lint yaml files
cmds:
- docker run --rm -it -v $(pwd):/data cytopia/yamllint -f parsable $(git ls-files '*.yml' '*.yaml')
lint:docker:
desc: lint Dockerfile
cmds:
- docker run --rm -i hadolint/hadolint hadolint - < ./Dockerfile
test:
desc: run all tests
sources:
- ./**/*.go
- go.mod
cmds:
- go install gotest.tools/gotestsum@latest
- gotestsum
coverage:
desc: run all tests with code coverage
cmds:
- go test -cover -covermode=count -coverprofile=profile.cov ./...
- go tool cover -func profile.cov
- defer: '{{.SHELL}} rm profile.cov'
run:
desc: run the application locally
aliases:
- run-local
cmds:
- go run main.go
pre-build:
internal: true
run: once
cmds:
- mkdir -p {{.BUILD_DIR}}
build:
desc: build binary
aliases: [build-local]
deps:
- pre-build
sources:
- ./**/*.go
- go.mod
generates:
- "{{.BUILD_DIR}}/{{.NAME}}"
cmds:
- "{{.BUILD_CMD}} -o {{.BUILD_DIR}}/{{.NAME}}"
build:linux:
desc: build linux binary
deps:
- pre-build
cmds:
- mkdir -p {{.BUILD_DIR}}/linux-amd64
- GOOS=linux GOARCH=amd64 {{.BUILD_CMD}} -o {{.BUILD_DIR}}/linux-amd64/{{.NAME}}
build:windows:
desc: build windows binary
deps:
- pre-build
cmds:
- mkdir -p {{.BUILD_DIR}}/windows-amd64
- GOOS=windows GOARCH=amd64 {{.BUILD_CMD}} -o {{.BUILD_DIR}}/windows-amd64/{{.NAME}}.exe
build:osx:
desc: build OSX binary
deps:
- pre-build
cmds:
- mkdir -p {{.BUILD_DIR}}/darwin-amd64
- GOOS=darwin GOARCH=amd64 {{.BUILD_CMD}} -o {{.BUILD_DIR}}/darwin-amd64/{{.NAME}}
- mkdir -p {{.BUILD_DIR}}/darwin-arm64
- GOOS=darwin GOARCH=arm64 {{.BUILD_CMD}} -o {{.BUILD_DIR}}/darwin-arm64/{{.NAME}}
build:all:
desc: build for all supported platforms
deps:
- build:linux
- build:windows
- build:osx
clean:
desc: clean project
vars:
FORCE: '{{if eq .OS "Windows_NT"}}-fo{{else}}-f{{end}}'
cmds:
- '{{.SHELL}} rm -r {{.FORCE}} {{.BUILD_DIR}}'
- go clean
docker:build:
desc: build a docker image
vars:
DOCKER_REPO: '{{ default "localhost:5000" .DOCKER_REPO }}'
TAG: '{{ default "latest" .VERSION }}'
cmds:
- docker build --tag "{{.DOCKER_REPO}}/{{.NAME}}:{{.TAG}}" --build-arg GH_TOKEN={{.GH_TOKEN}} --build-arg VERSION={{.VERSION}} .
docker:push:
desc: push docker image
deps:
- docker-build
vars:
DOCKER_REPO: '{{ default "localhost:5000" .DOCKER_REPO }}'
TAG: '{{ default "latest" .VERSION }}'
cmds:
- docker push "{{.DOCKER_REPO}}/{{.NAME}}:{{.TAG}}"
doc:
desc: documentation
cmds:
- go install golang.org/x/tools/cmd/godoc@latest
- echo 'documentation served from http://localhost:8080/'
- godoc -http=localhost:8080
outdated:
desc: list directly dependent modules that can be upgraded
cmds:
- go list -u -m $(go list -m -f '{{`{{.Indirect}} {{.}}`}}' all | grep '^false' | cut -d ' ' -f2) | grep '\['
graph:
desc: graph of upstream modules with gmchart
cmds:
- go install github.com/PaulXu-cn/go-mod-graph-chart/gmchart@latest
- go mod graph | gmchart
licenses:
desc: list project dependency licenses
cmds:
- go install github.com/google/go-licenses@latest
- go-licenses report .
binmap:
desc: treemap breakdown of binary
deps:
- build
cmds:
- go install github.com/nikolaydubina/go-binsize-treemap@latest
- go tool nm -size ./build/{{.NAME}} | go-binsize-treemap > ./build/binsize.svg
- open ./build/binsize.svg
bench:
desc: run benchmarks
cmds:
- go test -bench=. -benchmem ./...