Taskfile.yaml 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. - internal/agent/hyper/provider.json
  47. generates:
  48. - crush{{exeExt}}
  49. run:
  50. desc: Run build
  51. cmds:
  52. - task: build
  53. - "./crush{{exeExt}} {{.CLI_ARGS}} {{if .RACE}}2>race.log{{end}}"
  54. run:catwalk:
  55. desc: Run build with local Catwalk
  56. env:
  57. CATWALK_URL: http://localhost:8080
  58. cmds:
  59. - task: build
  60. - ./crush{{exeExt}} {{.CLI_ARGS}}
  61. run:onboarding:
  62. desc: Run build with custom config to test onboarding
  63. env:
  64. CRUSH_GLOBAL_DATA: tmp/onboarding/data
  65. CRUSH_GLOBAL_CONFIG: tmp/onboarding/config
  66. cmds:
  67. - task: build
  68. - rm -rf tmp/onboarding
  69. - ./crush{{exeExt}} {{.CLI_ARGS}}
  70. test:
  71. desc: Run tests
  72. cmds:
  73. - go test -race -failfast ./... {{.CLI_ARGS}}
  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. fmt:
  81. desc: Run gofumpt
  82. cmds:
  83. - gofumpt -w .
  84. fmt:html:
  85. desc: Run prettier on HTML/CSS/JS files
  86. cmds:
  87. - prettier --write internal/cmd/stats/index.html internal/cmd/stats/index.css internal/cmd/stats/index.js
  88. modernize:
  89. desc: Run modernize
  90. cmds:
  91. - go run golang.org/x/tools/go/analysis/passes/modernize/cmd/modernize@latest -fix -test ./...
  92. dev:
  93. desc: Run with profiling enabled
  94. env:
  95. CRUSH_PROFILE: true
  96. cmds:
  97. - go run .
  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. - internal/agent/**/*.md
  109. - internal/agent/**/*.md.tpl
  110. - internal/agent/hyper/provider.json
  111. profile:cpu:
  112. desc: 10s CPU profile
  113. cmds:
  114. - go tool pprof -http :6061 'http://localhost:6060/debug/pprof/profile?seconds=10'
  115. profile:heap:
  116. desc: Heap profile
  117. cmds:
  118. - go tool pprof -http :6061 'http://localhost:6060/debug/pprof/heap'
  119. profile:allocs:
  120. desc: Allocations profile
  121. cmds:
  122. - go tool pprof -http :6061 'http://localhost:6060/debug/pprof/allocs'
  123. schema:
  124. desc: Generate JSON schema for configuration
  125. cmds:
  126. - go run main.go schema > schema.json
  127. - echo "Generated schema.json"
  128. generates:
  129. - schema.json
  130. hyper:
  131. desc: Update Hyper embedded provider.json
  132. cmds:
  133. - go generate ./internal/agent/hyper/...
  134. generates:
  135. - ./internal/agent/hyper/provider.json
  136. release:
  137. desc: Create and push a new tag following semver
  138. vars:
  139. NEXT:
  140. sh: svu next --always || go run github.com/caarlos0/svu/v3@latest next --always
  141. prompt: "This will release {{.NEXT}}. Continue?"
  142. preconditions:
  143. - sh: '[ $(git symbolic-ref --short HEAD) = "main" ]'
  144. msg: Not on main branch
  145. - sh: "[ $(git status --porcelain=2 | wc -l) = 0 ]"
  146. msg: "Git is dirty"
  147. - sh: 'gh run list --workflow build.yml --commit $(git rev-parse HEAD) --status success --json conclusion -q ".[0].conclusion" | grep -q success'
  148. msg: "Test build for this commit failed or not present"
  149. - sh: 'gh run list --workflow snapshot.yml --commit $(git rev-parse HEAD) --status success --json conclusion -q ".[0].conclusion" | grep -q success'
  150. msg: "Snapshot build for this commit failed or not present"
  151. cmds:
  152. - task: fetch-tags
  153. - git commit --allow-empty -m "{{.NEXT}}"
  154. - git tag --annotate --sign -m "{{.NEXT}}" {{.NEXT}} {{.CLI_ARGS}}
  155. - echo "Pushing {{.NEXT}}..."
  156. - git push origin main --follow-tags
  157. fetch-tags:
  158. cmds:
  159. - git tag -d nightly || true
  160. - git fetch --tags
  161. deps:
  162. desc: Update Fantasy and Catwalk
  163. env:
  164. # The Go proxy takes a bit of time to see the latest release. Setting
  165. # these bypass it to ensure we can update to a release from a minute ago.
  166. GOPROXY: direct
  167. GONOSUMDB: charm.land/*
  168. cmds:
  169. - go get charm.land/fantasy@latest
  170. - go get charm.land/catwalk@latest
  171. - go mod tidy
  172. swag:
  173. desc: Generate OpenAPI spec from swag annotations
  174. cmds:
  175. - go run github.com/swaggo/swag/cmd/[email protected] init --generalInfo main.go --dir . --output internal/swagger --packageName swagger --parseDependency --parseInternal --parseDepth 5
  176. sources:
  177. - internal/server/*.go
  178. - internal/proto/*.go
  179. - main.go
  180. generates:
  181. - internal/swagger/docs.go
  182. - internal/swagger/swagger.json
  183. - internal/swagger/swagger.yaml
  184. sqlc:
  185. desc: Generate code using SQLC
  186. cmds:
  187. - sqlc generate