-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
88 lines (67 loc) · 2.66 KB
/
Makefile
File metadata and controls
88 lines (67 loc) · 2.66 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
# Alex Mackay 2025
# Build folder
BUILD_FOLDER = build
COVERAGE_BUILD_FOLDER ?= $(BUILD_FOLDER)/coverage
UNIT_COVERAGE_OUT ?= $(COVERAGE_BUILD_FOLDER)/ut_cov.out
BIN ?= $(BUILD_FOLDER)/checkout
# Packages
PKG ?= github.com/ATMackay/checkout
CONSTANTS_PKG ?= $(PKG)/constants
# Git based version
VERSION_TAG ?= $(shell git describe --tags)
GIT_COMMIT ?= $(shell git rev-parse HEAD)
BUILD_DATE ?= $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
COMMIT_DATE ?= $(shell TZ=UTC git show -s --format=%cd --date=format:%Y-%m-%dT%H:%M:%SZ HEAD)
ifndef DIRTY
DIRTY := $(shell if [ -n "$$(git status --porcelain 2>/dev/null)" ]; then echo true; else echo false; fi)
endif
LDFLAGS := -s -w \
-X '$(CONSTANTS_PKG).Version=$(VERSION_TAG)' \
-X '$(CONSTANTS_PKG).CommitDate=$(COMMIT_DATE)' \
-X '$(CONSTANTS_PKG).GitCommit=$(GIT_COMMIT)' \
-X '$(CONSTANTS_PKG).BuildDate=$(BUILD_DATE)' \
-X '$(CONSTANTS_PKG).Dirty=$(DIRTY)'
build:
@mkdir -p build
@echo ">> building $(BIN) (version=$(VERSION_TAG) commit=$(GIT_COMMIT) dirty=$(DIRTY))"
GO111MODULE=on go build -ldflags "$(LDFLAGS)" -o $(BIN)
@echo "Checkout server successfully built. To run the application execute './$(BIN) run'"
install: build
mv $(BIN) $(GOBIN)
run: build
@./$(BUILD_FOLDER)/checkout run --memory-db
build/coverage:
@mkdir -p $(COVERAGE_BUILD_FOLDER)
test: build/coverage
@go test -cover -coverprofile $(UNIT_COVERAGE_OUT) -v ./...
test-integration:
@echo "🧪 Running integration tests..."
@go test -v -tags=integration ./integration/... -count=1 -timeout=15m
test-coverage: test
@go tool cover -html=$(UNIT_COVERAGE_OUT)
docker:
@./build-docker.sh
@echo "To run the application execute 'docker run -p 8080:8080 -e DB_HOST=<DB_HOST> -e DB_PASSWORD=<DB_PASSWORD> checkout'"
docker-run-postgres:
@docker compose -f docker-compose.yml --profile postgres up --force-recreate
docker-run-sqlite:
@docker compose -f docker-compose.yml --profile sqlite up --force-recreate
openapi-clean:
rm -rf ./docs/openapi/*
@echo "Deleted docs/openapi/openapi.json"
swag-install:
@go install github.com/swaggo/swag/cmd/swag@latest
@echo "Installed swag"
openapi: swag-install openapi-clean
@swag init \
-g main.go \
--parseDependency --parseInternal \
-o ./docs/openapi/openapi.json \
-ot json
@echo "✅ Wrote OpenAPI to docs/openapi/openapi.json"
api-docs: openapi
@echo "✅ All docs generated."
mocks:
@go install go.uber.org/mock/mockgen@latest
@mockgen -source database/database.go -destination ./database/mock/database_mock.go -package mock database
.PHONY: build run docker test test-coverage docker-run-db swag-install openapi api-docs mocks