Taskfile.yaml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. # https://taskfile.dev
  2. version: "3"
  3. vars:
  4. VERSION:
  5. sh: git describe --long 2>/dev/null || echo ""
  6. RACE:
  7. sh: test -f race.log && echo "1" || echo ""
  8. env:
  9. CGO_ENABLED: 0
  10. GOEXPERIMENT: greenteagc
  11. tasks:
  12. lint:install:
  13. desc: Install golangci-lint
  14. cmds:
  15. - go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
  16. env:
  17. GOTOOLCHAIN: go1.25.0
  18. lint:
  19. desc: Run base linters
  20. cmds:
  21. - task: lint:log
  22. - golangci-lint run --path-mode=abs --config=".golangci.yml" --timeout=5m
  23. env:
  24. GOEXPERIMENT: null
  25. lint:log:
  26. desc: Check that log messages start with capital letters
  27. cmds:
  28. - ./scripts/check_log_capitalization.sh
  29. lint:fix:
  30. desc: Run base linters and fix issues
  31. cmds:
  32. - golangci-lint run --path-mode=abs --config=".golangci.yml" --timeout=5m --fix
  33. env:
  34. GOEXPERIMENT: null
  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 -v {{if .RACE}}-race{{end}} {{.LDFLAGS}} ."
  41. sources:
  42. - ./**/*.go
  43. - go.mod
  44. - internal/agent/**/*.md
  45. - internal/agent/**/*.md.tpl
  46. generates:
  47. - crush{{exeExt}}
  48. run:
  49. desc: Run build
  50. cmds:
  51. - task: build
  52. - "./crush{{exeExt}} {{.CLI_ARGS}} {{if .RACE}}2>race.log{{end}}"
  53. run:catwalk:
  54. desc: Run build with local Catwalk
  55. env:
  56. CATWALK_URL: http://localhost:8080
  57. cmds:
  58. - task: build
  59. - ./crush{{exeExt}} {{.CLI_ARGS}}
  60. run:onboarding:
  61. desc: Run build with custom config to test onboarding
  62. env:
  63. CRUSH_GLOBAL_DATA: tmp/onboarding/data
  64. CRUSH_GLOBAL_CONFIG: tmp/onboarding/config
  65. cmds:
  66. - task: build
  67. - rm -rf tmp/onboarding
  68. - ./crush{exeExt} {{.CLI_ARGS}}
  69. test:
  70. desc: Run tests
  71. cmds:
  72. - go test -race -failfast ./... {{.CLI_ARGS}}
  73. test:record:
  74. desc: Run tests and record all VCR cassettes again
  75. aliases: [record]
  76. cmds:
  77. - rm -r internal/agent/testdata
  78. - go test -v -count=1 -timeout=1h ./internal/agent
  79. fmt:
  80. desc: Run gofumpt
  81. cmds:
  82. - gofumpt -w .
  83. fmt:html:
  84. desc: Run prettier on HTML/CSS/JS files
  85. cmds:
  86. - prettier --write internal/cmd/stats/index.html internal/cmd/stats/index.css internal/cmd/stats/index.js
  87. modernize:
  88. desc: Run modernize
  89. cmds:
  90. - go run golang.org/x/tools/go/analysis/passes/modernize/cmd/modernize@latest -fix -test ./...
  91. dev:
  92. desc: Run with profiling enabled
  93. env:
  94. CRUSH_PROFILE: true
  95. cmds:
  96. - go run .
  97. install:
  98. desc: Install the application
  99. vars:
  100. LDFLAGS: '{{if .VERSION}}-ldflags="-X github.com/charmbracelet/crush/internal/version.Version={{.VERSION}}"{{end}}'
  101. cmds:
  102. - task: fetch-tags
  103. - go install {{.LDFLAGS}} -v .
  104. sources:
  105. - ./**/*.go
  106. - go.mod
  107. - internal/agent/**/*.md
  108. - internal/agent/**/*.md.tpl
  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. profile:heap:
  114. desc: Heap profile
  115. cmds:
  116. - go tool pprof -http :6061 'http://localhost:6060/debug/pprof/heap'
  117. profile:allocs:
  118. desc: Allocations profile
  119. cmds:
  120. - go tool pprof -http :6061 'http://localhost:6060/debug/pprof/allocs'
  121. schema:
  122. desc: Generate JSON schema for configuration
  123. cmds:
  124. - go run main.go schema > schema.json
  125. - echo "Generated schema.json"
  126. generates:
  127. - schema.json
  128. hyper:
  129. desc: Update Hyper embedded provider.json
  130. cmds:
  131. - go generate ./internal/agent/hyper/...
  132. generates:
  133. - ./internal/agent/hyper/provider.json
  134. release:
  135. desc: Create and push a new tag following semver
  136. vars:
  137. NEXT:
  138. sh: svu next --always || go run github.com/caarlos0/svu/v3@latest next --always
  139. prompt: "This will release {{.NEXT}}. Continue?"
  140. preconditions:
  141. - sh: '[ $(git symbolic-ref --short HEAD) = "main" ]'
  142. msg: Not on main branch
  143. - sh: "[ $(git status --porcelain=2 | wc -l) = 0 ]"
  144. msg: "Git is dirty"
  145. - sh: 'gh run list --workflow build.yml --commit $(git rev-parse HEAD) --status success --json conclusion -q ".[0].conclusion" | grep -q success'
  146. msg: "Test build for this commit failed or not present"
  147. - sh: 'gh run list --workflow snapshot.yml --commit $(git rev-parse HEAD) --status success --json conclusion -q ".[0].conclusion" | grep -q success'
  148. msg: "Snapshot build for this commit failed or not present"
  149. cmds:
  150. - task: fetch-tags
  151. - git commit --allow-empty -m "{{.NEXT}}"
  152. - git tag --annotate --sign -m "{{.NEXT}}" {{.NEXT}} {{.CLI_ARGS}}
  153. - echo "Pushing {{.NEXT}}..."
  154. - git push origin main --follow-tags
  155. fetch-tags:
  156. cmds:
  157. - git tag -d nightly || true
  158. - git fetch --tags
  159. deps:
  160. desc: Update Fantasy and Catwalk
  161. env:
  162. # The Go proxy takes a bit of time to see the latest release. Setting
  163. # these bypass it to ensure we can update to a release from a minute ago.
  164. GOPROXY: direct
  165. GONOSUMDB: charm.land/*
  166. cmds:
  167. - go get charm.land/fantasy@latest
  168. - go get charm.land/catwalk@latest
  169. - go mod tidy
  170. sqlc:
  171. desc: Generate code using SQLC
  172. cmds:
  173. - sqlc generate