Taskfile.yaml 4.8 KB

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