forked from Checkmarx/kics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
156 lines (132 loc) · 4.16 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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
########################
# GNU Makefile #
# Golang SDK required #
########################
.DEFAULT_GOAL := help
GOLINT := golangci-lint
COMMIT := $(shell git rev-parse HEAD)
VERSION := snapshot-$(shell echo ${COMMIT} | cut -c1-8)
IMAGE_TAG := dev
TARGET_BIN ?= bin/kics
CONSTANTS_PATH = github.com/Checkmarx/kics/internal/constants
.PHONY: clean
clean: ## remove files created during build
$(call print-target)
rm -rf dist
rm -rf bin
rm -rf vendor
rm -f coverage.*
rm -f cover.out
rm -rf **/*.log
.PHONY: mod-tidy
mod-tidy: ## go mod tidy - download and cleanup modules
$(call print-target)
@go mod tidy
cd tools && go mod tidy
.PHONY: vendor
vendor: ## go mod vendor - download vendor modules
$(call print-target)
@go mod vendor
.PHONY: install
install: ## go install tools
$(call print-target)
cd tools && go install $(shell cd tools && go list -f '{{ join .Imports " " }}' -tags=tools)
.PHONY: lint
lint: ## Lint the files
lint: mod-tidy
$(call print-target)
$(GOLINT) run -c .golangci.yml
.PHONY: build-all
build-all: ## go build for both kics and query builder
build-all: lint generate
$(call print-target)
@go build -o bin/ \
-ldflags "-X ${CONSTANTS_PATH}.Version=${VERSION} -X ${CONSTANTS_PATH}.SCMCommit=${COMMIT}" ./...
@mv bin/console bin/kics
.PHONY: build
build: ## go build
build: generate
$(call print-target)
@go build -o ${TARGET_BIN} -ldflags "-X ${CONSTANTS_PATH}.SCMCommit=${COMMIT} -X ${CONSTANTS_PATH}.Version=${VERSION}" \
cmd/console/main.go
.PHONY: go-clean
go-clean: ## Go clean build, test and modules caches
$(call print-target)
@go clean -r -i -cache -testcache -modcache
.PHONY: generate
generate: mod-tidy ## go generate
$(call print-target)
@go generate ./...
.PHONY: test
test-short: # Run sanity unit tests
test-short: generate
$(call print-target)
@go test -short ./...
.PHONY: test
test: ## Run all tests
test: test-cover test-e2e
$(call print-target)
.PHONY: test-race
test-race: ## Run tests with race detector
test-race: generate
$(call print-target)
@go test -race $(shell go list ./... | grep -v e2e)
.PHONY: test-cover
test-cover: ## Run tests with code coverage
test-cover: generate
$(call print-target)
@go test -covermode=atomic -v -coverprofile=coverage.out $(shell go list ./... | grep -v e2e)
.PHONY: test-coverage-report
test-coverage-report: ## Run unit tests and generate test coverage report
test-coverage-report: test-cover
@python3 .github/scripts/coverage/get-coverage.py coverage.out
@echo "Generating coverage.html"
@go tool cover -html=coverage.out -o coverage.html
.PHONY: test-e2e
test-e2e: ## Run E2E tests
test-e2e: build
$(call print-target)
E2E_KICS_BINARY=$(PWD)/bin/kics go test "github.com/Checkmarx/kics/e2e" -v
.PHONY: cover
cover: ## generate coverage report
cover: test
$(call print-target)
@go tool cover -html=coverage.out -o coverage.html
.PHONY: docker
docker: ## build docker image
$(call print-target)
@docker build --build-arg VERSION=${VERSION} --build-arg COMMIT=${COMMIT} -t "kics:${IMAGE_TAG}" .
.PHONY: docker-compose
dkr-compose: ## build docker image and runs docker-compose up
$(call print-target)
VERSION=${VERSION} COMMIT=${COMMIT} IMAGE_TAG=${IMAGE_TAG} docker-compose up --build
.PHONY: release
release: ## goreleaser --rm-dist
release: install
$(call print-target)
@goreleaser --rm-dist
.PHONY: run-local
run-local: ## run agains local kics.config
run-local: build
$(call print-target)
@./bin/kics scan --config kics.config
.PHONY: generate-queries-docs
generate-queries-docs: ## generate queries catalog md files
$(call print-target)
@pip3 install -r .github/generators/requirements.txt
@python3 -u .github/generators/docs_generator.py \
-p ./assets/queries/ \
-o ./docs/queries/ \
-f md \
-t .github/generators/templates
@echo "\033[36mQueries catalog updated\033[0m"
.PHONY: integration
integration: ## run kics against all its samples
$(call print-target)
@go run cmd/console/main.go -p assets/queries --log-level DEBUG --log-file
.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
define print-target
@printf "Executing target: \033[36m$@\033[0m\n"
endef