Skip to content

Commit 0b1055e

Browse files
committed
create makefile
Signed-off-by: Chayan Das <[email protected]>
1 parent 2a26d6c commit 0b1055e

File tree

5 files changed

+204
-13
lines changed

5 files changed

+204
-13
lines changed

.github/workflows/actions.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
with:
2424
node-version: 20
2525
cache: 'npm'
26+
cache-dependency-path: Frontend/package-lock.json
2627

2728
- name: Install Dependencies
2829
run: |
@@ -31,6 +32,7 @@ jobs:
3132
npm ci
3233
else
3334
npm i
35+
fi
3436
3537
lint:
3638
name: Lint

Backend/.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,6 @@ licenseRef.json
3232

3333
external_ref_fields.yaml
3434

35-
pkg/models/external_ref_structs.go
35+
pkg/models/external_ref_structs.go
36+
coverage.out
37+
coverage.html

Backend/pkg/models/external_ref_structs.go

Lines changed: 0 additions & 12 deletions
This file was deleted.

Frontend/.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# SPDX-FileCopyrightText: 2025 Chayan Das <[email protected]>
2+
# SPDX-License-Identifier: GPL-2.0-only
3+
4+
15
# Ignore node_modules and build files
26
node_modules/
37
dist/

makefile

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
# SPDX-FileCopyrightText: 2025 Chayan Das <[email protected]>
2+
# SPDX-License-Identifier: GPL-2.0-only
3+
4+
5+
# ==============================================================================
6+
# Makefile for KubeStellar Backend
7+
# ==============================================================================
8+
include Backend/.env
9+
10+
11+
12+
DB_URL=postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}?sslmode=disable
13+
MIGRATION_PATH=./Backend/pkg/db/migrations
14+
15+
# Declare all targets as phony (they don't create files with these names)
16+
.PHONY: help dev build test test-verbose test-coverage test-individual test-file test-func test-watch quick-test fmt lint clean deps create-migration migrate-up migrate-down migrate-force
17+
18+
# Default target - show help
19+
help:
20+
@echo "LicenseDB Backend - Available Commands"
21+
@echo "========================================"
22+
@echo ""
23+
@echo "Development Commands:"
24+
@echo " make generate - Generate Go structs from external_ref_fields.yaml"
25+
@echo " make build - Build the Go application"
26+
@echo " make run - Run backend server (go run)"
27+
@echo " make help - Display available commands (default target)"
28+
@echo ""
29+
@echo "Testing Commands:"
30+
@echo " make test - Run all API tests"
31+
@echo " make test-verbose - Run tests with verbose output"
32+
@echo " make test-coverage - Run tests with coverage report (generates coverage.html)"
33+
@echo " make test-individual - Run each test file individually"
34+
@echo " make test-file FILE=filename - Run specific test file"
35+
@echo " make test-func FUNC=TestName - Run specific test function"
36+
@echo " make test-watch - Watch mode info (not implemented - manual alternative)"
37+
@echo " make quick-test - Run subset of tests (status and logs only)"
38+
@echo ""
39+
@echo "Code Quality Commands:"
40+
@echo " make fmt - Format Go code"
41+
@echo " make lint - Run go vet linter"
42+
@echo ""
43+
@echo "Utility Commands:"
44+
@echo " make clean - Clean test cache and temporary files"
45+
@echo " make deps - Install and tidy Go dependencies"
46+
@echo ""
47+
@echo "Database Migration Commands:"
48+
@echo " make create-migration - Create a new database migration file"
49+
@echo " make migrate-up - Apply all pending database migrations"
50+
@echo " make migrate-down - Rollback last N database migrations"
51+
@echo " make migrate-force - Force a specific migration version (e.g., when tables already exist)"
52+
@echo " make migrate-version - Show the current version of the migration"
53+
54+
# ==============================================================================
55+
# Development Commands
56+
# ==============================================================================
57+
generate:
58+
cd Backend
59+
@echo "Generating Go structs from external_ref_fields.yaml..."
60+
cp Backend/external_ref_fields.example.yaml Backend/external_ref_fields.yaml
61+
@echo "Please edit external_ref_fields.yaml as needed..."
62+
vim Backend/external_ref_fields.yaml
63+
cd Backend && go generate ./...
64+
@echo "Struct generation complete"
65+
66+
67+
# Build the application
68+
build:
69+
@echo "Building Go application..."
70+
cd Backend && go build -o ./lass ./cmd/laas/main.go
71+
@echo "Build complete: Backend/lass"
72+
73+
# Run the application
74+
run:
75+
@echo "Running LicenseDB backend..."
76+
cd Backend && go run ./cmd/laas/main.go
77+
@echo "LicenseDB backend stopped"
78+
79+
# ==============================================================================
80+
# Testing Commands
81+
# ==============================================================================
82+
83+
# Run all API tests
84+
test:
85+
@echo "Running all tests..."
86+
cd Backend && go test ./... -v
87+
88+
# Run tests with verbose output
89+
test-verbose:
90+
@echo "Running tests with verbose output..."
91+
cd Backend && go test ./... -v -count=1
92+
93+
# Run tests with coverage report
94+
test-coverage:
95+
@echo "Running tests with coverage report..."
96+
cd Backend && go test ./... -coverprofile=coverage.out
97+
cd Backend && go tool cover -html=coverage.out -o coverage.html
98+
@echo "Coverage report generated: coverage.html"
99+
100+
# Run each test file individually
101+
test-individual:
102+
@echo "Running each test file individually..."
103+
@cd Backend && \
104+
for file in $$(find . -name "*_test.go" -not -path "./vendor/*"); do \
105+
echo "Testing: $$file"; \
106+
go test $$(dirname $$file) -v; \
107+
done
108+
109+
110+
# Run specific test file
111+
test-file:
112+
@if [ -z "$(FILE)" ]; then \
113+
echo "Usage: make test-file FILE=filename"; \
114+
echo "Example: make test-file FILE=auth"; \
115+
else \
116+
echo "Running tests in file: $(FILE)"; \
117+
go test ./test/$(FILE) -v; \
118+
fi
119+
120+
# Run specific test function
121+
test-func:
122+
@if [ -z "$(FUNC)" ]; then \
123+
echo "Usage: make test-func FUNC=TestName"; \
124+
echo "Example: make test-func FUNC=TestAuth"; \
125+
else \
126+
echo "Running test function: $(FUNC)"; \
127+
go test ./... -run $(FUNC) -v; \
128+
fi
129+
130+
# Watch mode info (manual alternative)
131+
test-watch:
132+
@echo "Test watch mode is not implemented."
133+
@echo "Manual alternative: Use 'air' for live reload during development"
134+
@echo "Or run: find . -name '*.go' | entr -r go test ./..."
135+
136+
# Run subset of tests (status and logs only)
137+
quick-test:
138+
@echo "Running quick tests (status and logs only)..."
139+
@if [ -d "./test/auth" ]; then go test ./test/auth -v; fi
140+
@if [ -d "./test/redis" ]; then go test ./test/redis -v; fi
141+
142+
# ==============================================================================
143+
# Code Quality Commands
144+
# ==============================================================================
145+
146+
# Format Go code
147+
fmt:
148+
@echo "Formatting Go code..."
149+
go fmt ./...
150+
@echo "Code formatting complete"
151+
152+
# Run go vet linter
153+
lint:
154+
@echo "Running go vet linter..."
155+
go vet ./...
156+
@echo "Linting complete"
157+
158+
# ==============================================================================
159+
# Utility Commands
160+
# ==============================================================================
161+
162+
# Clean test cache and temporary files
163+
clean:
164+
@echo "Cleaning test cache and temporary files..."
165+
go clean -testcache
166+
rm -rf bin
167+
rm -f coverage.out coverage.html
168+
@echo "Cleanup complete"
169+
170+
# Install and tidy Go dependencies
171+
deps:
172+
@echo "Installing and tidying Go dependencies..."
173+
go mod download
174+
go mod tidy
175+
@echo "Dependencies updated"
176+
177+
# Database Migration Commands
178+
create-migration:
179+
@read -p "Enter migration name: " name; \
180+
migrate create -ext sql -dir ${MIGRATION_PATH} -seq $${name}
181+
182+
migrate-up:
183+
@migrate -path=${MIGRATION_PATH} -database "${DB_URL}" up
184+
185+
migrate-down:
186+
@read -p "Number of migrations you want to rollback (default: 1): " NUM; \
187+
NUM=$${NUM:-1}; \
188+
migrate -path=${MIGRATION_PATH} -database "${DB_URL}" down $${NUM}
189+
190+
migrate-force:
191+
@read -p "Enter the version to force: " VERSION; \
192+
migrate -path=${MIGRATION_PATH} -database "${DB_URL}" force $${VERSION}
193+
194+
migrate-version:
195+
@migrate -path=${MIGRATION_PATH} -database "${DB_URL}" version

0 commit comments

Comments
 (0)