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