-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTaskfile.yml
270 lines (248 loc) · 6.6 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
269
270
# Reference: https://taskfile.dev/api/
version: "3"
vars:
# Dependencies.
PROTOC_GEN_GO_VERSION: v1.34.2
PROTOC_GEN_GO_GRPC_VERSION: v1.4.0
PROTOC_GEN_GRPC_GATEWAY_VERSION: v2.20.0
MIGRATE_VERSION: v4.17.0
# Project vars.
IMAGE_NAME: auditumio/auditum
env:
GOBIN: "{{ .ROOT_DIR }}/bin"
# Local development environment
POSTGRES_HOST: localhost
POSTGRES_PORT: 5432
POSTGRES_DATABASE: auditum_db
POSTGRES_USERNAME: auditum_user
POSTGRES_PASSWORD: auditum_pass
POSTGRES_SSL_MODE: disable
tasks:
############
# Wrappers #
############
default:
desc: "Install deps, check and build"
cmds:
- task: deps
- task: lint-proto
- task: generate-proto
- task: lint-go
- task: test-go
- task: build
check:
desc: "Run all check tasks"
cmds:
- task: default
- task: test-integration-docker
proto:
desc: "Lint and generate proto sources"
cmds:
- task: lint-proto
- task: generate-proto
go:
desc: "Lint and test Go sources"
cmds:
- task: lint-go
- task: test-go
#########
# Tasks #
#########
deps:
desc: "Install and tidy up dependencies"
run: once
cmds:
- go mod tidy
lint-proto:
desc: "Lint proto files"
deps:
- tools
cmds:
- PATH="${GOBIN}:${PATH}" buf lint --error-format=msvs
generate-proto:
aliases:
- gen-proto
desc: "Generate code from proto files"
deps:
- tools
cmds:
- PATH="${GOBIN}:${PATH}" buf generate
--template buf.gen.yaml
- PATH="${GOBIN}:${PATH}" buf generate
--template api/proto/auditumio/auditum/v1alpha1/openapi.buf.gen.yaml
--path api/proto/auditumio/auditum/v1alpha1
--path api/proto/google/api
--path api/proto/protoc-gen-openapiv2/options
lint-go:
desc: "Lint Go sources"
deps:
- deps
- tools
cmds:
- golangci-lint run {{ .CLI_ARGS }}
test-go:
desc: "Run unit tests for Go sources"
deps:
- deps
cmds:
- go test -race {{ .CLI_ARGS }} ./...
build:
desc: "Build binaries"
deps:
- deps
cmds:
- go build -o ${GOBIN}/auditum ./cmd/auditum
test-integration:
desc: "Run integration tests"
summary: |
Run integration tests.
Examples:
# Runs all integration tests
task test-integration
# Runs specific tests
task test-integration -- TestIntegration_Some
deps:
- deps
cmds:
- go test
-tags "integration postgres"
-v
-p 1
-count 1
./internal/sql/...
-run {{ default "TestIntegration" .CLI_ARGS }}
- go test
-tags "integration sqlite"
-v
-p 1
-count 1
./internal/sql/...
-run {{ default "TestIntegration" .CLI_ARGS }}
test-integration-docker:
desc: "Run integration tests with docker"
summary: |
Run integration tests with docker.
Examples:
# Runs all integration tests
task test-integration-docker
# Runs specific tests
task test-integration-docker -- TestIntegration_Some
deps:
- deps
cmds:
- ./test/docker-compose.sh {{ .CLI_ARGS }}
migration:
desc: "Create migration files"
summary: |
Create migration files for the given name.
Examples:
task migration -- create_table_foo
deps:
- tools
cmds:
- PATH="${GOBIN}:${PATH}" migrate
create
-ext sql
-dir ./internal/sql/postgres/migrations
{{ .CLI_ARGS }}
- PATH="${GOBIN}:${PATH}" migrate
create
-ext sql
-dir ./internal/sql/sqlite/migrations
{{ .CLI_ARGS }}
tools:
internal: true
run: once
cmds:
- go install -v google.golang.org/protobuf/cmd/protoc-gen-go@{{ .PROTOC_GEN_GO_VERSION }}
- go install -v google.golang.org/grpc/cmd/protoc-gen-go-grpc@{{ .PROTOC_GEN_GO_GRPC_VERSION }}
- go install -v github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@{{ .PROTOC_GEN_GRPC_GATEWAY_VERSION }}
- go install -v github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@{{ .PROTOC_GEN_GRPC_GATEWAY_VERSION }}
- go install -v -tags 'postgres sqlite' github.com/golang-migrate/migrate/v4/cmd/migrate@{{ .MIGRATE_VERSION }}
docker-build:
desc: "Build docker image"
cmds:
- go mod vendor
- defer: rm -rf ./vendor/
- docker build
--tag {{ .IMAGE_NAME }}:{{ default "latest" .IMAGE_TAG }}
--file Dockerfile
.
docker-run:
desc: "Run docker image"
cmds:
- docker run
--rm
--interactive
--tty
--publish 8080:8080
--publish 9090:9090
{{ .IMAGE_NAME }}:{{ default "latest" .IMAGE_TAG }}
local-up:
desc: "Start local development environment"
cmds:
- docker-compose
--file hack/local/docker-compose.yml
--project-directory .
up
--build
--detach
--wait
local-down:
desc: "Stop local development environment"
cmds:
- docker-compose
--file hack/local/docker-compose.yml
--project-directory .
down
local-cleanup:
desc: "Delete local development environment"
cmds:
- docker-compose
--file hack/local/docker-compose.yml
--project-directory .
down
--volumes
local-migrate-up:
desc: "Run migrations on local development environment"
cmds:
- PATH="${GOBIN}:${PATH}" migrate
-path ./internal/sql/postgres/migrations/
-database postgres://${POSTGRES_USERNAME}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DATABASE}?sslmode=${POSTGRES_SSL_MODE}
up
local-migrate-down:
desc: "Delete database data on local development environment"
cmds:
- PATH="${GOBIN}:${PATH}" migrate
-path ./internal/sql/postgres/migrations/
-database postgres://${POSTGRES_USERNAME}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DATABASE}?sslmode=${POSTGRES_SSL_MODE}
down -all
local-migrate-reset:
desc: "Reset database migrations on local development environment"
cmds:
- task: local-migrate-down
- task: local-migrate-up
website-start:
dir: website
deps:
- website-prepare
cmds:
- npm run start
website-build:
dir: website
cmds:
- npm run build
website-serve:
dir: website
cmds:
- npm run serve
website-deploy:
dir: website
cmds:
- npm run deploy
website-prepare:
internal: true
run: once
dir: website
cmds:
- npm install