Files
go-caatsm/Taskfile.yml
T

236 lines
6.6 KiB
YAML
Raw Normal View History

2024-07-23 11:29:12 +08:00
version: '3'
2024-07-23 11:29:12 +08:00
vars:
build_dir: bin
binary: '{{.build_dir}}/receiver'
cmd: ./cmd/main
2024-07-23 11:29:12 +08:00
tasks:
all:
desc: Default target
cmds:
- task: build
build:
desc: Build the receiver binary
2024-07-23 11:29:12 +08:00
cmds:
- mkdir -p {{.build_dir}}
2024-07-23 11:29:12 +08:00
- echo "Building receiver..."
- go build -o {{.binary}} {{.cmd}}
2024-07-23 11:29:12 +08:00
run:
desc: Alias for run-dev
2024-07-23 11:29:12 +08:00
cmds:
- task: run-dev
run-dev:
desc: Run the receiver in development mode (uses core NATS mode by default)
deps:
- build
cmds:
- |
echo "Running receiver in development mode (NATS mode: core by default)..."
- GO_ENV=dev {{.binary}} listen
2024-07-23 11:29:12 +08:00
run-prod:
desc: Run the receiver in production mode (requires config.prod.toml and JetStream mode)
deps:
- build
2024-07-23 11:29:12 +08:00
cmds:
- |
echo "Running receiver in production mode..."
echo "Note: Production mode requires:"
echo " - configs/config.prod.toml file (or CAATSM_* environment variables)"
echo " - NATS JetStream enabled (nats.mode = jetstream)"
echo " - Stream and Consumer must exist (not auto-created in prod)"
echo " - PostgreSQL connection configured"
- GO_ENV=prod {{.binary}} listen
2024-07-23 11:29:12 +08:00
run-test:
desc: Run the receiver in test mode
deps:
- build
2024-07-23 11:29:12 +08:00
cmds:
- echo "Running receiver in test mode..."
- GO_ENV=test {{.binary}} listen
run-local:
desc: Run receiver via go run (default GO_ENV=dev, uses core NATS mode by default)
cmds:
- |
echo "Running receiver via go run (GO_ENV=${GO_ENV:-dev}, NATS mode: core by default in dev)..."
- |
GO_ENV=${GO_ENV:-dev} go run {{.cmd}} listen
2024-07-23 11:29:12 +08:00
test:
desc: Run Ginkgo unit test suites (verbose)
2024-07-23 11:29:12 +08:00
cmds:
- |
if ! command -v ginkgo >/dev/null; then
echo "Install ginkgo (go install github.com/onsi/ginkgo/v2/ginkgo@latest)"
exit 1
fi
- echo "Running Ginkgo unit test suites (verbose)..."
- ginkgo -r -v ./cmd ./internal
test-int:
desc: Run integration tests (requires Docker)
cmds:
- |
echo "Running integration tests (Docker required)..."
GO_ENV=${GO_ENV:-test} go test -tags=integration ./test/integration/...
test-ginkgo:
desc: Alias for Ginkgo unit test suites
cmds:
- task: test
test-all:
desc: Run unit tests (Ginkgo) and integration tests
cmds:
- task: test
- task: test-int
2024-07-23 11:29:12 +08:00
coverage:
desc: Generate coverage report (profile + HTML)
cmds:
- mkdir -p coverage
- echo "Generating test coverage report..."
- go test ./... -coverprofile=coverage/coverage.out
- go tool cover -html=coverage/coverage.out -o coverage/coverage.html
2024-07-23 11:29:12 +08:00
fmt:
desc: Format Go code
2024-07-23 11:29:12 +08:00
cmds:
- echo "Formatting code..."
- go fmt ./...
lint:
desc: Run golangci-lint
2024-07-23 11:29:12 +08:00
cmds:
- |
if ! command -v golangci-lint >/dev/null; then
echo "Install golangci-lint: https://golangci-lint.run/"
exit 1
fi
- echo "Linting code..."
- golangci-lint run ./...
wire:
desc: Generate wire dependency injection code
cmds:
- |
if ! command -v wire >/dev/null; then
echo "Install wire: go install github.com/google/wire/cmd/wire@latest"
exit 1
fi
- echo "Generating wire code..."
- wire ./pkg/di
generate:
desc: Generate all code (wire, etc.)
cmds:
- task: wire
- echo "Code generation complete"
deps:
desc: Sync go.mod / go.sum
cmds:
- echo "Tidying go modules..."
2024-07-23 11:29:12 +08:00
- go mod tidy
upgrade:
desc: Upgrade Go dependencies
2024-07-23 11:29:12 +08:00
cmds:
- echo "Upgrading go modules..."
- go get -u -v ./...
- go mod tidy
2024-07-23 11:29:12 +08:00
install-test:
desc: Install ginkgo/gomega tooling
cmds:
- echo "Installing ginkgo tooling..."
- go install github.com/onsi/ginkgo/v2/ginkgo@latest
- go get github.com/onsi/gomega/...
clean:
desc: Clean build + coverage artifacts
cmds:
- echo "Cleaning build artifacts..."
- rm -rf {{.build_dir}} coverage
up:
desc: Start TimescaleDB + NATS dev stack (docker compose)
cmds:
- echo "Starting dev infrastructure..."
- docker compose -f docker-compose.dev.yml up -d postgres nats nats-box nats-exporter
- docker compose -f docker-compose.dev.yml up -d otel-collector jaeger prometheus grafana
down:
desc: Stop dev compose stack and remove containers
cmds:
- echo "Stopping dev infrastructure..."
- docker compose -f docker-compose.dev.yml down -v
dev-run-compose:
desc: Run receiver inside docker-compose dev stack
cmds:
- echo "Starting dev stack including caatsm-receiver..."
- docker compose -f docker-compose.dev.yml up -d postgres nats nats-box nats-exporter
- docker compose -f docker-compose.dev.yml up -d otel-collector jaeger prometheus grafana caatsm-receiver
dev-run:
desc: Run receiver locally against dev stack
deps:
- up
env:
CAATSM_NATS_URL: nats://localhost:4222
CAATSM_NATS_MODE: core
CAATSM_POSTGRES_URL: postgres://caatsm:caatsm@localhost:5432/aviation?sslmode=disable
CAATSM_TELEMETRY_ENABLED: "true"
CAATSM_TELEMETRY_ENDPOINT: localhost:4318
CAATSM_TELEMETRY_INSECURE: "true"
CAATSM_MONITORING_ADDR: 0.0.0.0:2112
CAATSM_MONITORING_ENABLE_METRICS: "true"
CAATSM_MONITORING_ENABLE_HEALTH: "true"
GO_ENV: dev
cmds:
- |
echo "Ensuring observability stack is healthy (Jaeger @ http://localhost:16686)"
docker compose -f docker-compose.dev.yml ps jaeger otel-collector >/dev/null
echo "Running receiver with telemetry (mode=${CAATSM_NATS_MODE:-core})"
CAATSM_NATS_MODE=${CAATSM_NATS_MODE:-core} \
go run ./cmd/main listen
seed:
desc: Generate sample telegrams (publishes to Core NATS by default, compatible with dev mode)
cmds:
- |
GO_ENV=dev \
NATS_URL=${CAATSM_NATS_URL:-nats://localhost:4222} \
SUBJECT=${CAATSM_NATS_SUBJECT:-telegram.serial} \
COUNT={{.COUNT | default "10"}} \
CATEGORY={{.CATEGORY | default "mixed"}} \
STATUS={{.STATUS | default "random"}} \
bash -c '
set -euo pipefail
cmd=(go run ./cmd/seed-telegrams)
if [ -n "$NATS_URL" ]; then
cmd+=("--nats-url" "$NATS_URL")
fi
cmd+=(
--subject "$SUBJECT"
--count "$COUNT"
--category "$CATEGORY"
--status "$STATUS"
)
exec "${cmd[@]}"
'
2024-07-23 11:29:12 +08:00
help:
desc: Show this help message
cmds:
- |
printf "Task targets:\n"
task --list