Taskfile.yaml

  1# https://taskfile.dev
  2
  3version: "3"
  4
  5vars:
  6  VERSION:
  7    sh: git describe --long 2>/dev/null || echo ""
  8
  9env:
 10  CGO_ENABLED: 0
 11  GOEXPERIMENT: greenteagc
 12
 13tasks:
 14  lint:install:
 15    desc: Install golangci-lint
 16    cmds:
 17      - go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
 18    env:
 19      GOTOOLCHAIN: go1.25.0
 20
 21  lint:
 22    desc: Run base linters
 23    cmds:
 24      - golangci-lint run --path-mode=abs --config=".golangci.yml" --timeout=5m
 25    env:
 26      GOEXPERIMENT: null
 27
 28  lint:fix:
 29    desc: Run base linters and fix issues
 30    cmds:
 31      - golangci-lint run --path-mode=abs --config=".golangci.yml" --timeout=5m --fix
 32    env:
 33      GOEXPERIMENT: null
 34
 35  build:
 36    desc: Run build
 37    vars:
 38      LDFLAGS: '{{if .VERSION}}-ldflags="-X github.com/charmbracelet/crush/internal/version.Version={{.VERSION}}"{{end}}'
 39    cmds:
 40      - go build {{.LDFLAGS}} .
 41    generates:
 42      - crush
 43
 44  run:
 45    desc: Run build
 46    cmds:
 47      - go run . {{.CLI_ARGS}}
 48
 49  test:
 50    desc: Run tests
 51    cmds:
 52      - go test ./... {{.CLI_ARGS}}
 53
 54  fmt:
 55    desc: Run gofumpt
 56    cmds:
 57      - gofumpt -w .
 58
 59  dev:
 60    desc: Run with profiling enabled
 61    env:
 62      CRUSH_PROFILE: true
 63    cmds:
 64      - go run .
 65
 66  install:
 67    desc: Install the application
 68    vars:
 69      LDFLAGS: '{{if .VERSION}}-ldflags="-X github.com/charmbracelet/crush/internal/version.Version={{.VERSION}}"{{end}}'
 70    cmds:
 71      - task: fetch-tags
 72      - go install {{.LDFLAGS}} -v .
 73
 74  profile:cpu:
 75    desc: 10s CPU profile
 76    cmds:
 77      - go tool pprof -http :6061 'http://localhost:6060/debug/pprof/profile?seconds=10'
 78
 79  profile:heap:
 80    desc: Heap profile
 81    cmds:
 82      - go tool pprof -http :6061 'http://localhost:6060/debug/pprof/heap'
 83
 84  profile:allocs:
 85    desc: Allocations profile
 86    cmds:
 87      - go tool pprof -http :6061 'http://localhost:6060/debug/pprof/allocs'
 88
 89  schema:
 90    desc: Generate JSON schema for configuration
 91    cmds:
 92      - go run main.go schema > schema.json
 93      - echo "Generated schema.json"
 94    generates:
 95      - schema.json
 96
 97  release:
 98    desc: Create and push a new tag following semver
 99    vars:
100      NEXT:
101        sh: svu next --always || go run github.com/caarlos0/svu/v3@latest next --always
102    prompt: "This will release {{.NEXT}}. Continue?"
103    preconditions:
104      - sh: '[ $(git symbolic-ref --short HEAD) = "main" ]'
105        msg: Not on main branch
106      - sh: "[ $(git status --porcelain=2 | wc -l) = 0 ]"
107        msg: "Git is dirty"
108    cmds:
109      - task: fetch-tags
110      - git commit --allow-empty -m "{{.NEXT}}"
111      - git tag --annotate --sign -m "{{.NEXT}}" {{.NEXT}} {{.CLI_ARGS}}
112      - echo "Pushing {{.NEXT}}..."
113      - git push origin main --follow-tags
114
115  fetch-tags:
116    cmds:
117      - git tag -d nightly || true
118      - git fetch --tags