forked from kwilteam/kwil-db
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTaskfile.yml
268 lines (234 loc) · 8.29 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
version: "3"
includes:
pb: ./Taskfile-pb.yml
tasks:
default:
cmds:
- task -l
install:deps:
aliases: [tools]
desc: Install tools required to build this app
cmds:
- go install "github.com/grpc-ecosystem/grpc-gateway/v2/[email protected]"
- go install "github.com/grpc-ecosystem/grpc-gateway/v2/[email protected]"
- go install "golang.org/x/tools/cmd/[email protected]"
- go install "google.golang.org/grpc/cmd/[email protected]"
- go install "google.golang.org/protobuf/cmd/[email protected]"
git:init:
desc: Initialize git submodules
cmds:
- git submodule update --init
git:sync:
desc: Sync git submodules to required revisions
cmds:
- git submodule update
git:advance:
desc: Advance git submodules to latest main revision
cmds:
- git submodule update --remote
init:
desc: Initialize the project
deps: [install:deps, git:init]
cmds:
- go mod download
fmt:
desc: Format the code
cmds:
# goimports does not allow to ignore certain paths (protobuf) with modules,
# so we have to list all the folders that are adjacent to protobuf.
- |
goimports -format-only -w ./cmd ./internal ./test ./core/client \
./core/crypto ./core/log ./core/rpc/client ./core/rpc/conversion \
./core/rpc/transport ./core/types ./core/utils
tidy:
desc: go mod tidy each module
cmds:
# This is simple, but it require to run go mod tidy in each module's folder,
# and from bottom to top in terms of dependencies.
- |
(cd core; go mod tidy)
(cd parse; go mod tidy)
go mod tidy
(cd test; go mod tidy)
lint:
desc: Lint with golangci-lint
cmds:
# skip-dirs only works in .yaml
- golangci-lint run ./... ./core/... ./test/... ./parse/... -c .golangci.yml
linter:
desc: Install the linter (not for CI which has an action for this)
cmds:
- go install "github.com/golangci/golangci-lint/cmd/[email protected]"
build:
desc: Build cli, admin & kwild
cmds:
- task: build:cli
- task: build:kwild
- task: build:admin
build:cli:
desc: Build kwil-cli
cmds:
- ./scripts/build/binary kwil-cli #-mod=mod
generates:
- .build/kwil-cli
build:admin:
desc: Build kwil-admin
cmds:
- ./scripts/build/binary kwil-admin
generates:
- .build/kwil-admin
build:kwild:
desc: Builds kwild server
cmds:
- ./scripts/build/binary kwild #-mod=mod
generates:
- .build/kwild
generate:docs:
desc: Generate docs for CLIs
cmds:
- go run ./cmd/kwil-cli/generate -out ./gen
- go run ./cmd/kwil-admin/generate -out ./gen
# ************ docker ************
vendor:
desc: Generate vendor
deps:
- task: vendor:clean
cmds:
# somehow GOWORK=off has no effect on local dev workflow, it will include local module changes
- GOWORK=off go mod vendor
vendor:clean:
desc: Clean vendor
cmds:
- rm -rf ./vendor
build:docker:
desc: Build the docker image for the kwild, support extra args to specify image flavor
cmds:
- task: vendor
- defer: { task: vendor:clean }
# pass any args to build flavored image, e.g. task build:docker -- debug
# NOTE: this is kind hack/messy, since `./scripts/build/docker` only care first 2 args
# {{.CLI_ARGS}} is a special variable that will be replaced with the CLI args
# {{.VARIANT}} is a variable other tasks can set, it will have effect if {{.CLI_ARGS}} is empty
# !! if parent task(which has deps on this task) has {{.CLI_ARGS}}, only this child task get the {{.CLI_ARGS}}
- GO_BUILDTAGS="{{.GO_BUILDTAGS}}" ./scripts/build/docker kwild {{.CLI_ARGS}} {{.VARIANT}}
publish:dockerhub:
desc: Publish docker image to dockerhub
cmds:
- task: vendor
- defer: { task: vendor:clean }
# TAG is the docker tag. GO_BUILDTAGS is the build tags for go build
- TAG={{.TAG}} GO_BUILDTAGS="{{.GO_BUILDTAGS}}" ./scripts/publish/dockerhub
requires:
vars: [TAG]
pg:
desc: Start the postgres docker image
cmds:
- |
docker run -p 5432:5432 -v kwil-pg-demo:/var/lib/postgresql/data \
--shm-size 256m -e "POSTGRES_HOST_AUTH_METHOD=trust" \
--name kwil-pg-demo kwildb/postgres:latest
pg:clean:
desc: Wipe data from the pg task
cmds:
- |
docker container rm -f kwil-pg-demo
docker volume rm -f kwil-pg-demo
# ************ dev ************
dev:up:
desc: Start the dev environment
deps:
- task: build:docker
cmds:
- task: dev:up:nb
dev:up:debug:
desc: Start the dev environment
deps:
- task: build:docker
vars: { VARIANT: 'debug' }
cmds:
- task: dev:up:nb
dev:up:nb:
desc: Start the dev environment without rebuilding docker image
env:
# NOTE: this timeout should be long enough to attach to debugger
KACT_WAIT_TIMEOUT: 20s
dir: test # different module
cmds:
- go test ./acceptance -run ^TestLocalDevSetup -timeout 12h -dev -v {{.CLI_ARGS}}
dev:testnet:up:
desc: Start the dev environment(with testnet)
deps:
- task: build:docker
cmds:
- task: dev:testnet:up:nb
dev:testnet:up:nb:
desc: Start the dev environment(with testnet) without rebuilding docker image
dir: test # different module
cmds:
- go test ./integration -run ^TestLocalDevSetup$ -timeout 12h -dev -v
# ************ test ************
# test with build:docker task support passing CLI_ARGS to go test, e.g. task test:act -- -debug
# but this CLI_ARGS will only be used by `build:docker`
test:act:
desc: Run acceptance tests
deps:
- task: build:cli
- task: build:admin
- task: build:docker
cmds:
- task: test:act:nb
# *:nb task support passing CLI_ARGS to go test
# this CLI_ARGS will be used by `go test`
# e.g.
# - task test:act:nb -- -remote
# - task test:act:nb -- -drivers grpc
# - task test:act:nb -- -parallel-mode -parallel 2
test:act:nb:
desc: Run acceptance tests without building docker image
dir: test # different module
cmds:
- go test ./acceptance -count=1 -v {{.CLI_ARGS}}
# NOTE: for now the unit tests require postgres running to support the tests
# with the "pglive" build tag. In CI, a postgres service is started by the
# github actions workflow. In dev machines, you can either use a system
# installation with a "kwild" (super)user and "kwil_test_db" database, or you
# can use the postgresql Docker compose at deployments/compose/postgres/docker-compose.yml
# or the custom Dockerfile at deployments/compose/postgres/Dockerfile.
#
# This should be TEMPORARY. The unit tests should work without postgres, or
# ideally any database engine. The various "stores" like account store can
# use a stubbed out Datastore interface to test the application logic, although
# the SQL queries in those packages should still be tested with a live DB.
# A mock interface should also be good for the engine. However, for the
# internal/sql/pg package, it is very tightly coupled to the pgx package and
# and the workings of an actual postgres host.
test:unit:
desc: Run unit tests
cmds:
- go test ./core/... -tags=ext_test -count=1
- CGO_ENABLED=1 go test ./parse/... -tags=ext_test -count=1
- CGO_ENABLED=1 go test ./... -tags=ext_test,pglive -count=1 -p=1 # no parallel for now because several try to use one pg database
test:unit:race:
desc: Run unit tests with the race detector
cmds:
- go test ./core/... -tags=ext_test -count=1 -race
- CGO_ENABLED=1 go test ./parse/... -tags=ext_test -count=1 -race
- CGO_ENABLED=1 go test ./... -tags=ext_test -count=1 -race
test:it:
desc: Run integration tests ('short' mode)
deps:
- task: build:cli
- task: build:admin
- task: build:docker
cmds:
- task: test:it:nb
test:it:nb:
desc: Run integration tests ('short' mode)
dir: test # different module
cmds:
- go test -short -count=1 -timeout 0 ./integration -v {{.CLI_ARGS}}
test:it:nb:all:
desc: Run integration tests
dir: test # different module
cmds:
- go test -count=1 -timeout 0 ./integration -v {{.CLI_ARGS}}