forked from datarobot-oss/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.yaml
More file actions
370 lines (338 loc) · 13.5 KB
/
Copy pathTaskfile.yaml
File metadata and controls
370 lines (338 loc) · 13.5 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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
version: "3"
vars:
VERSION_PACKAGE: "github.com/datarobot/cli/internal/version"
VERSION: { sh: 'git describe --dirty --tags --long --always --abbrev=15' }
COMMIT: { sh: "git describe --dirty --long --always --abbrev=15" }
BUILD_DATE: '{{now.UTC.Format "2006-01-02T15:04:05Z"}}'
LDFLAGS_COMMON: |
-X {{.VERSION_PACKAGE}}.GitCommit={{.COMMIT}} \
-X {{.VERSION_PACKAGE}}.Version={{.VERSION}} \
-X {{.VERSION_PACKAGE}}.BuildDate={{.BUILD_DATE}}
BIN_DIR: "$PWD/tmp/bin"
GOLANGCI_LINT_VERSION: "v2.11.4"
LEFTHOOK_VERSION: "v2.1.10"
JSCPD_VERSION: "5.0.12"
GORELEASER_VERSION: "v2.17.1"
# Keep this in sync with the GOOS lists in goreleaser.yaml.
LINT_GOOS_TARGETS: "linux darwin windows"
dotenv: [".env"]
tasks:
help:
desc: "🛠️ Dev Commands"
cmds:
- echo "🛠️ Dev Commands"
- task --list
default:
cmds:
- task help
install-tools:
silent: true
desc: "Install static checkers & other binaries"
cmds:
- |
echo "🚚 Downloading tools…"
export GOBIN={{.BIN_DIR}}
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b {{.BIN_DIR}} {{.GOLANGCI_LINT_VERSION}}
# goreleaser: download the prebuilt binary instead of `go install`, which
# compiles a large dependency tree from source and slows container/CI setup.
GORELEASER_OS=$(go env GOOS)
GORELEASER_ARCH=$(go env GOARCH)
case "$GORELEASER_OS-$GORELEASER_ARCH" in
darwin-arm64) GORELEASER_ASSET="goreleaser_Darwin_arm64.tar.gz" ;;
darwin-amd64) GORELEASER_ASSET="goreleaser_Darwin_x86_64.tar.gz" ;;
linux-arm64) GORELEASER_ASSET="goreleaser_Linux_arm64.tar.gz" ;;
linux-amd64) GORELEASER_ASSET="goreleaser_Linux_x86_64.tar.gz" ;;
windows-amd64) GORELEASER_ASSET="goreleaser_Windows_x86_64.zip" ;;
*) echo "Unsupported platform for goreleaser: $GORELEASER_ASSET on $GORELEASER_OS-$GORELEASER_ARCH"; exit 1 ;;
esac
GORELEASER_TMP=$(mktemp -d)
curl -sSfL "https://github.com/goreleaser/goreleaser/releases/download/{{.GORELEASER_VERSION}}/${GORELEASER_ASSET}" -o "$GORELEASER_TMP/archive"
if [ "$GORELEASER_OS" = "windows" ]; then
unzip -o "$GORELEASER_TMP/archive" -d "$GORELEASER_TMP"
mv "$GORELEASER_TMP/goreleaser.exe" {{.BIN_DIR}}/
else
tar -xzf "$GORELEASER_TMP/archive" -C "$GORELEASER_TMP"
mv "$GORELEASER_TMP/goreleaser" {{.BIN_DIR}}/
fi
rm -rf "$GORELEASER_TMP"
# jscpd: download prebuilt Rust binary from GitHub releases
JSCPD_OS=$(go env GOOS)
JSCPD_ARCH=$(go env GOARCH)
case "$JSCPD_OS-$JSCPD_ARCH" in
darwin-arm64) JSCPD_ASSET="jscpd-darwin-arm64" ;;
darwin-amd64) JSCPD_ASSET="jscpd-darwin-x64" ;;
linux-arm64) JSCPD_ASSET="jscpd-linux-arm64-gnu" ;;
linux-amd64) JSCPD_ASSET="jscpd-linux-x64-gnu" ;;
windows-amd64) JSCPD_ASSET="jscpd-windows-x64-msvc" ;;
*) echo "Unsupported platform for jscpd: $JSCPD_OS-$JSCPD_ARCH"; exit 1 ;;
esac
curl -sSfL "https://github.com/kucherenko/jscpd/releases/download/v{{.JSCPD_VERSION}}/${JSCPD_ASSET}.tar.gz" | tar -xz -C {{.BIN_DIR}}
# lefthook: download the prebuilt binary instead of `go install` for the
# same reason as goreleaser (avoids compiling its dependency tree from source).
LEFTHOOK_OS=$(go env GOOS)
LEFTHOOK_ARCH=$(go env GOARCH)
LEFTHOOK_VER={{.LEFTHOOK_VERSION}}
LEFTHOOK_VER=${LEFTHOOK_VER#v}
case "$LEFTHOOK_OS-$LEFTHOOK_ARCH" in
darwin-arm64) LEFTHOOK_ASSET="lefthook_${LEFTHOOK_VER}_MacOS_arm64.gz" ;;
darwin-amd64) LEFTHOOK_ASSET="lefthook_${LEFTHOOK_VER}_MacOS_x86_64.gz" ;;
linux-arm64) LEFTHOOK_ASSET="lefthook_${LEFTHOOK_VER}_Linux_arm64.gz" ;;
linux-amd64) LEFTHOOK_ASSET="lefthook_${LEFTHOOK_VER}_Linux_x86_64.gz" ;;
windows-amd64) LEFTHOOK_ASSET="lefthook_${LEFTHOOK_VER}_Windows_x86_64.exe" ;;
*) echo "Unsupported platform for lefthook: $LEFTHOOK_OS-$LEFTHOOK_ARCH"; exit 1 ;;
esac
if [ "$LEFTHOOK_OS" = "windows" ]; then
curl -sSfL "https://github.com/evilmartians/lefthook/releases/download/{{.LEFTHOOK_VERSION}}/${LEFTHOOK_ASSET}" -o {{.BIN_DIR}}/lefthook.exe
else
curl -sSfL "https://github.com/evilmartians/lefthook/releases/download/{{.LEFTHOOK_VERSION}}/${LEFTHOOK_ASSET}" | gunzip > {{.BIN_DIR}}/lefthook
chmod +x {{.BIN_DIR}}/lefthook
fi
status:
- "{{.BIN_DIR}}/golangci-lint --version"
- "{{.BIN_DIR}}/goreleaser --version"
- "{{.BIN_DIR}}/jscpd --version"
- "{{.BIN_DIR}}/lefthook version"
uninstall-tools:
silent: true
desc: "Uninstall static checkers & other binaries"
cmds:
- "rm {{.BIN_DIR}}/golangci-lint"
- "rm {{.BIN_DIR}}/goreleaser"
- "rm {{.BIN_DIR}}/jscpd"
- "rm {{.BIN_DIR}}/lefthook"
dev-init:
silent: true
desc: "Initialize development environment"
deps: [delint]
cmds:
- |
export GOBIN={{.BIN_DIR}}
echo "🔧 Initializing development environment…"
mkdir -p {{.BIN_DIR}}
echo "🛠️ Installing tools…"
go get github.com/stretchr/testify@latest
echo "🪝 Installing git hooks…"
{{.BIN_DIR}}/lefthook install
echo "✅ Development environment initialized."
bootstrap:
silent: true
desc: "Set up complete dev environment (verify Go, tools, hooks, build)"
cmds:
- |
GO_REQUIRED=$(grep '^go ' go.mod | awk '{print $2}')
GO_INSTALLED=$(go version | awk '{print $3}' | sed 's/go//')
if [ "$GO_REQUIRED" != "$GO_INSTALLED" ]; then
echo "Go version mismatch: go.mod requires $GO_REQUIRED, installed is $GO_INSTALLED"
echo "Install Go $GO_REQUIRED from https://go.dev/dl/"
exit 1
fi
echo "Go $GO_INSTALLED matches go.mod"
- task: install-tools
- "{{.BIN_DIR}}/lefthook install"
- task: build
lint:
silent: true
desc: "Check for lint issues (does not modify files)"
deps: [install-tools]
cmds:
- echo "🧹 Checking go.mod…"
- go mod tidy -diff
- echo "🧹 Checking formatting…"
- "{{.BIN_DIR}}/golangci-lint fmt --diff"
- echo "🧹 Vetting…"
- go vet ./...
- task: lint-goos
- echo "🧹 Checking GoReleaser config…"
- "{{.BIN_DIR}}/goreleaser check"
delint:
silent: true
desc: "Fix lint and formatting issues"
deps: [install-tools]
cmds:
- echo "🧹 Cleaning go.mod…"
- go mod tidy
- echo "🧹 Formatting files…"
- "{{.BIN_DIR}}/golangci-lint fmt"
- task: lint-goos
vars:
LINT_ARGS: "--fix"
# CFX-7138: run golangci-lint once per target GOOS so build-constrained files
# (*_windows.go, //go:build linux, …) are enforced no matter which OS the
# linter runs on. Without this, a macOS dev only lints the darwin/!windows
# files and CI (ubuntu) only the linux/!windows ones, so windows-only files
# are linted by nobody. Callers pass LINT_ARGS to select the mode.
lint-goos:
internal: true
silent: true
deps: [install-tools]
cmds:
- for: { var: LINT_GOOS_TARGETS, split: " " }
cmd: |
echo "🧹 Linting (GOOS={{.ITEM}})…"
GOOS={{.ITEM}} {{.BIN_DIR}}/golangci-lint run {{.LINT_ARGS}} ./...
run:
silent: true
desc: "Run CLI"
cmds:
- |
if [ -z "{{.CLI_ARGS}}" ]; then
go run -ldflags "{{.LDFLAGS_COMMON}}" main.go
else
go run -ldflags "{{.LDFLAGS_COMMON}}" main.go -- {{.CLI_ARGS}}
fi
build:
silent: true
desc: "Build CLI"
cmds:
- 'echo "🔨 Building binary…"'
- 'echo "• Version: {{.VERSION}}"'
- 'echo "• Commit: {{.COMMIT}}"'
- 'echo "• Build Date: {{.BUILD_DATE}}"'
- 'go build -ldflags "{{.LDFLAGS_COMMON}}" -o ./dist/dr'
- 'echo "✨ Binary built at ./dist/dr"'
gen:
silent: true
desc: "Generate Go code"
cmds:
- go generate ./...
gen-check:
silent: true
desc: "Check if Go code needs to be generated"
deps: [gen]
cmds:
- git diff --exit-code
test:
silent: true
desc: "Run tests"
cmds:
- go test -count=1 -race -shuffle=on -coverprofile=coverage.txt ./...
test-no-coverage:
silent: true
desc: "Run tests without coverage"
cmds:
- go test -count=1 -race -shuffle=on ./...
test-windows:
silent: true
desc: "Run tests without race detector or coverage (Windows CI leg, CFX-6919)"
cmds:
- go test -count=1 -shuffle=on ./...
test-coverage:
silent: true
desc: "Run tests with coverage rendered in HTML"
cmds:
- task test
- go tool cover -html=coverage.txt -o coverage.html
- |
{{if eq OS "darwin"}}
open ./coverage.html
{{else if eq OS "linux"}}
xdg-open ./coverage.html
{{else}}
echo "Running on OS other than Mac/Linux - assuming Windows."
start ./coverage.html
{{end}}
precommit:
silent: true
desc: "Run pre-commit checks (format, tidy, vet, lint)"
deps: [install-tools]
cmds:
- echo "🧹 Formatting…"
- "{{.BIN_DIR}}/golangci-lint fmt"
- echo "🧹 Checking Go files are formatted…"
- git diff --exit-code -- '*.go'
- echo "🧹 Tidying go.mod…"
- go mod tidy
- echo "🧹 Vetting…"
- go vet ./...
# CFX-7138: deliberately host-GOOS only. The commit hook runs on every
# commit, and looping all targets here costs ~4-6s of interactive latency
# for little benefit — `task lint` and CI already enforce every GOOS.
- echo "🧹 Linting new changes…"
- "{{.BIN_DIR}}/golangci-lint run --new-from-rev HEAD ./..."
- echo "🧹 Verifying golangci-lint config…"
- "{{.BIN_DIR}}/golangci-lint config verify"
- echo "🧹 Checking go.mod/go.sum are tidy…"
- git diff --exit-code go.mod go.sum
dupcheck:
silent: true
desc: "Check for duplicate code (jscpd)"
deps: [install-tools]
cmds:
- "{{.BIN_DIR}}/jscpd --no-tips --config .jscpd.json ."
smoke-test:
desc: "Run smoke tests"
cmds:
- ./smoke_test_scripts/run_smoke_test.sh {{if .DR_API_TOKEN}}{{.DR_API_TOKEN}}{{else}}$DR_API_TOKEN{{end}}
smoke-test-pre-release:
desc: "Run pre-release smoke tests (heavier end-to-end; gates release promotion)"
cmds:
- ./smoke_test_scripts/run_pre_release_smoke_test.sh {{if .DR_API_TOKEN}}{{.DR_API_TOKEN}}{{else}}$DR_API_TOKEN{{end}}
smoke-test-self-update:
desc: "Run self-update smoke tests"
cmds:
- ./smoke_test_scripts/run_self_update_smoke_test.sh
smoke-test-plugin-update:
desc: "Run plugin auto-update-check smoke tests (requires internet, no API token needed)"
deps: [build]
cmds:
- ./smoke_test_scripts/run_plugin_update_smoke_test.sh
smoke-test-workload:
desc: "Run workload/artifact acceptance scenarios (live; uses configured drconfig.yaml auth)"
deps: [build]
cmds:
- ./smoke_test_scripts/run_workload_smoke_test.sh {{.CLI_ARGS}}
smoke-test-workload-full:
desc: "Run the full workload/artifact acceptance suite incl. the ~20-30 min built-workload scenario (live; uses configured drconfig.yaml auth)"
deps: [build]
cmds:
- WORKLOAD_SMOKE_INCLUDE_D=1 ./smoke_test_scripts/run_workload_smoke_test.sh
smoke-test-windows:
desc: "Run smoke tests (Windows)"
cmds:
# Clear PSModulePath so powershell.exe (5.1) reconstructs its own module
# path instead of inheriting pwsh 7's incompatible module paths.
# Taskfile uses mvdan/sh (POSIX sh), so we use env-prefix assignment
# syntax (not cmd.exe `set` or pwsh `$env:` syntax).
# See: https://github.com/PowerShell/PowerShell/issues/18530#issuecomment-1325691850
- PSModulePath= powershell.exe -ExecutionPolicy Bypass -File ./smoke_test_scripts/windows/run_smoke_test.ps1 {{if .DR_API_TOKEN}}{{.DR_API_TOKEN}}{{else}}$env:DR_API_TOKEN{{end}}
docs-serve:
silent: true
desc: "Serve documentation site locally"
dir: docs
cmds:
- echo "📚 Starting documentation server…"
- uv sync
- echo "🌐 Open http://localhost:8000 in your browser"
- uv run mkdocs serve
copyright:
silent: true
desc: "Apply copyrights to all files"
aliases:
- license
cmds:
- echo "🧹 Applying license headers"
- |
docker run --rm \
-v $PWD:/github/workspace \
ghcr.io/apache/skywalking-eyes/license-eye:4021a396bf07b2136f97c12708476418a8157d72 \
-v info -c .licenserc.yaml header fix
copyright-year:
silent: true
platforms: [linux, darwin]
desc: "Update copyright year in all source files to the current year"
vars:
TO_YEAR:
sh: date +%Y
FROM_YEAR:
sh: echo $(($(date +%Y) - 1))
FIND_GO_FILES: "find cmd internal tui main.go -type f -name '*.go'"
SED_EXPR: "s/Copyright {{.FROM_YEAR}} DataRobot/Copyright {{.TO_YEAR}} DataRobot/g"
COUNT:
sh: "{{.FIND_GO_FILES}} -exec grep -l 'Copyright {{.FROM_YEAR}} DataRobot' {} + 2>/dev/null | wc -l | tr -d ' '"
cmds:
- echo "Updating copyright year from {{.FROM_YEAR}} to {{.TO_YEAR}}"
- platforms: [darwin]
cmd: "{{.FIND_GO_FILES}} -exec sed -i '' '{{.SED_EXPR}}' {} +"
- platforms: [linux]
cmd: "{{.FIND_GO_FILES}} -exec sed -i '{{.SED_EXPR}}' {} +"
- echo "{{.COUNT}} files were updated!"