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 {{if .RACE}}-race{{end}} {{.LDFLAGS}} ."
49 sources:
50 - ./**/*.go
51 - go.mod
52 generates:
53 - crush{{exeExt}}
54
55 run:
56 desc: Run build
57 cmds:
58 - task: build
59 - "./crush {{.CLI_ARGS}} {{if .RACE}}2>race.log{{end}}"
60
61 run:catwalk:
62 desc: Run build with local Catwalk
63 env:
64 CATWALK_URL: http://localhost:8080
65 cmds:
66 - task: build
67 - ./crush {{.CLI_ARGS}}
68
69 test:
70 desc: Run tests
71 cmds:
72 - go test -race -failfast ./... {{.CLI_ARGS}}
73
74 test:record:
75 desc: Run tests and record all VCR cassettes again
76 aliases: [record]
77 cmds:
78 - rm -r internal/agent/testdata
79 - go test -v -count=1 -timeout=1h ./internal/agent
80
81 fmt:
82 desc: Run gofumpt
83 cmds:
84 - gofumpt -w .
85
86 fmt:html:
87 desc: Run prettier on HTML/CSS/JS files
88 cmds:
89 - prettier --write internal/cmd/stats/index.html internal/cmd/stats/index.css internal/cmd/stats/index.js
90
91 modernize:
92 desc: Run modernize
93 cmds:
94 - go run golang.org/x/tools/go/analysis/passes/modernize/cmd/modernize@latest -fix -test ./...
95
96 dev:
97 desc: Run with profiling enabled
98 env:
99 CRUSH_PROFILE: true
100 cmds:
101 - go run .
102
103 install:
104 desc: Install the application
105 vars:
106 LDFLAGS: '{{if .VERSION}}-ldflags="-X github.com/charmbracelet/crush/internal/version.Version={{.VERSION}}"{{end}}'
107 cmds:
108 - task: fetch-tags
109 - go install {{.LDFLAGS}} -v .
110 sources:
111 - ./**/*.go
112 - go.mod
113
114 profile:cpu:
115 desc: 10s CPU profile
116 cmds:
117 - go tool pprof -http :6061 'http://localhost:6060/debug/pprof/profile?seconds=10'
118
119 profile:heap:
120 desc: Heap profile
121 cmds:
122 - go tool pprof -http :6061 'http://localhost:6060/debug/pprof/heap'
123
124 profile:allocs:
125 desc: Allocations profile
126 cmds:
127 - go tool pprof -http :6061 'http://localhost:6060/debug/pprof/allocs'
128
129 schema:
130 desc: Generate JSON schema for configuration
131 cmds:
132 - go run main.go schema > schema.json
133 - echo "Generated schema.json"
134 generates:
135 - schema.json
136
137 hyper:
138 desc: Update Hyper embedded provider.json
139 cmds:
140 - go generate ./internal/agent/hyper/...
141 generates:
142 - ./internal/agent/hyper/provider.json
143
144 release:
145 desc: Create and push a new tag following semver
146 vars:
147 NEXT:
148 sh: svu next --always || go run github.com/caarlos0/svu/v3@latest next --always
149 prompt: "This will release {{.NEXT}}. Continue?"
150 preconditions:
151 - sh: '[ $(git symbolic-ref --short HEAD) = "main" ]'
152 msg: Not on main branch
153 - sh: "[ $(git status --porcelain=2 | wc -l) = 0 ]"
154 msg: "Git is dirty"
155 - sh: 'gh run list --workflow build.yml --commit $(git rev-parse HEAD) --status success --json conclusion -q ".[0].conclusion" | grep -q success'
156 msg: "Test build for this commit failed or not present"
157 - sh: 'gh run list --workflow snapshot.yml --commit $(git rev-parse HEAD) --status success --json conclusion -q ".[0].conclusion" | grep -q success'
158 msg: "Snapshot build for this commit failed or not present"
159 cmds:
160 - task: fetch-tags
161 - git commit --allow-empty -m "{{.NEXT}}"
162 - git tag --annotate --sign -m "{{.NEXT}}" {{.NEXT}} {{.CLI_ARGS}}
163 - echo "Pushing {{.NEXT}}..."
164 - git push origin main --follow-tags
165
166 fetch-tags:
167 cmds:
168 - git tag -d nightly || true
169 - git fetch --tags
170
171 deps:
172 desc: Update Fantasy and Catwalk
173 cmds:
174 - go get charm.land/fantasy
175 - go get charm.land/catwalk
176 - go mod tidy