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 {{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  dev:
 92    desc: Run with profiling enabled
 93    env:
 94      CRUSH_PROFILE: true
 95    cmds:
 96      - go run .
 97
 98  install:
 99    desc: Install the application
100    vars:
101      LDFLAGS: '{{if .VERSION}}-ldflags="-X github.com/charmbracelet/crush/internal/version.Version={{.VERSION}}"{{end}}'
102    cmds:
103      - task: fetch-tags
104      - go install {{.LDFLAGS}} -v .
105    sources:
106      - ./**/*.go
107      - go.mod
108
109  profile:cpu:
110    desc: 10s CPU profile
111    cmds:
112      - go tool pprof -http :6061 'http://localhost:6060/debug/pprof/profile?seconds=10'
113
114  profile:heap:
115    desc: Heap profile
116    cmds:
117      - go tool pprof -http :6061 'http://localhost:6060/debug/pprof/heap'
118
119  profile:allocs:
120    desc: Allocations profile
121    cmds:
122      - go tool pprof -http :6061 'http://localhost:6060/debug/pprof/allocs'
123
124  schema:
125    desc: Generate JSON schema for configuration
126    cmds:
127      - go run main.go schema > schema.json
128      - echo "Generated schema.json"
129    generates:
130      - schema.json
131
132  hyper:
133    desc: Update Hyper embedded provider.json
134    cmds:
135      - go generate ./internal/agent/hyper/...
136    generates:
137      - ./internal/agent/hyper/provider.json
138
139  release:
140    desc: Create and push a new tag following semver
141    vars:
142      NEXT:
143        sh: svu next --always || go run github.com/caarlos0/svu/v3@latest next --always
144    prompt: "This will release {{.NEXT}}. Continue?"
145    preconditions:
146      - sh: '[ $(git symbolic-ref --short HEAD) = "main" ]'
147        msg: Not on main branch
148      - sh: "[ $(git status --porcelain=2 | wc -l) = 0 ]"
149        msg: "Git is dirty"
150      - sh: 'gh run list --workflow build.yml --commit $(git rev-parse HEAD) --status success --json conclusion -q ".[0].conclusion" | grep -q success'
151        msg: "Test build for this commit failed or not present"
152      - sh: 'gh run list --workflow snapshot.yml --commit $(git rev-parse HEAD) --status success --json conclusion -q ".[0].conclusion" | grep -q success'
153        msg: "Snapshot build for this commit failed or not present"
154    cmds:
155      - task: fetch-tags
156      - git commit --allow-empty -m "{{.NEXT}}"
157      - git tag --annotate --sign -m "{{.NEXT}}" {{.NEXT}} {{.CLI_ARGS}}
158      - echo "Pushing {{.NEXT}}..."
159      - git push origin main --follow-tags
160
161  fetch-tags:
162    cmds:
163      - git tag -d nightly || true
164      - git fetch --tags
165
166  deps:
167    desc: Update Fantasy and Catwalk
168    cmds:
169      - go get charm.land/fantasy
170      - go get charm.land/catwalk
171      - go mod tidy