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