-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
115 lines (89 loc) · 4.05 KB
/
Makefile
File metadata and controls
115 lines (89 loc) · 4.05 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
# Copyright Manetu Inc. All Rights Reserved.
PROJECT_NAME := manetu-go-policyengine
BINARY_NAME := mpe
GO_FILES := $(shell find . -name '*.go')
OUTPUTDIR := target
DOCKER_IMAGE ?= ghcr.io/manetu/policyengine
# Version injection via ldflags
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
VERSION_PKG := github.com/manetu/policyengine/cmd/mpe/version
LDFLAGS := -ldflags "-X $(VERSION_PKG).Version=$(VERSION)"
.PHONY: lint all clean test goimports staticcheck tests sec-scan protos docker docs-lint notices-generate license-check knowledge-build knowledge-install knowledge-deploy
all: lint test test_fips race staticcheck goimports sec-scan build docs-lint
build: $(OUTPUTDIR)/$(BINARY_NAME)
$(OUTPUTDIR)/$(BINARY_NAME): $(GO_FILES) Makefile
@printf "\033[36m%-30s\033[0m %s\n" "### make $@"
@mkdir -p $(OUTPUTDIR)
@GOOS=${GOOS} GOARCH=${GOARCH} go build $(LDFLAGS) -o $@ ./cmd/mpe
docker: ## Build and publish Docker container using ko (requires DOCKER_IMAGE env var, e.g., DOCKER_IMAGE=ghcr.io/manetu/policyengine)
@printf "\033[36m%-30s\033[0m %s\n" "### make $@"
@if [ -z "$(DOCKER_IMAGE)" ]; then \
echo "Error: DOCKER_IMAGE is required (e.g., DOCKER_IMAGE=ghcr.io/manetu/policyengine)"; \
exit 1; \
fi
@./scripts/generate-notices.sh
@mkdir -p cmd/mpe/kodata
@cp NOTICES LICENSE cmd/mpe/kodata/
@KO_DOCKER_REPO=$(DOCKER_IMAGE) ko build --platform=linux/amd64,linux/arm64 --bare --push github.com/manetu/policyengine/cmd/mpe
lint: ## Lint the files
@printf "\033[36m%-30s\033[0m %s\n" "### make $@"
@golangci-lint run --timeout=5m
test: ## Run unittests
@printf "\033[36m%-30s\033[0m %s\n" "### make $@"
@go test -coverpkg=./... -cover ./...
target/cover.out:
@printf "\033[36m%-30s\033[0m %s\n" "### make $@"
@mkdir -p $(OUTPUTDIR)
@go test -v -coverpkg=./... -coverprofile $@ -cover ./...
target/cover.html: target/cover.out
@printf "\033[36m%-30s\033[0m %s\n" "### make $@"
@go tool cover -html $^ -o $@
coverage: target/cover.html
test_fips: ## Run unittests with FIPS enabled
@printf "\033[36m%-30s\033[0m %s\n" "### make $@"
@GODEBUG=fips140=only go test -cover ./...
race: ## Run data race detector
@printf "\033[36m%-30s\033[0m %s\n" "### make $@"
@go test ./... -race -short .
staticcheck: ## Run data race detector
@printf "\033[36m%-30s\033[0m %s\n" "### make $@"
@staticcheck -f stylish ./...
goimports: ## Run goimports
@printf "\033[36m%-30s\033[0m %s\n" "### make $@"
$(eval goimportsdiffs = $(shell goimports -l $(shell find . -name '*.go' | grep -v pkg/protos)))
@if [ -n "$(goimportsdiffs)" ]; then\
echo "goimports shows diffs for these files:";\
echo "$(goimportsdiffs)";\
exit 1;\
fi
protos:
@printf "\033[36m%-30s\033[0m %s\n" "### make $@"
@buf generate
knowledge-build: ## Build the knowledge artifact JAR
@$(MAKE) -f knowledge/Makefile knowledge-build
knowledge-install: ## Install knowledge JAR to ~/.m2
@$(MAKE) -f knowledge/Makefile knowledge-install
knowledge-deploy: ## Deploy knowledge JAR to GitHub Packages (CI)
@$(MAKE) -f knowledge/Makefile knowledge-deploy
clean: ## Remove previous build
@printf "\033[36m%-30s\033[0m %s\n" "### make $@"
@go clean -testcache
-@rm -rf target
-@rm NOTICES
@$(MAKE) -C docs clean
@$(MAKE) -f knowledge/Makefile knowledge-clean
sec-scan: ## Run gosec; see https://github.com/securego/gosec
@printf "\033[36m%-30s\033[0m %s\n" "### make $@"
@gosec --exclude-dir=pkg/protos ./...
docs-lint: ## Lint and build the documentation site
@printf "\033[36m%-30s\033[0m %s\n" "### make $@"
@$(MAKE) -C docs lint
help: ## Display this help screen
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
notices-generate: ## Generate NOTICES file with third-party license information (for artifact builds)
@printf "\033[36m%-30s\033[0m %s\n" "### make $@"
@./scripts/generate-notices.sh
license-check: ## Check that all dependencies use compatible licenses (MIT, BSD, Apache-2.0)
@printf "\033[36m%-30s\033[0m %s\n" "### make $@"
@go-licenses check ./...
@echo "All licenses are compatible."