|
| 1 | +version: '3' |
| 2 | + |
| 3 | +vars: |
| 4 | + PROJECT_ROOT: |
| 5 | + sh: pwd |
| 6 | + GOBIN: '{{.PROJECT_ROOT}}/bin' |
| 7 | + GOLANGCI_LINT_BINARY: '{{.GOBIN}}/golangci-lint' |
| 8 | + REQUIRED_GOLANGCI_LINT_VERSION: |
| 9 | + sh: cat .golangci.version 2>/dev/null || echo "2.9.0" |
| 10 | + GOLANGCI_LINT_VERSION: |
| 11 | + sh: '{{.GOLANGCI_LINT_BINARY}} version --format short 2>/dev/null || {{.GOLANGCI_LINT_BINARY}} version --short 2>/dev/null || echo "not-installed"' |
| 12 | + |
| 13 | +env: |
| 14 | + GOBIN: '{{.GOBIN}}' |
| 15 | + |
| 16 | +tasks: |
| 17 | + default: |
| 18 | + desc: Run lint and test with Redis |
| 19 | + cmds: |
| 20 | + - task: lint |
| 21 | + - task: test-with-redis |
| 22 | + |
| 23 | + help: |
| 24 | + desc: Show this help message |
| 25 | + cmds: |
| 26 | + - echo "Available commands:" |
| 27 | + - echo " all - Run linting and tests with Redis" |
| 28 | + - echo " test - Run tests (requires Redis to be running)" |
| 29 | + - echo " test-with-redis - Start Redis, run tests, then cleanup" |
| 30 | + - echo " redis - Start Redis service" |
| 31 | + - echo " redis-stop - Stop Redis service" |
| 32 | + - echo " lint - Run linter" |
| 33 | + - echo " clean - Remove binary files" |
| 34 | + silent: true |
| 35 | + |
| 36 | + clean: |
| 37 | + desc: Remove binary files |
| 38 | + cmds: |
| 39 | + - rm -rf {{.GOBIN}} |
| 40 | + |
| 41 | + test: |
| 42 | + desc: Run tests (requires Redis to be running) |
| 43 | + cmds: |
| 44 | + - cd tests && go test -v -race |
| 45 | + |
| 46 | + redis: |
| 47 | + desc: Start Redis service |
| 48 | + cmds: |
| 49 | + - | |
| 50 | + if redis-cli ping 2>/dev/null | grep -q PONG; then |
| 51 | + echo "✅ Redis is already running" |
| 52 | + else |
| 53 | + echo "🚀 Starting Redis service via Docker..." |
| 54 | + docker-compose up -d |
| 55 | + echo "⏳ Waiting for Redis service to be ready..." |
| 56 | + timeout=30 |
| 57 | + counter=0 |
| 58 | + until docker-compose exec redis redis-cli ping 2>/dev/null | grep -q PONG; do |
| 59 | + sleep 1 |
| 60 | + counter=$((counter + 1)) |
| 61 | + if [ $counter -gt $timeout ]; then |
| 62 | + echo "❌ Timeout waiting for Redis service" |
| 63 | + docker-compose down |
| 64 | + exit 1 |
| 65 | + fi |
| 66 | + done |
| 67 | + echo "✅ Redis service is ready" |
| 68 | + fi |
| 69 | +
|
| 70 | + redis-stop: |
| 71 | + desc: Stop Redis service |
| 72 | + cmds: |
| 73 | + - echo "🧹 Stopping Redis service..." |
| 74 | + - docker-compose down |
| 75 | + |
| 76 | + test-with-redis: |
| 77 | + desc: Start Redis, run tests, then cleanup |
| 78 | + deps: |
| 79 | + - redis |
| 80 | + cmds: |
| 81 | + - echo "🧪 Running tests..." |
| 82 | + - task: test |
| 83 | + - echo "✅ Tests completed!" |
| 84 | + |
| 85 | + lint: |
| 86 | + desc: Run all linters |
| 87 | + deps: |
| 88 | + - golangci-lint |
| 89 | + - tidy-lint |
| 90 | + |
| 91 | + install-golangci-lint: |
| 92 | + desc: Install golangci-lint with the required version |
| 93 | + cmds: |
| 94 | + - mkdir -p {{.GOBIN}} |
| 95 | + - | |
| 96 | + if [ "{{.GOLANGCI_LINT_VERSION}}" != "{{.REQUIRED_GOLANGCI_LINT_VERSION}}" ]; then |
| 97 | + echo "Installing golangci-lint v{{.REQUIRED_GOLANGCI_LINT_VERSION}} (current: {{.GOLANGCI_LINT_VERSION}})..." |
| 98 | + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b {{.GOBIN}} v{{.REQUIRED_GOLANGCI_LINT_VERSION}} |
| 99 | + echo "golangci-lint v{{.REQUIRED_GOLANGCI_LINT_VERSION}} installed successfully" |
| 100 | + fi |
| 101 | + status: |
| 102 | + - test "{{.GOLANGCI_LINT_VERSION}}" = "{{.REQUIRED_GOLANGCI_LINT_VERSION}}" |
| 103 | + |
| 104 | + golangci-lint: |
| 105 | + desc: Run golangci-lint |
| 106 | + deps: |
| 107 | + - install-golangci-lint |
| 108 | + cmds: |
| 109 | + - '{{.GOLANGCI_LINT_BINARY}} version' |
| 110 | + - echo "Running golangci-lint..." |
| 111 | + - '{{.GOLANGCI_LINT_BINARY}} run --timeout=10m --path-prefix .' |
| 112 | + |
| 113 | + tidy-lint: |
| 114 | + desc: Check if go.mod and go.sum are tidy |
| 115 | + cmds: |
| 116 | + - echo "Checking go.mod and go.sum are tidy..." |
| 117 | + - go mod tidy |
| 118 | + - git diff --exit-code -- go.mod go.sum |
0 commit comments