-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathTaskfile.yml
More file actions
176 lines (151 loc) · 5.07 KB
/
Copy pathTaskfile.yml
File metadata and controls
176 lines (151 loc) · 5.07 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
version: "3"
vars:
APP_NAME: ai
GOPATH:
sh: go env GOPATH
DIST_DIR: dist/{{OS}}
BIN_NAME: '{{if eq OS "windows"}}ai.exe{{else}}ai{{end}}'
BIN_PATH: "{{.DIST_DIR}}/{{.BIN_NAME}}"
INSTALL_DIR_UNIX: /usr/local/bin
INSTALL_DIR_WINDOWS: '{{.USERPROFILE}}\bin'
INSTALL_PATH_UNIX: "{{.INSTALL_DIR_UNIX}}/ai"
INSTALL_PATH_WINDOWS: '{{.INSTALL_DIR_WINDOWS}}\ai.exe'
tasks:
default:
desc: Build and test the project
cmds:
- task: build
- task: test
build:
desc: Build the CLI binary to dist/<os>/
cmds:
- task: '{{if eq OS "windows"}}build:windows{{else}}build:unix{{end}}'
build:unix:
internal: true
cmds:
- |
if [ -f "{{.BIN_PATH}}" ] \
&& ! find . \( -name "*.go" -o -name "go.mod" -o -name "go.sum" \) -newer "{{.BIN_PATH}}" | grep -q .; then
echo "Up-to-date: {{.BIN_PATH}}"
exit 0
fi
mkdir -p "{{.DIST_DIR}}"
go build \
-ldflags "-X github.com/kriserickson/ai-cli/cmd.Version=dev-$(date +%y%m%d%H%M%S)" \
-o "{{.BIN_PATH}}" \
.
echo "Built {{.BIN_PATH}}"
build:windows:
internal: true
silent: true
cmds:
- |
powershell -NoProfile -Command "
if (Test-Path '{{.BIN_PATH}}') {
\$bin = (Get-Item '{{.BIN_PATH}}').LastWriteTime
\$srcs = Get-ChildItem -Recurse -File | Where-Object {
\$_.Extension -eq '.go' -or \$_.Name -eq 'go.mod' -or \$_.Name -eq 'go.sum'
}
if (-not (\$srcs | Where-Object { \$_.LastWriteTime -gt \$bin })) {
Write-Output 'Up-to-date: {{.BIN_PATH}}'
exit 0
}
}
if (-not (Test-Path '{{.DIST_DIR}}')) {
New-Item -ItemType Directory -Path '{{.DIST_DIR}}' | Out-Null
}
\$dt = Get-Date -Format 'yyMMddHHmmss'
go build -ldflags \"-X github.com/kriserickson/ai-cli/cmd.Version=dev-\$dt\" -o '{{.BIN_PATH}}' .
Write-Output 'Built {{.BIN_PATH}}'
"
test:
desc: Run all Go tests
cmds:
- go test -cover ./...
test:coverage:
desc: Run all Go tests
cmds:
- go test -coverprofile=coverage.out ./...
test:verbose:
desc: Run all Go tests with verbose output
cmds:
- go test -cover ./... -v
test:pkg:
desc: Run tests for a specific package (set PKG=./internal/llm/...)
vars:
PKG: '{{default "./..." .PKG}}'
cmds:
- go test {{.PKG}}
lint:
desc: Run golangci-lint
env:
PATH: '{{.GOPATH}}/bin:{{.PATH}}'
cmds:
- task: install:lint
- golangci-lint run ./...
lint:fix:
desc: Run golangci-lint and fix issues
env:
PATH: '{{.GOPATH}}/bin:{{.PATH}}'
cmds:
- task: install:lint
- golangci-lint run ./... --fix
install:lint:
desc: Install golangci-lint if missing
internal: true
cmds:
- |
if ! command -v golangci-lint >/dev/null 2>&1 && [ ! -f "{{.GOPATH}}/bin/golangci-lint" ] && [ ! -f "{{.GOPATH}}/bin/golangci-lint.exe" ]; then
echo "Installing golangci-lint v2.10.1..."
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.10.1
fi
install:
desc: Build (if needed) and copy the CLI into an OS-specific PATH directory
silent: true
deps: [build]
cmds:
- task: '{{if eq OS "windows"}}install:windows{{else}}install:unix{{end}}'
install:unix:
internal: true
silent: true
cmds:
- |
mkdir -p "{{.INSTALL_DIR_UNIX}}" 2>/dev/null || {
echo "Permission denied. Try running with sudo: sudo task install"
exit 1
}
[ -f "{{.BIN_PATH}}" ] || {
echo "No built binary found in {{.DIST_DIR}} - run: task build"
exit 1
}
cp "{{.BIN_PATH}}" "{{.INSTALL_PATH_UNIX}}" 2>/dev/null || {
echo "Permission denied. Try running with sudo: sudo task install"
exit 1
}
chmod +x "{{.INSTALL_PATH_UNIX}}"
echo "Installed {{.APP_NAME}} to {{.INSTALL_PATH_UNIX}}"
case ":$PATH:" in
*":{{.INSTALL_DIR_UNIX}}:"*) ;;
*) echo "Ensure {{.INSTALL_DIR_UNIX}} is in your PATH to use the {{.APP_NAME}} command." ;;
esac
install:windows:
internal: true
silent: true
cmds:
- |
powershell -NoProfile -Command "
if (-not (Test-Path '{{.INSTALL_DIR_WINDOWS}}')) {
New-Item -ItemType Directory -Path '{{.INSTALL_DIR_WINDOWS}}' | Out-Null
}
\$binPath = '{{.DIST_DIR}}/ai.exe'
if (-not (Test-Path \$binPath)) {
Write-Error 'No built binary found in {{.DIST_DIR}} - run: task build'
exit 1
}
Copy-Item -Path \$binPath -Destination '{{.INSTALL_PATH_WINDOWS}}' -Force
Write-Output 'Installed {{.APP_NAME}} to {{.INSTALL_PATH_WINDOWS}}'
\$pathEntries = \$env:Path -split ';'
if (-not (\$pathEntries -contains '{{.INSTALL_DIR_WINDOWS}}')) {
Write-Output 'Ensure {{.INSTALL_DIR_WINDOWS}} is in your PATH to use the {{.APP_NAME}} command.'
}
"