-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
139 lines (103 loc) · 4.13 KB
/
Copy pathMakefile
File metadata and controls
139 lines (103 loc) · 4.13 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
# TaskFlow Makefile
#
# Common targets for development, testing, and CI.
# Use `make <target>` to run a specific command.
GO ?= go
GOFLAGS ?=
BINARY ?= taskflow
PORT ?= 8080
.PHONY: all build vet test race lint sign-payload run clean
all: build vet test
# ── Build ──────────────────────────────────────────────────────
build:
$(GO) build $(GOFLAGS) -o $(BINARY) .
build-race:
$(GO) build $(GOFLAGS) -race -o $(BINARY) .
# ── Static analysis ────────────────────────────────────────────
vet:
$(GO) vet $(GOFLAGS) ./...
fmt:
$(GO) fmt ./...
# fmt-check verifies formatting without modifying files.
# Exits non-zero if any file needs formatting.
fmt-check:
@if [ -n "$$(gofmt -l .)" ]; then \
echo "Files need formatting:"; \
gofmt -l .; \
exit 1; \
fi
# lint runs vet and checks formatting (without modifying).
# Use `make fmt` to auto-format before committing.
lint: vet fmt-check
# ── Tests ──────────────────────────────────────────────────────
test:
$(GO) test $(GOFLAGS) -v -count=1 ./...
test-short:
$(GO) test $(GOFLAGS) -short -count=1 ./...
race:
$(GO) test $(GOFLAGS) -race -v -count=1 ./...
test-all: build-race vet race
@echo "All checks passed ✓"
# ── Database ────────────────────────────────────────────────────
# DATABASE_URL must be set, e.g.:
# export DATABASE_URL="postgres://user:pass@localhost:5432/taskflow?sslmode=disable"
# migrate applies all pending SQL migrations.
migrate:
@if [ -z "$$DATABASE_URL" ]; then \
echo "ERROR: DATABASE_URL is not set"; \
exit 1; \
fi
@for f in migrations/*.sql; do \
echo "Running $$f..."; \
psql "$$DATABASE_URL" -f "$$f" -q 2>&1 | grep -v "NOTICE:\|already exists"; \
done
@echo "Migrations complete ✓"
# db-status checks if PostgreSQL is reachable and tables exist.
db-status:
@if [ -z "$$DATABASE_URL" ]; then \
echo "DATABASE_URL not set — using in-memory storage"; \
exit 0; \
fi
@echo "Testing PostgreSQL connection..."
@psql "$$DATABASE_URL" -c "SELECT COUNT(*) AS task_count FROM tasks" -q 2>&1 || \
echo "⚠️ Could not connect (run 'make migrate' first)"
# ── Tools ──────────────────────────────────────────────────────
# sign-payload generates a valid x402 PAYMENT-SIGNATURE header
# using a freshly generated ECDSA key. Output includes the sender
# address, the base64-encoded header value, and ready-to-use curl
# commands.
sign-payload:
$(GO) run $(GOFLAGS) scripts/sign_payload.go
# ── Run ────────────────────────────────────────────────────────
run:
PORT=$(PORT) $(GO) run $(GOFLAGS) .
run-pg:
DATABASE_URL=$(DATABASE_URL) PORT=$(PORT) $(GO) run $(GOFLAGS) .
run-binary:
PORT=$(PORT) ./$(BINARY)
# ── Docker ─────────────────────────────────────────────────────
# Start PostgreSQL + the app with hot-reload.
dc-up:
docker compose up -d
# Start only PostgreSQL (for running the app locally with make run-pg).
dc-db:
docker compose up -d db
# View logs.
dc-logs:
docker compose logs -f
# Stop and remove containers.
dc-down:
docker compose down
# Stop and remove containers + volumes (wipes the database).
dc-down-clean:
docker compose down -v
# Build the production image.
dc-build:
docker compose build app
# Run the production stack.
dc-prod:
docker compose up -d app
# ── Clean ──────────────────────────────────────────────────────
clean:
rm -f $(BINARY)
rm -rf dist/