-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.yml
More file actions
240 lines (210 loc) · 7.73 KB
/
Copy pathTaskfile.yml
File metadata and controls
240 lines (210 loc) · 7.73 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
version: "3"
vars:
VERSION:
sh: git describe --tags --always --dirty 2>/dev/null || echo "dev"
DOCKER_REPO: schedsim
LDFLAGS: -X main.version={{.VERSION}}
SQLITE_WEB_PORT: "8081"
SQLITE_DB_PATH: ./data/schedsim.db
tasks:
# ── Default ────────────────────────────────────────────────────────────────
default:
desc: Start all services (alias for start)
cmds:
- task: start
# ── Environment setup & check ──────────────────────────────────────────────
setup:
desc: Install all dev dependencies (idempotent)
cmds:
- bash scripts/setup.sh
check-env:
desc: Verify dev environment; auto-fix if possible
cmds:
- |
if ! bash scripts/check-env.sh; then
echo ""
echo "Running 'task setup' to install missing dependencies..."
task setup
echo ""
echo "Re-running environment check..."
bash scripts/check-env.sh
fi
# ── Build ──────────────────────────────────────────────────────────────────
build:
desc: "Full build: check-env + frontend + backend"
cmds:
- task: check-env
- task: build-frontend
- task: build-backend
build-backend:
desc: Build Go backend binary (CGO_ENABLED=1)
cmds:
- CGO_ENABLED=1 go build -ldflags "{{.LDFLAGS}}" -o bin/schedsim ./cmd/schedsim
- go build -o bin/schedsim-cli ./cmd/schedsim-cli
build-cli:
desc: Build schedsim-cli binary only
cmds:
- go build -o bin/schedsim-cli ./cmd/schedsim-cli
build-frontend:
desc: Build React frontend
cmds:
- cd web && npm ci && npm run build
status:
- test -d web
# ── Development ────────────────────────────────────────────────────────────
start:
desc: check-env, build if needed, run all services
deps: [check-env, ensure-frontend, sqlite-web-bg]
cmds:
- |
trap 'kill %1 2>/dev/null; exit 0' INT TERM
task dev-backend &
sleep 2
task dev-frontend
dev:
desc: Alias for start
cmds:
- task: start
ensure-frontend:
desc: Build frontend if dist bundle is absent
cmds:
- task: build-frontend
status:
- test -f web/dist/index.html
dev-backend:
desc: Run backend with hot-reload (air) or go run
cmds:
- |
if command -v air > /dev/null 2>&1; then
air
else
echo "air not found — falling back to go run (no hot-reload)."
echo "Install with: task setup"
go run ./cmd/schedsim
fi
dev-frontend:
desc: Run Vite dev server
dir: web
cmds:
- npm run dev
# ── SQLite Web ─────────────────────────────────────────────────────────────
setup-sqlite-web:
desc: Install sqlite_web at pinned version
cmds:
- pip3 install "sqlite-web=$(grep '^sqlite-web ' .tool-versions | awk '{print $2}')"
- echo "sqlite_web installed."
sqlite-web:
desc: Launch sqlite_web in foreground
cmds:
- |
if [ ! -f {{.SQLITE_DB_PATH}} ]; then
echo "Error: database not found at {{.SQLITE_DB_PATH}}. Run 'task dev' first."
exit 1
fi
echo "Starting sqlite_web on http://localhost:{{.SQLITE_WEB_PORT}}"
sqlite_web {{.SQLITE_DB_PATH}} --host 0.0.0.0 --port {{.SQLITE_WEB_PORT}} --no-browser
sqlite-web-bg:
desc: Launch sqlite_web in background (silently skips if not installed)
cmds:
- |
if ! command -v sqlite_web > /dev/null 2>&1; then
echo "sqlite_web not installed (optional) — skipping DB browser."
elif lsof -ti:{{.SQLITE_WEB_PORT}} > /dev/null 2>&1; then
echo "sqlite_web already running on http://localhost:{{.SQLITE_WEB_PORT}}"
else
(
i=0
while [ ! -f {{.SQLITE_DB_PATH}} ] && [ $i -lt 30 ]; do
sleep 1; i=$((i+1))
done
if [ -f {{.SQLITE_DB_PATH}} ]; then
sqlite_web {{.SQLITE_DB_PATH}} --host 0.0.0.0 --port {{.SQLITE_WEB_PORT}} --no-browser &
echo "sqlite_web started in background on http://localhost:{{.SQLITE_WEB_PORT}}"
else
echo "Database not ready after 30s — skipping sqlite_web"
fi
) &
fi
# ── Production ─────────────────────────────────────────────────────────────
prod:
desc: Build then run in production mode
cmds:
- task: build
- task: sqlite-web-bg
- ./bin/schedsim
# ── Docker & Helm ──────────────────────────────────────────────────────────
docker:
desc: Build Docker image with BuildKit cache mount support
vars:
REGISTRY: '{{default "ccr.ccs.tencentyun.com/roczzhang/sched-sim" .REGISTRY}}'
env:
DOCKER_HOST: "unix://{{.HOME}}/.colima/default/docker.sock"
DOCKER_BUILDKIT: "1"
cmds:
- docker build
--platform linux/amd64
-t {{.REGISTRY}}:{{.VERSION}}
-f deploy/docker/Dockerfile
.
docker-push:
desc: Push Docker image
vars:
REGISTRY: '{{default "ccr.ccs.tencentyun.com/roczzhang/sched-sim" .REGISTRY}}'
env:
DOCKER_HOST: "unix://{{.HOME}}/.colima/default/docker.sock"
cmds:
- task: docker
vars: {REGISTRY: "{{.REGISTRY}}"}
- docker push {{.REGISTRY}}:{{.VERSION}}
helm-lint:
desc: Validate Helm chart
cmds:
- helm lint deploy/helm/schedsim
helm-package:
desc: Package Helm chart to dist/
cmds:
- mkdir -p dist
- helm package deploy/helm/schedsim -d dist/
# ── Test & Lint ────────────────────────────────────────────────────────────
test:
desc: Run Go unit tests with coverage
cmds:
- go test ./internal/... ./pkg/... -v -cover
test-cli:
desc: Run CLI unit tests with coverage
cmds:
- go test ./pkg/cli/... -v -cover
test-e2e:
desc: "Run CLI E2E tests (requires SCHEDSIM_BASE_URL and SCHEDSIM_CLI_PATH)"
cmds:
- go test ./test/e2e/ -v -count=1 -run "TestCLI_" -timeout 300s
test-frontend:
desc: Run frontend tests
dir: web
cmds:
- npm test -- --watchAll=false
verify-scenarios:
desc: Verify built-in scenario templates against a running backend
cmds:
- ./scripts/verify-scenarios.sh
lint:
desc: Run golangci-lint + eslint
cmds:
- golangci-lint run ./...
- cd web && npm run lint
# ── Misc ───────────────────────────────────────────────────────────────────
migrate:
desc: Run DB migration
cmds:
- go run ./cmd/schedsim migrate
install-frontend:
desc: Install frontend npm dependencies
dir: web
cmds:
- npm install
clean:
desc: Remove bin/, web/dist/, data/
cmds:
- rm -rf bin/
- rm -rf web/dist/
- rm -rf data/