-
Notifications
You must be signed in to change notification settings - Fork 12
/
Taskfile.yml
266 lines (234 loc) · 8.3 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
version: "3"
tasks:
default:
cmds:
- task -l
work:
cmds:
- cmd: go work init . ./core ./test
ignore_error: true
generates:
- go.work
tools:
aliases: [install:deps]
desc: Install tools required to build this app
cmds:
- go install "golang.org/x/tools/cmd/[email protected]"
fmt:
desc: Format the code
cmds:
# goimports does not allow to ignore certain paths with modules,
# so we have to list all the folders that are adjacent generated code.
- |
goimports -format-only -w ./app ./cmd ./common ./core ./node ./testing \
./extensions
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)
go mod tidy
# (cd test; go mod tidy)
# (cd core/client/example; go mod tidy)
# (cd core/gatewayclient/example; go mod tidy)
lint:
desc: Lint with golangci-lint
cmds:
# skip-dirs only works in .yaml
- golangci-lint run ./... -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 kwil-cli and kwild
cmds:
- task: build:cli
- task: build:kwild
build:cli:
desc: Build kwil-cli
cmds:
- ./contrib/scripts/build/binary kwil-cli #-mod=mod
generates:
- .build/kwil-cli
build:kwild:
desc: Builds kwild server
cmds:
- ./contrib/scripts/build/binary kwild #-mod=mod
generates:
- .build/kwild
generate:docs:
desc: Generate docs for CLIs
cmds:
- go run ./cmd/kwild/generate -out ./gen
- go run ./cmd/kwil-cli/generate -out ./gen
kuneiform:grammar:
desc: Generate kuneiform grammar go code.
cmds:
- rm -rf node/engine/parse/gen/*
- cd node/engine/parse/grammar/ && ./generate.sh
sources:
- node/engine/parse/grammar/*.g4
generates:
- node/engine/parse/gen/*.{go,interp,tokens}
# ************ docker ************
vendor:
desc: Generate vendor
deps:
- task: vendor:clean
- task: work
cmds:
- go work 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}}" ./contrib/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}}" ./contrib/scripts/publish/dockerhub
requires:
vars: [TAG]
pg:
desc: Start the postgres docker image
vars:
PORT: '{{ .PORT | default 5432 }}'
NAME: '{{ .NAME | default "kwil-pg-demo" }}'
cmds:
- defer: { task: pg:clean }
- |
docker run -p :5432 -v {{ .NAME }}:/var/lib/postgresql/data \
--shm-size 512m -e "POSTGRES_HOST_AUTH_METHOD=trust" \
--name {{ .NAME }} kwildb/postgres:16.5-1
pg:clean:
desc: Wipe data from the pg task
vars:
NAME: '{{ .NAME | default "kwil-pg-demo" }}'
cmds:
- |
docker container rm -f {{ .NAME }}
docker volume rm -f {{ .NAME }}
# ************ 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 {{.CLI_ARGS}}
# ************ 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: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 ./... -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 ./... -tags=ext_test,pglive -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}}
# test:it:spam:
# desc: Run integration test with oracle spammer nodes
# dir: test # different module
# cmds:
# - (cd nodes/spamd; ./build.sh)
# - go test -count=1 -timeout 0 -run TestSpamListener ./integration -v -spam {{.CLI_ARGS}}
# test:it:fork:
# desc: Run integration test with a hardfork configured
# dir: test # different module
# cmds:
# - (cd nodes/fork; ./build.sh)
# - go test -count=1 -timeout 0 -run TestKwildNetworkHardfork ./integration -v -fork {{.CLI_ARGS}}