-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTaskfile.yml
More file actions
280 lines (249 loc) · 9.19 KB
/
Taskfile.yml
File metadata and controls
280 lines (249 loc) · 9.19 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
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
271
272
273
274
275
276
277
278
279
280
version: "3"
vars:
BINARY_NAME: deps
BUILD_DIR: ./.bin
MAIN_PATH: ./cmd/deps/main.go
GINKGO: go run github.com/onsi/ginkgo/v2/ginkgo
tasks:
default:
desc: List all available tasks
cmds:
- task --list
install-ginkgo:
desc: Install Ginkgo test framework
status:
- which ginkgo
cmds:
- go install github.com/onsi/ginkgo/v2/ginkgo
build:
desc: Build the deps binary
vars:
VERSION:
sh: git describe --tags --always 2>/dev/null || echo "dev"
COMMIT:
sh: git rev-parse --short HEAD 2>/dev/null || echo "unknown"
DATE:
sh: date -u '+%Y-%m-%dT%H:%M:%SZ'
DIRTY:
sh: if [ -n "$(git status --porcelain 2>/dev/null)" ]; then echo "true"; else echo "false"; fi
LDFLAGS: -s -w -X main.version={{.VERSION}} -X main.commit={{.COMMIT}} -X main.date={{.DATE}} -X main.dirty={{.DIRTY}}
cmds:
- mkdir -p {{.BUILD_DIR}}
- go build -ldflags "{{.LDFLAGS}}" -o {{.BUILD_DIR}}/{{.BINARY_NAME}} {{.MAIN_PATH}}
sources:
- "**/*.go"
- pkg/**/*.yaml
- pkg/config/defaults.yaml
- go.mod
- go.sum
generates:
- "{{.BUILD_DIR}}/{{.BINARY_NAME}}"
build-all:
desc: Build for all supported platforms
vars:
VERSION:
sh: git describe --tags --always 2>/dev/null || echo "dev"
COMMIT:
sh: git rev-parse --short HEAD 2>/dev/null || echo "unknown"
DATE:
sh: date -u '+%Y-%m-%dT%H:%M:%SZ'
DIRTY:
sh: if [ -n "$(git status --porcelain 2>/dev/null)" ]; then echo "true"; else echo "false"; fi
LDFLAGS: -s -w -X main.version={{.VERSION}} -X main.commit={{.COMMIT}} -X main.date={{.DATE}} -X main.dirty={{.DIRTY}}
cmds:
- mkdir -p {{.BUILD_DIR}}
- GOOS=linux GOARCH=amd64 go build -ldflags "{{.LDFLAGS}}" -o {{.BUILD_DIR}}/{{.BINARY_NAME}}-linux-amd64 {{.MAIN_PATH}}
- GOOS=linux GOARCH=arm64 go build -ldflags "{{.LDFLAGS}}" -o {{.BUILD_DIR}}/{{.BINARY_NAME}}-linux-arm64 {{.MAIN_PATH}}
- GOOS=darwin GOARCH=amd64 go build -ldflags "{{.LDFLAGS}}" -o {{.BUILD_DIR}}/{{.BINARY_NAME}}-darwin-amd64 {{.MAIN_PATH}}
- GOOS=darwin GOARCH=arm64 go build -ldflags "{{.LDFLAGS}}" -o {{.BUILD_DIR}}/{{.BINARY_NAME}}-darwin-arm64 {{.MAIN_PATH}}
- GOOS=windows GOARCH=amd64 go build -ldflags "{{.LDFLAGS}}" -o {{.BUILD_DIR}}/{{.BINARY_NAME}}-windows-amd64.exe {{.MAIN_PATH}}
dup:
desc: Run jscpd against production Go source
cmds:
- jscpd --config .jscpd.json
sources:
- "cmd/**/*.go"
- "pkg/**/*.go"
- ".jscpd.json"
test:
desc: Run all tests using Ginkgo
deps:
- install-ginkgo
cmds:
- "{{.GINKGO}} -v ./..."
sources:
- "**/*.go"
test:unit:
desc: Run all unit tests using Ginkgo
cmds:
- "{{.GINKGO}} -v --skip-package e2e ./..."
sources:
- "**/*.go"
test:e2e:
desc: Run all e2e tests using Ginkgo
deps:
- install-ginkgo
cmds:
- go run github.com/onsi/ginkgo/v2/ginkgo -v -p -nodes=4 --skip-package ./e2e
sources:
- "**/*.go"
test:report:
desc: Run all tests with Ginkgo JSON and JUnit report generation
deps:
- install-ginkgo
cmds:
- mkdir -p test-results
- ginkgo -v --json-report test-results/test-results.json --junit-report test-results/test-junit.xml ./... || true
- echo "Test results saved to test-results/"
sources:
- "**/*.go"
generates:
- "test-results/test-results.json"
- "test-results/test-junit.xml"
test:e2e-report:
desc: Run e2e tests with Ginkgo JSON and JUnit report generation
cmds:
- mkdir -p test-results
- ginkgo -v --json-report test-results/e2e-results.json --junit-report test-results/e2e-junit.xml -timeout=30m ./e2e || true
- echo "E2E test results saved to test-results/"
sources:
- "e2e/**/*.go"
- "**/*.go"
generates:
- "test-results/e2e-results.json"
- "test-results/e2e-junit.xml"
test:failed:
desc: Rerun only failed tests from last test run
deps: ["test:parse-failed"]
cmds:
- |
if [ ! -f test-results/failed-focus.txt ]; then
echo "No failed tests found. Run 'task test:report' or 'task test:e2e-report' first."
exit 0
fi
if [ ! -s test-results/failed-focus.txt ]; then
echo "No failed tests to rerun. All tests passed in last run!"
exit 0
fi
echo "Rerunning failed tests..."
FOCUS_PATTERN=$(cat test-results/failed-focus.txt)
echo "Focus pattern: $FOCUS_PATTERN"
if grep -q "e2e" test-results/test-type.txt 2>/dev/null; then
echo "Running failed e2e tests..."
ginkgo -v --focus="$FOCUS_PATTERN" -timeout=30m ./e2e
else
echo "Running failed unit tests..."
go test -v -run="$FOCUS_PATTERN" -timeout=10m ./...
fi
test:parse-failed:
desc: Parse failed tests from Ginkgo JSON reports and generate focus patterns
cmds:
- mkdir -p test-results
- |
# Parse failed tests from Ginkgo JSON reports
echo "Parsing failed tests from Ginkgo JSON reports..."
# Check for both e2e and regular test results
FAILED_TESTS=""
FOCUS_PATTERNS=""
# Parse regular test results from Ginkgo JSON report (Ginkgo format)
if [ -f test-results/test-results.json ]; then
# Check if this contains E2E tests by looking for "E2E Suite" description
IS_E2E=$(/usr/local/bin/jq -r '.[] | select(.SuiteDescription == "E2E Suite")' test-results/test-results.json 2>/dev/null)
# Ginkgo JSON format: look for State=failed and extract platform/test info
UNIT_FAILED=$(/usr/local/bin/jq -r '.[] | select(.SpecReports != null) | .SpecReports[] | select(.State == "failed") | if (.ContainerHierarchyTexts | length) > 1 then "\(.ContainerHierarchyTexts[1])/\(.LeafNodeText)" else .LeafNodeText end' test-results/test-results.json 2>/dev/null | sort -u)
if [ ! -z "$UNIT_FAILED" ]; then
FAILED_TESTS="$UNIT_FAILED"
if [ ! -z "$IS_E2E" ]; then
echo "e2e" > test-results/test-type.txt
else
echo "unit" > test-results/test-type.txt
fi
fi
fi
# Parse e2e test results from Ginkgo JSON report (Ginkgo format)
if [ -f test-results/e2e-results.json ]; then
# Ginkgo JSON format: look for State=failed and extract platform/test info
E2E_FAILED=$(/usr/local/bin/jq -r '.[] | select(.SpecReports != null) | .SpecReports[] | select(.State == "failed") | if (.ContainerHierarchyTexts | length) > 1 then "\(.ContainerHierarchyTexts[1])/\(.LeafNodeText)" else .LeafNodeText end' test-results/e2e-results.json 2>/dev/null | sort -u)
if [ ! -z "$E2E_FAILED" ]; then
if [ ! -z "$FAILED_TESTS" ]; then
FAILED_TESTS="$FAILED_TESTS"$'\n'"$E2E_FAILED"
else
FAILED_TESTS="$E2E_FAILED"
fi
echo "e2e" > test-results/test-type.txt
fi
fi
# Clean up failed tests list
FAILED_TESTS=$(echo "$FAILED_TESTS" | grep -v '^$' | sort -u)
# Convert test names to focus patterns
if [ ! -z "$FAILED_TESTS" ]; then
while IFS= read -r test; do
if [ ! -z "$test" ]; then
# For Ginkgo tests with platform/test format, convert to space-separated format
FOCUS_TEST=$(echo "$test" | sed 's/\// /')
if [ -z "$FOCUS_PATTERNS" ]; then
FOCUS_PATTERNS="$FOCUS_TEST"
else
FOCUS_PATTERNS="$FOCUS_PATTERNS|$FOCUS_TEST"
fi
fi
done <<< "$FAILED_TESTS"
fi
# Save results
echo "$FAILED_TESTS" > test-results/failed-tests.txt
echo "$FOCUS_PATTERNS" > test-results/failed-focus.txt
if [ -z "$FOCUS_PATTERNS" ]; then
echo "No failed tests found"
else
echo "Found failed tests:"
echo "$FAILED_TESTS"
echo "Generated focus pattern: $FOCUS_PATTERNS"
fi
sources:
- "test-results/test-results.json"
- "test-results/e2e-results.json"
generates:
- "test-results/failed-tests.txt"
- "test-results/failed-focus.txt"
install-golangci-lint:
desc: Install golangci-lint
status:
- which golangci-lint
cmds:
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.4.0
lint:
desc: Run golangci-lint
cmds:
- golangci-lint run
fmt:
desc: Format Go code
cmds:
- go fmt ./...
vet:
desc: Run go vet
cmds:
- go vet ./...
mod-tidy:
desc: Tidy Go modules
cmds:
- go mod tidy
mod-download:
desc: Download Go module dependencies
cmds:
- go mod download
clean:
desc: Clean build artifacts
cmds:
- rm -rf {{.BUILD_DIR}}
- go clean
install:
desc: Install the binary to /usr/local/bin
deps: [build]
cmds:
- mv "{{.BUILD_DIR}}/{{.BINARY_NAME}}" /usr/local/bin
check:
desc: Run all checks (fmt, vet, lint, test)
deps: [fmt, vet, lint, test]
ci:
desc: Run all CI checks
deps: [mod-download, check, build]