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      - golangci-lint run --path-mode=abs --config=".golangci.yml" --timeout=5m
 27    env:
 28      GOEXPERIMENT: null
 29
 30  lint:fix:
 31    desc: Run base linters and fix issues
 32    cmds:
 33      - golangci-lint run --path-mode=abs --config=".golangci.yml" --timeout=5m --fix
 34    env:
 35      GOEXPERIMENT: null
 36
 37  build:
 38    desc: Run build
 39    vars:
 40      LDFLAGS: '{{if .VERSION}}-ldflags="-X github.com/charmbracelet/crush/internal/version.Version={{.VERSION}}"{{end}}'
 41    cmds:
 42      - "go build {{if .RACE}}-race{{end}} {{.LDFLAGS}} ."
 43    generates:
 44      - crush
 45
 46  run:
 47    desc: Run build
 48    cmds:
 49      - task: build
 50      - "./crush {{.CLI_ARGS}} {{if .RACE}}2>race.log{{end}}"
 51
 52  test:
 53    desc: Run tests
 54    cmds:
 55      - go test -race -failfast ./... {{.CLI_ARGS}}
 56
 57  test:record:
 58    desc: Run tests and record all VCR cassettes again
 59    aliases: [record]
 60    cmds:
 61      - rm -r internal/agent/testdata
 62      - go test -v -count=1 -timeout=1h ./internal/agent
 63
 64  fmt:
 65    desc: Run gofumpt
 66    cmds:
 67      - gofumpt -w .
 68
 69  dev:
 70    desc: Run with profiling enabled
 71    env:
 72      CRUSH_PROFILE: true
 73    cmds:
 74      - go run .
 75
 76  install:
 77    desc: Install the application
 78    vars:
 79      LDFLAGS: '{{if .VERSION}}-ldflags="-X github.com/charmbracelet/crush/internal/version.Version={{.VERSION}}"{{end}}'
 80    cmds:
 81      - task: fetch-tags
 82      - go install {{.LDFLAGS}} -v .
 83
 84  profile:cpu:
 85    desc: 10s CPU profile
 86    cmds:
 87      - go tool pprof -http :6061 'http://localhost:6060/debug/pprof/profile?seconds=10'
 88
 89  profile:heap:
 90    desc: Heap profile
 91    cmds:
 92      - go tool pprof -http :6061 'http://localhost:6060/debug/pprof/heap'
 93
 94  profile:allocs:
 95    desc: Allocations profile
 96    cmds:
 97      - go tool pprof -http :6061 'http://localhost:6060/debug/pprof/allocs'
 98
 99  schema:
100    desc: Generate JSON schema for configuration
101    cmds:
102      - go run main.go schema > schema.json
103      - echo "Generated schema.json"
104    generates:
105      - schema.json
106
107  hyper:
108    desc: Update Hyper embedded provider.json
109    cmds:
110      - go generate ./internal/agent/hyper/...
111    generates:
112      - ./internal/agent/hyper/provider.json
113
114  release:
115    desc: Create and push a new tag following semver
116    vars:
117      NEXT:
118        sh: svu next --always || go run github.com/caarlos0/svu/v3@latest next --always
119    prompt: "This will release {{.NEXT}}. Continue?"
120    preconditions:
121      - sh: '[ $(git symbolic-ref --short HEAD) = "main" ]'
122        msg: Not on main branch
123      - sh: "[ $(git status --porcelain=2 | wc -l) = 0 ]"
124        msg: "Git is dirty"
125    cmds:
126      - task: fetch-tags
127      - git commit --allow-empty -m "{{.NEXT}}"
128      - git tag --annotate --sign -m "{{.NEXT}}" {{.NEXT}} {{.CLI_ARGS}}
129      - echo "Pushing {{.NEXT}}..."
130      - git push origin main --follow-tags
131
132  fetch-tags:
133    cmds:
134      - git tag -d nightly || true
135      - git fetch --tags
136
137  deps:
138    desc: Update Fantasy and Catwalk
139    cmds:
140      - go get charm.land/fantasy
141      - go get github.com/charmbracelet/catwalk
142      - go mod tidy