-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.yml
More file actions
240 lines (206 loc) · 5.85 KB
/
Taskfile.yml
File metadata and controls
240 lines (206 loc) · 5.85 KB
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
# https://taskfile.dev
version: '3'
vars:
BINARY_NAME: assistant
BUILD_DIR: ./bin
COVERAGE_DIR: ./coverage
DATABASE_URL: '{{.DATABASE_URL | default "postgresql://localhost/assistant?sslmode=disable"}}'
TEST_DATABASE_URL: '{{.TEST_DATABASE_URL | default "postgres://postgres:postgres@localhost:5432/assistant_test?sslmode=disable"}}'
tasks:
# Default
default:
desc: List available tasks
cmds:
- task --list
# ========== Build ==========
build:
desc: Build the binary
cmds:
- go build -o {{.BUILD_DIR}}/{{.BINARY_NAME}} ./cmd/assistant
sources:
- '**/*.go'
- go.mod
- go.sum
generates:
- '{{.BUILD_DIR}}/{{.BINARY_NAME}}'
run:
desc: Build and run
deps: [build]
cmds:
- '{{.BUILD_DIR}}/{{.BINARY_NAME}}'
clean:
desc: Clean build artifacts
cmds:
- rm -rf {{.BUILD_DIR}}
- rm -rf {{.COVERAGE_DIR}}
- go clean || true
# ========== Development ==========
dev:
desc: Quick rebuild (sqlc + build)
cmds:
- task: sqlc
- task: build
generate:
desc: Generate all code (sqlc + mocks)
cmds:
- task: sqlc
- task: mocks
sqlc:
desc: Generate SQL code
cmds:
- sqlc generate -f configs/sqlc.yaml
sources:
- configs/sqlc.yaml
- internal/storage/database/queries/*.sql
mocks:
desc: Generate mocks
cmds:
- go generate ./...
- mockgen -source=internal/storage/database/sqlc/querier.go -destination=internal/storage/database/mocks/mock_querier.go -package=mocks
# ========== Testing ==========
test:
desc: Run all tests
cmds:
- go test -v ./...
test-short:
desc: Run unit tests only
cmds:
- go test -short -v ./...
test-integration:
desc: Run integration tests
cmds:
- TEST_DATABASE_URL={{.TEST_DATABASE_URL}} go test -tags=integration -v ./...
test-race:
desc: Run tests with race detector
cmds:
- go test -race -v ./...
test-pkg:
desc: Test specific package (usage- task test-pkg PKG=./internal/memory)
cmds:
- go test -v {{.PKG}}
preconditions:
- sh: test -n "{{.PKG}}"
msg: "PKG required. Usage- task test-pkg PKG=./internal/memory"
test-func:
desc: Test specific function (usage- task test-func FUNC=TestMemory)
cmds:
- go test -v -run {{.FUNC}} ./...
preconditions:
- sh: test -n "{{.FUNC}}"
msg: "FUNC required. Usage- task test-func FUNC=TestMemory"
coverage:
desc: Generate coverage report
cmds:
- mkdir -p {{.COVERAGE_DIR}}
- go test -coverprofile={{.COVERAGE_DIR}}/coverage.out ./...
- go tool cover -html={{.COVERAGE_DIR}}/coverage.out -o {{.COVERAGE_DIR}}/coverage.html
- echo "Coverage report generated at {{.COVERAGE_DIR}}/coverage.html"
coverage-func:
desc: Show coverage by function
deps: [coverage]
cmds:
- go tool cover -func={{.COVERAGE_DIR}}/coverage.out
benchmark:
desc: Run benchmarks
cmds:
- go test -bench=. -benchmem ./...
# ========== Code Quality ==========
lint:
desc: Run all linters (golangci-lint + vet + staticcheck + gosec)
cmds:
- echo "Running go vet..."
- go vet ./...
- echo "Running golangci-lint..."
- golangci-lint run --timeout=5m
- echo "Running staticcheck..."
- staticcheck ./... || true
- echo "Running gosec..."
- gosec -fmt=text -exclude=G101 -quiet ./... || true
lint-install:
desc: Install all linter tools
cmds:
- go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
- go install honnef.co/go/tools/cmd/staticcheck@latest
- go install github.com/securego/gosec/v2/cmd/gosec@latest
fmt:
desc: Format code
cmds:
- gofmt -w -s .
- goimports -w .
fmt-check:
desc: Check formatting
cmds:
- test -z "$(gofmt -l .)" || (echo "Unformatted files found. Run 'task fmt'" && exit 1)
vet:
desc: Run go vet
cmds:
- go vet ./...
# ========== Dependencies ==========
deps:
desc: Download dependencies
cmds:
- go mod download
- go mod tidy
deps-update:
desc: Update dependencies
cmds:
- go get -u ./...
- go mod tidy
# ========== Database ==========
migrate:
desc: Run database migrations up
cmds:
- migrate -path internal/storage/database/migrations -database "{{.DATABASE_URL}}" up
migrate-down:
desc: Rollback database migrations
cmds:
- migrate -path internal/storage/database/migrations -database "{{.DATABASE_URL}}" down
migrate-create:
desc: Create new migration
cmds:
- migrate create -ext sql -dir internal/storage/database/migrations -seq {{.NAME}}
preconditions:
- sh: test -n "{{.NAME}}"
msg: "NAME required. Usage: task migrate-create NAME=add_users"
# ========== CI/CD ==========
ci:
desc: Run all CI checks
cmds:
- task: fmt-check
- task: lint
- task: test
- task: build
pre-commit:
desc: Pre-commit checks
cmds:
- task: fmt
- task: lint
- task: test-short
check:
desc: Quick quality check
cmds:
- task: fmt-check
- task: vet
- task: test-short
# ========== Installation ==========
install:
desc: Install binary
deps: [build]
cmds:
- cp {{.BUILD_DIR}}/{{.BINARY_NAME}} $(go env GOPATH)/bin/
install-tools:
desc: Install all dev tools
cmds:
- task: lint-install
- go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
- go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
- go install go.uber.org/mock/mockgen@latest
- go install golang.org/x/tools/cmd/goimports@latest
- echo "All tools installed"
# ========== Utility ==========
all:
desc: Build everything
cmds:
- task: deps
- task: generate
- task: build