Taskfile.yaml

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