-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtaskfile.yml
More file actions
188 lines (149 loc) · 5.06 KB
/
Copy pathtaskfile.yml
File metadata and controls
188 lines (149 loc) · 5.06 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
version: '3'
silent: true
env:
CWD: "{{ .USER_WORKING_DIR }}"
DOCKERFILE: ./dockerfile
COMPOSE_FILE: .config/deployment/local/compose.yml
GO_VERSION: 1.24
VERSION: 0.1.0
CGO_ENABLED: 0
# Secrets for local development
POSTGRES_CONN: postgresql://user:password@postgres:5432/goshare?sslmode=disable
JAEGER_CONN: jaeger:4317
# Tools
SQLC: go tool -modfile=.tools/sqlc/go.mod sqlc -f .config/.sqlc.yaml
GOLANGCI: go tool -modfile=.tools/golangci-lint/go.mod golangci-lint run -c .config/.golangci.yaml
GOTESTSUM: go tool -modfile=.tools/gotestsum/go.mod gotestsum
OGEN: go tool -modfile=.tools/ogen/go.mod ogen -config .config/.ogen.yaml
MOCKERY: go tool -modfile=.tools/mockery/go.mod mockery --config .config/.mockery.yaml
JUNIT_REPORT: go tool -modfile=.tools/go-junit-report/go.mod go-junit-report
tasks:
junit-report:
cmd: $JUNIT_REPORT -set-exit-code > report.xml
diff-mockery:
cmd: |
if ! git diff --quiet; then
echo "❌ commit all changes before comparing the diff"
exit 1
fi
task generate-mocks
if ! git diff --quiet; then
echo "❌ mockery generated changes. Run 'task generate-mocks' and commit the results."
exit 1
fi
diff-sqlc:
cmd: $SQLC diff
vet-sql:
cmd: $SQLC vet
lint:
cmd: $GOLANGCI
test:
cmd: $GOTESTSUM --hide-summary=skipped -- -v -timeout=10s ./...
test-coverage:
cmd: $GOTESTSUM --hide-summary=skipped -- -coverprofile=coverage.out -timeout=10s -v ./...
build-server:
cmd: go build -ldflags "-extldflags '-static' -X main.version=$VERSION" -o ./bin/server ./cmd/server
generates:
- bin/server
build-migration:
cmd: go build -gcflags "all=-N -l" -a -ldflags "-extldflags '-static' -X main.version=$VERSION" -o ./bin/migration ./cmd/migration
generates:
- bin/migration
add-tool:
vars:
tool: { sh: 'echo "${tool}"' }
cmds:
- |
if [ -z "{{.tool}}" ]; then
echo "❌ tool variable is required, e.g.: task add-tool tool=github.com/vektra/mockery/v3"
exit 1
fi
TOOLNAME=$(basename $(echo "{{.tool}}" | sed -E 's/\/v[0-9]+$//; s/^v[0-9]+$//'))
DIR=".tools/$TOOLNAME"
echo "📦 Adding tool: $TOOLNAME into $DIR"
mkdir -p "$DIR"
cd "$DIR"
if [ ! -f go.mod ]; then
go mod init github.com/sonalys/goshare/tools/$TOOLNAME
fi
go get -tool {{.tool}}@latest
go mod tidy
download:
cmd: |
go mod download
for tool in .tools/*; do
(cd $tool; go mod download)
done
tidy:
cmd: |
go mod tidy
for tool in .tools/*; do
(cd $tool; go mod tidy)
done
upgrade_tools:
cmd: |
for d in .tools/*; do
if [ -d "$d" ] && [ -f "$d/go.mod" ]; then
TOOL=$(grep "^tool " "$d/go.mod" | awk '{print $2}')
echo "Updating tool: $TOOL"
(cd "$d" && go get -tool "${TOOL}@latest" && go mod tidy)
fi
done
build:
deps: [build-server,build-migration]
start:
env:
POSTGRES_CONN: postgresql://user:password@localhost:5432/goshare?sslmode=disable
JAEGER_CONN: localhost:4317
cmd: go run ./cmd/server/...
dev:
env:
POSTGRES_CONN: postgresql://user:password@localhost:5432/goshare?sslmode=disable
JAEGER_CONN: localhost:4317
cmd: go run ./cmd/server/... | docker compose -f {{ .COMPOSE_FILE }} run --rm -T promtail
migrate:
env:
POSTGRES_CONN: postgresql://user:password@localhost:5432/goshare?sslmode=disable
JAEGER_CONN: localhost:4317
cmd: go run ./cmd/migration/...
generate:
deps:
- generate-sql
- generate-openapi
- generate-mocks
generate-sql:
cmd: $SQLC -f .config/.sqlc.yaml generate
generate-openapi:
env:
OPENAPI_SPEC: internal/infrastructure/http/openapi.yaml
cmd: $OGEN -package server --target internal/infrastructure/http/server --clean $OPENAPI_SPEC
generate-mocks:
cmd: >
rm -rf internal/mocks;
$MOCKERY
compose-server:
cmd: docker compose -f {{ .COMPOSE_FILE }} up -d --build goshare && docker compose -f {{ .COMPOSE_FILE }} logs -f goshare_migrate goshare
compose-down-server:
cmd: docker compose -f {{ .COMPOSE_FILE }} down goshare
compose:
cmd: docker compose -f {{ .COMPOSE_FILE }} up -d --build && docker compose -f {{ .COMPOSE_FILE }} logs -f goshare_migrate goshare
compose-down:
args:
services
cmd: docker compose -f {{ .COMPOSE_FILE }} down -v
compose-db:
cmd: docker compose -f {{ .COMPOSE_FILE }} up -d postgres
compose-down-infra:
cmd: docker compose -f {{ .COMPOSE_FILE }} down -v postgres jaeger promtail loki grafana
compose-infra:
cmd: docker compose -f {{ .COMPOSE_FILE }} up -d postgres jaeger promtail loki grafana
enter-db:
cmd: docker exec -it postgres psql -U user goshare
debug-server:
cmd: dlv debug cmd/server --headless --listen=:2345 --api-version=2 --accept-multiclient
sources:
- ./**/*.go
- go.mod
- go.sum
generates:
- bin/server