-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
95 lines (76 loc) · 4.19 KB
/
Makefile
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
BINPATH ?= build
GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
WHITE := $(shell tput -Txterm setaf 7)
CYAN := $(shell tput -Txterm setaf 6)
RESET := $(shell tput -Txterm sgr0)
BUILD_TIME=$(shell date +%s)
GIT_COMMIT=$(shell git rev-parse HEAD)
VERSION ?= $(shell git tag --points-at HEAD | grep ^v | head -n 1)
LOCAL_DP_RENDERER_IN_USE = $(shell grep -c "\"github.com/ONSdigital/dp-renderer/v2\" =" go.mod)
SERVICE_PATH = github.com/ONSdigital/dp-frontend-release-calendar/service
LDFLAGS = -ldflags "-X $(SERVICE_PATH).BuildTime=$(BUILD_TIME) -X $(SERVICE_PATH).GitCommit=$(GIT_COMMIT) -X $(SERVICE_PATH).Version=$(VERSION)"
.PHONY: all
all: delimiter-AUDIT audit delimiter-LINTERS lint delimiter-UNIT-TESTS test delimiter-COMPONENT-TESTS test-component delimiter-FINISH ## Runs multiple targets, audit, lint, test and test-component
.PHONY: audit
audit: ## Runs checks for security vulnerabilities on dependencies (including transient ones)
go list -json -m all | nancy sleuth
.PHONY: build
build: generate-prod ## Builds binary of application code and stores in bin directory as dp-frontend-release-calendar
go build -tags 'production' $(LDFLAGS) -o $(BINPATH)/dp-frontend-release-calendar
.PHONY: convey
convey: ## Runs unit test suite and outputs results on http://127.0.0.1:8080/
goconvey ./...
.PHONY: delimiter-%
delimiter-%:
@echo '===================${GREEN} $* ${RESET}==================='
.PHONY: debug
debug: generate-debug ## Used to build and run code locally in debug mode
go build -tags 'debug' $(LDFLAGS) -o $(BINPATH)/dp-frontend-release-calendar
HUMAN_LOG=1 DEBUG=1 $(BINPATH)/dp-frontend-release-calendar
.PHONY: fmt
fmt: ## Run Go formatting on code
go fmt ./...
.PHONY: lint
lint: ## Used in ci to run linters against Go code
cp assets/assets.go assets/assets.go.bak
echo 'func Asset(_ string) ([]byte, error) { return nil, nil }' >> assets/assets.go
echo 'func AssetNames() []string { return []string{} }' >> assets/assets.go
gofmt -w assets/assets.go
golangci-lint run ./... || { echo "Linting failed, restoring original assets.go"; mv assets/assets.go.bak assets/assets.go; exit 1; }
mv assets/assets.go.bak assets/assets.go
.PHONY: test
test: generate-prod ## Runs unit tests including checks for race conditions and returns coverage
go test -count=1 -race -cover -tags 'production' ./...
.PHONY: test-component
test-component: generate-prod ## Runs component test suite
go test -cover -tags 'production' -coverpkg=github.com/ONSdigital/dp-frontend-release-calendar/... -component
.PHONY: generate-debug
generate-debug: fetch-renderer-lib
cd assets; go run github.com/kevinburke/go-bindata/go-bindata -prefix $(CORE_ASSETS_PATH)/assets -debug -o data.go -pkg assets locales/... templates/... $(CORE_ASSETS_PATH)/assets/locales/... $(CORE_ASSETS_PATH)/assets/templates/...
{ echo "// +build debug\n"; cat assets/data.go; } > assets/debug.go.new
mv assets/debug.go.new assets/data.go
.PHONY: generate-prod
generate-prod: fetch-renderer-lib
cd assets; go run github.com/kevinburke/go-bindata/go-bindata -prefix $(CORE_ASSETS_PATH)/assets -o data.go -pkg assets locales/... templates/... $(CORE_ASSETS_PATH)/assets/locales/... $(CORE_ASSETS_PATH)/assets/templates/...
{ echo "// +build production\n"; cat assets/data.go; } > assets/data.go.new
mv assets/data.go.new assets/data.go
.PHONY: fetch-dp-renderer
fetch-renderer-lib:
ifeq ($(LOCAL_DP_RENDERER_IN_USE), 1)
$(eval CORE_ASSETS_PATH = $(shell grep -w "\"github.com/ONSdigital/dp-renderer/v2\" =>" go.mod | awk -F '=> ' '{print $$2}' | tr -d '"'))
else
$(eval APP_RENDERER_VERSION=$(shell grep "github.com/ONSdigital/dp-renderer/v2" go.mod | cut -d ' ' -f2 ))
$(eval CORE_ASSETS_PATH = $(shell go get github.com/ONSdigital/dp-renderer/v2@$(APP_RENDERER_VERSION) && go list -f '{{.Dir}}' -m github.com/ONSdigital/dp-renderer/v2))
endif
.PHONY: help
help: ## Show help page for list of make targets
@echo ''
@echo 'Usage:'
@echo ' ${YELLOW}make${RESET} ${GREEN}<target>${RESET}'
@echo ''
@echo 'Targets:'
@awk 'BEGIN {FS = ":.*?## "} { \
if (/^[a-zA-Z_-]+:.*?##.*$$/) {printf " ${YELLOW}%-20s${GREEN}%s${RESET}\n", $$1, $$2} \
else if (/^## .*$$/) {printf " ${CYAN}%s${RESET}\n", substr($$1,4)} \
}' $(MAKEFILE_LIST)