-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.yml
More file actions
212 lines (183 loc) · 5.98 KB
/
Taskfile.yml
File metadata and controls
212 lines (183 loc) · 5.98 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
version: '3'
vars:
GEN_DIR: gen
PROTO_DIR: proto
tasks:
default:
desc: Show available tasks
cmds:
- task --list
silent: true
# Installation
install:
desc: Install npm dependencies and update buf dependencies
cmds:
- task: check
- npm install
- npx buf dep update proto
- echo "✅ All dependencies installed successfully!"
check:
desc: Check if required tools are installed
cmds:
- |
echo "Checking required tools..."
echo ""
MISSING_REQUIRED=0
# Check required tools
command -v node &> /dev/null && echo "✅ Node.js $(node --version)" || { echo "❌ Node.js - Install from: https://nodejs.org/"; MISSING_REQUIRED=1; }
command -v npm &> /dev/null && echo "✅ npm $(npm --version)" || { echo "❌ npm - Install from: https://nodejs.org/"; MISSING_REQUIRED=1; }
# Check optional tools
command -v buf &> /dev/null && echo "✅ buf $(buf --version)" || { npx buf --version &> /dev/null 2>&1 && echo "✅ buf $(npx buf --version) (via npx)" || echo "⚠️ buf - Will use npx (optional: go install github.com/bufbuild/buf/cmd/buf@latest)"; }
command -v go &> /dev/null && echo "✅ Go $(go version | awk '{print $3}')" || echo "⚠️ Go (optional) - Install from: https://go.dev/dl/"
echo ""
[ $MISSING_REQUIRED -eq 0 ] && echo "✅ All required tools are installed!" || { echo "❌ Some required tools are missing. Please install them before continuing."; exit 1; }
# Linting
lint:
desc: Lint proto files with buf
cmds:
- npx buf lint {{.PROTO_DIR}}
sources:
- '{{.PROTO_DIR}}/**/*.proto'
- '{{.PROTO_DIR}}/buf.yaml'
lint:buf:
desc: Lint proto files with buf
cmds:
- npx buf lint {{.PROTO_DIR}}
sources:
- '{{.PROTO_DIR}}/**/*.proto'
- '{{.PROTO_DIR}}/buf.yaml'
lint:ci:
desc: Run all linting checks (CI mode)
cmds:
- task: lint
- task: format:check
# Formatting
format:
desc: Format proto files with buf
cmds:
- npx buf format -w
sources:
- '{{.PROTO_DIR}}/**/*.proto'
format:check:
desc: Check if proto files are formatted (no write)
cmds:
- npx buf format -d --exit-code
sources:
- '{{.PROTO_DIR}}/**/*.proto'
# Breaking changes
breaking:
desc: Check for breaking changes against main branch
cmds:
- npx buf breaking --against '.git#branch=main'
sources:
- '{{.PROTO_DIR}}/**/*.proto'
breaking:verbose:
desc: Check for breaking changes with verbose output
cmds:
- npx buf breaking --against '.git#branch=main' --error-format=json | jq
# Code generation
generate:
desc: Generate code for all languages Python
cmds:
- npx buf generate
sources:
- '{{.PROTO_DIR}}/**/*.proto'
- buf.gen.yaml
generates:
- '{{.GEN_DIR}}/**/*'
generate:check:
desc: Verify generated code is up to date
cmds:
- npx buf generate
- |
if [ -n "$(git status --porcelain {{.GEN_DIR}}/)" ]; then
echo "Error: Generated code is out of date"
echo "Run 'task generate' and commit the changes"
exit 1
fi
# Buf Schema Registry
push:
desc: Push schema to Buf Schema Registry (requires DKIN_CLOUD_TOKEN or BUF_TOKEN)
cmds:
- npx buf push {{.PROTO_DIR}}
preconditions:
- sh: '[ ! -z "$DKIN_CLOUD_TOKEN" ] || [ ! -z "$BUF_TOKEN" ]'
msg: 'DKIN_CLOUD_TOKEN or BUF_TOKEN environment variable must be set'
push:tag:
desc: "Push schema with a tag (usage: task push:tag TAG=v1.0.0)"
cmds:
- npx buf push {{.PROTO_DIR}} --tag {{.TAG}}
preconditions:
- sh: '[ ! -z "{{.TAG}}" ]'
msg: 'TAG variable must be set (e.g., task push:tag TAG=v1.0.0)'
- sh: '[ ! -z "$DKIN_CLOUD_TOKEN" ] || [ ! -z "$BUF_TOKEN" ]'
msg: 'DKIN_CLOUD_TOKEN or BUF_TOKEN environment variable must be set'
# Build workflows
build:
desc: Full build - format, lint, and generate
cmds:
- task: format
- task: lint
- task: generate
- echo "✅ Build completed successfully!"
build:ci:
desc: CI build - format check, lint, breaking, and generate check
cmds:
- task: format:check
- task: lint
- task: breaking
- task: generate:check
# CI simulation
ci:
desc: Run all CI checks locally (format, lint, breaking, generate)
cmds:
- echo "Running CI checks..."
- task: format:check
- task: lint
- task: breaking
- task: generate:check
- echo "✅ All CI checks passed!"
# Cleanup
clean:
desc: Remove generated files (gen/)
cmds:
- rm -rf {{.GEN_DIR}}/
clean:all:
desc: Remove all generated and dependency files
cmds:
- task: clean
- rm -rf node_modules/
# Validation
validate:
desc: Validate proto files are syntactically correct
cmds:
- npx buf build {{.PROTO_DIR}}
# Dependency management
deps:
desc: Show buf dependencies
cmds:
- npx buf dep ls {{.PROTO_DIR}}
deps:update:
desc: Update buf dependencies
cmds:
- npx buf dep update {{.PROTO_DIR}}
# Development helpers
watch:
desc: Watch for changes and auto-generate code
cmds:
- |
echo "Watching for proto file changes..."
while true; do
inotifywait -e modify,create,delete -r {{.PROTO_DIR}}/ && task generate
done
stats:
desc: Show statistics about proto files
cmds:
- |
echo "Proto File Statistics:"
echo "======================"
echo "Total proto files: $(find {{.PROTO_DIR}} -name '*.proto' | wc -l)"
echo "Total services: $(grep -r 'service ' {{.PROTO_DIR}} --include='*.proto' | wc -l)"
echo "Total messages: $(grep -r 'message ' {{.PROTO_DIR}} --include='*.proto' | wc -l)"
echo "Total RPCs: $(grep -r 'rpc ' {{.PROTO_DIR}} --include='*.proto' | wc -l)"
echo "Lines of proto: $(find {{.PROTO_DIR}} -name '*.proto' -exec wc -l {} + | tail -1)"