-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtaskfile.yml
More file actions
244 lines (214 loc) · 5.93 KB
/
taskfile.yml
File metadata and controls
244 lines (214 loc) · 5.93 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
version: '3'
# Variables
vars:
APP_NAME: mpiper
BUILD_DIR: build
MAIN_PATH: cmd/server/main.go
# Dynamic variables
BUILD_TIME:
sh: |
# Use PowerShell when available (Windows / pwsh), otherwise fallback to UTC date
if command -v pwsh >/dev/null 2>&1 || command -v powershell >/dev/null 2>&1; then
if command -v pwsh >/dev/null 2>&1; then
pwsh -NoProfile -Command "Get-Date -Format 'yyyy-MM-ddTHH:mm:ssZ'"
else
powershell -NoProfile -Command "Get-Date -Format 'yyyy-MM-ddTHH:mm:ssZ'"
fi
else
date -u +%Y-%m-%dT%H:%M:%SZ
fi
GIT_COMMIT:
sh: |
git rev-parse --short HEAD 2>/dev/null || echo unknown
VERSION:
sh: toml get --toml-path mpiper.toml version
# Build flags
LDFLAGS: >-
-X 'main.Version={{.VERSION}}'
-X 'main.BuildTime={{.BUILD_TIME}}'
-X 'main.CommitHash={{.GIT_COMMIT}}'
# Tasks
tasks:
default:
desc: Show available tasks
cmds:
- task --list
install:
desc: Install dependencies
cmds:
- go mod download
- go mod tidy
run:
desc: Run the application (development)
cmds:
- air -c .air.toml
dev:
desc: Run the application (development)
env:
LOG_LEVEL: DEBUG
ENV: development
cmds:
- go run -ldflags="{{.LDFLAGS}} -X 'main.Env=development'" {{.MAIN_PATH}}
staging:
desc: Run the application (staging)
env:
LOG_LEVEL: INFO
ENV: staging
cmds:
- go run -ldflags="{{.LDFLAGS}}" {{.MAIN_PATH}}
prod:
desc: Run the application (production)
env:
LOG_LEVEL: WARN
ENV: production
cmds:
- go run -ldflags="{{.LDFLAGS}}" {{.MAIN_PATH}}
build:
desc: Build the application
cmds:
- echo "Building {{.APP_NAME}} version {{.VERSION}}"
- mkdir -p {{.BUILD_DIR}}
- CGO_ENABLED=0 go build -ldflags="-w -s {{.LDFLAGS}}" -o {{.BUILD_DIR}}/{{.APP_NAME}}.exe {{.MAIN_PATH}}
- echo "Build completed {{.BUILD_DIR}}/{{.APP_NAME}}"
run-binary:
desc: Run the built binary
env:
LOG_LEVEL: INFO
ENV: production
cmds:
- ./{{.BUILD_DIR}}/{{.APP_NAME}}.exe
build-prod:
desc: Build the application for production
env:
ENV: production
cmds:
- task build
build-all:
desc: Build for all platforms
cmds:
- task: build-windows
- task: build-linux
- task: build-mac
build-windows:
desc: Build for Windows
env:
GOOS: windows
GOARCH: amd64
cmds:
- go build -ldflags="{{.LDFLAGS}}" -o {{.BUILD_DIR}}/{{.APP_NAME}}-windows-amd64.exe {{.MAIN_PATH}}
build-linux:
desc: Build for Linux
env:
GOOS: linux
GOARCH: amd64
cmds:
- go build -ldflags="{{.LDFLAGS}}" -o {{.BUILD_DIR}}/{{.APP_NAME}}-linux-amd64 {{.MAIN_PATH}}
build-mac:
desc: Build for macOS
env:
GOOS: darwin
GOARCH: amd64
cmds:
- go build -ldflags="{{.LDFLAGS}}" -o {{.BUILD_DIR}}/{{.APP_NAME}}-darwin-amd64 {{.MAIN_PATH}}
test:
desc: Run tests
cmds:
- gotestsum --format testname --format-icons codicons -- -v {{.CLI_ARGS}}
test-coverage:
desc: Run tests with coverage
cmds:
- go test -v -coverprofile=coverage.out ./...
- go tool cover -html=coverage.out -o coverage.html
- echo "✅ Coverage report - coverage.html"
lint:
desc: Run linter
cmds:
- golangci-lint run ./...
fmt:
desc: Format code
cmds:
- go fmt ./...
- goimports -w .
clean:
desc: Clean build artifacts
cmds:
- powershell -Command "if (Test-Path {{.BUILD_DIR}}) { Remove-Item -Recurse -Force {{.BUILD_DIR}} }"
- powershell -Command "if (Test-Path coverage.out) { Remove-Item coverage.out }"
- powershell -Command "if (Test-Path coverage.html) { Remove-Item coverage.html }"
- echo "✅ Cleaned build artifacts"
docker-build-worker:
desc: Build Docker image for worker
cmds:
- docker build
--build-arg ENV=development
--build-arg VERSION={{.VERSION}}
--build-arg BUILD_TIME={{.BUILD_TIME}}
--build-arg COMMIT_HASH={{.GIT_COMMIT}}
-t {{.APP_NAME}}-worker:{{.VERSION}}
-f deploy/docker/worker.dockerfile .
docker-run-worker:
desc: Run Docker container for worker
cmds:
- docker run
--rm
--name {{.APP_NAME}}_worker_dev
--env-file .env.local
-v .secrets/:/app/.secrets:ro
-e DB_HOST=host.docker.internal
-e ENV=development
-e LOG_LEVEL=DEBUG
-e VERSION={{.VERSION}}
-e BUILD_TIME={{.BUILD_TIME}}
-e COMMIT_HASH={{.GIT_COMMIT}}
{{.APP_NAME}}-worker:{{.VERSION}}
docker-build:
desc: Build Docker image
cmds:
- docker build
--build-arg ENV=development
--build-arg VERSION={{.VERSION}}
--build-arg BUILD_TIME={{.BUILD_TIME}}
--build-arg COMMIT_HASH={{.GIT_COMMIT}}
--build-arg HOST=0.0.0.0
-t {{.APP_NAME}}:{{.VERSION}} .
docker-run:
desc: Run Docker container
cmds:
- docker run
--rm
-p 5010:5010
--name {{.APP_NAME}}_dev
--env-file .env.local
-e DB_HOST=host.docker.internal
-e ENV=development
-e HOST=0.0.0.0
-e LOG_LEVEL=DEBUG
-e VERSION={{.VERSION}}
-e BUILD_TIME={{.BUILD_TIME}}
-e COMMIT_HASH={{.GIT_COMMIT}}
{{.APP_NAME}}:{{.VERSION}}
deps-update:
desc: Update dependencies
cmds:
- go get -u ./...
- go mod tidy
version:
desc: Show version information
cmds:
- echo "App Name {{.APP_NAME}}"
- echo "Version {{.VERSION}}"
- echo "Build Time {{.BUILD_TIME}}"
- echo "Git Commit {{.GIT_COMMIT}}"
all:
desc: Clean, build, and test
cmds:
- task: clean
- task: build
- task: test
ci:
desc: Run CI pipeline
cmds:
- task: fmt
- task: lint
- task: test
- task: build