1# https://taskfile.dev
2
3version: "3"
4
5vars:
6 VERSION:
7 sh: git describe --long 2>/dev/null || echo ""
8 RACE:
9 sh: test -f race.log && echo "1" || echo ""
10
11env:
12 CGO_ENABLED: 0
13 GOEXPERIMENT: greenteagc
14
15tasks:
16 lint:install:
17 desc: Install golangci-lint
18 cmds:
19 - go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
20 env:
21 GOTOOLCHAIN: go1.25.0
22
23 lint:
24 desc: Run base linters
25 cmds:
26 - task: lint:log
27 - golangci-lint run --path-mode=abs --config=".golangci.yml" --timeout=5m
28 env:
29 GOEXPERIMENT: null
30
31 lint:log:
32 desc: Check that log messages start with capital letters
33 cmds:
34 - ./scripts/check_log_capitalization.sh
35
36 lint:fix:
37 desc: Run base linters and fix issues
38 cmds:
39 - golangci-lint run --path-mode=abs --config=".golangci.yml" --timeout=5m --fix
40 env:
41 GOEXPERIMENT: null
42
43 build:
44 desc: Run build
45 vars:
46 LDFLAGS: '{{if .VERSION}}-ldflags="-X github.com/charmbracelet/crush/internal/version.Version={{.VERSION}}"{{end}}'
47 cmds:
48 - "go build -v {{if .RACE}}-race{{end}} {{.LDFLAGS}} ."
49 sources:
50 - ./**/*.go
51 - go.mod
52 - internal/agent/**/*.md
53 - internal/agent/**/*.md.tpl
54 - internal/agent/hyper/provider.json
55 generates:
56 - crush{{exeExt}}
57
58 run:
59 desc: Run build
60 cmds:
61 - task: build
62 - "./crush{{exeExt}} {{.CLI_ARGS}} {{if .RACE}}2>race.log{{end}}"
63
64 run:catwalk:
65 desc: Run build with local Catwalk
66 env:
67 CATWALK_URL: http://localhost:8080
68 cmds:
69 - task: build
70 - ./crush{{exeExt}} {{.CLI_ARGS}}
71
72 run:onboarding:
73 desc: Run build with custom config to test onboarding
74 env:
75 CRUSH_GLOBAL_DATA: tmp/onboarding/data
76 CRUSH_GLOBAL_CONFIG: tmp/onboarding/config
77 cmds:
78 - task: build
79 - rm -rf tmp/onboarding
80 - ./crush{{exeExt}} {{.CLI_ARGS}}
81
82 test:
83 desc: Run tests
84 cmds:
85 - go test -race -failfast ./... {{.CLI_ARGS}}
86
87 test:record:
88 desc: Run tests and record all VCR cassettes again
89 aliases: [record]
90 cmds:
91 - rm -r internal/agent/testdata
92 - go test -v -count=1 -timeout=1h ./internal/agent
93
94 fmt:
95 desc: Run gofumpt
96 cmds:
97 - gofumpt -w .
98
99 fmt:html:
100 desc: Run prettier on HTML/CSS/JS files
101 cmds:
102 - prettier --write internal/cmd/stats/index.html internal/cmd/stats/index.css internal/cmd/stats/index.js
103
104 modernize:
105 desc: Run modernize
106 cmds:
107 - go run golang.org/x/tools/go/analysis/passes/modernize/cmd/modernize@latest -fix -test ./...
108
109 dev:
110 desc: Run with profiling enabled
111 env:
112 CRUSH_PROFILE: true
113 cmds:
114 - go run .
115
116 install:
117 desc: Install the application
118 vars:
119 LDFLAGS: '{{if .VERSION}}-ldflags="-X github.com/charmbracelet/crush/internal/version.Version={{.VERSION}}"{{end}}'
120 cmds:
121 - task: fetch-tags
122 - go install {{.LDFLAGS}} -v .
123 sources:
124 - ./**/*.go
125 - go.mod
126 - internal/agent/**/*.md
127 - internal/agent/**/*.md.tpl
128 - internal/agent/hyper/provider.json
129
130 profile:cpu:
131 desc: 10s CPU profile
132 cmds:
133 - go tool pprof -http :6061 'http://localhost:6060/debug/pprof/profile?seconds=10'
134
135 profile:heap:
136 desc: Heap profile
137 cmds:
138 - go tool pprof -http :6061 'http://localhost:6060/debug/pprof/heap'
139
140 profile:allocs:
141 desc: Allocations profile
142 cmds:
143 - go tool pprof -http :6061 'http://localhost:6060/debug/pprof/allocs'
144
145 schema:
146 desc: Generate JSON schema for configuration
147 cmds:
148 - go run main.go schema > schema.json
149 - echo "Generated schema.json"
150 generates:
151 - schema.json
152
153 hyper:
154 desc: Update Hyper embedded provider.json
155 cmds:
156 - go generate ./internal/agent/hyper/...
157 generates:
158 - ./internal/agent/hyper/provider.json
159
160 release:
161 desc: Create and push a new tag following semver
162 vars:
163 NEXT:
164 sh: svu next --always || go run github.com/caarlos0/svu/v3@latest next --always
165 prompt: "This will release {{.NEXT}}. Continue?"
166 preconditions:
167 - sh: '[ $(git symbolic-ref --short HEAD) = "main" ]'
168 msg: Not on main branch
169 - sh: "[ $(git status --porcelain=2 | wc -l) = 0 ]"
170 msg: "Git is dirty"
171 - sh: 'gh run list --workflow build.yml --commit $(git rev-parse HEAD) --status success --json conclusion -q ".[0].conclusion" | grep -q success'
172 msg: "Test build for this commit failed or not present"
173 - sh: 'gh run list --workflow snapshot.yml --commit $(git rev-parse HEAD) --status success --json conclusion -q ".[0].conclusion" | grep -q success'
174 msg: "Snapshot build for this commit failed or not present"
175 cmds:
176 - task: fetch-tags
177 - git commit --allow-empty -m "{{.NEXT}}"
178 - git tag --annotate --sign -m "{{.NEXT}}" {{.NEXT}} {{.CLI_ARGS}}
179 - echo "Pushing {{.NEXT}}..."
180 - git push origin main --follow-tags
181
182 fetch-tags:
183 cmds:
184 - git tag -d nightly || true
185 - git fetch --tags
186
187 deps:
188 desc: Update Fantasy and Catwalk
189 env:
190 # The Go proxy takes a bit of time to see the latest release. Setting
191 # these bypass it to ensure we can update to a release from a minute ago.
192 GOPROXY: direct
193 GONOSUMDB: charm.land/*
194 cmds:
195 - go get charm.land/fantasy@latest
196 - go get charm.land/catwalk@latest
197 - go mod tidy
198
199 swag:
200 desc: Generate OpenAPI spec from swag annotations
201 cmds:
202 - go run github.com/swaggo/swag/cmd/swag@v1.16.6 init --generalInfo main.go --dir . --output internal/swagger --packageName swagger --parseDependency --parseInternal --parseDepth 5
203 sources:
204 - internal/server/*.go
205 - internal/proto/*.go
206 - main.go
207 generates:
208 - internal/swagger/docs.go
209 - internal/swagger/swagger.json
210 - internal/swagger/swagger.yaml
211
212 sqlc:
213 desc: Generate code using SQLC
214 cmds:
215 - sqlc generate