forked from Checkmarx/kics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
176 lines (149 loc) · 5.06 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
########################
# 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)
LIB = $(shell pwd)/lib
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
rm -rf **/*.log
rm -f results.*
rm -rf e2e/output
.PHONY: mod-tidy
mod-tidy: ## go mod tidy - download and cleanup modules
$(call print-target)
@go mod tidy
.PHONY: vendor
vendor: ## go mod vendor - download vendor modules
$(call print-target)
@go mod vendor
.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} -X ${CONSTANTS_PATH}.BaseURL=${DESCRIPTIONS_URL}" \
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: generate-antlr
generate-antlr: ## generate parser with ANTLRv4, needs JRE (Java Runtime Environment) on the system
@cd pkg/parser/jsonfilter/ && java -jar $(LIB)/antlr-4.11.1-complete.jar -Dlanguage=Go -visitor -no-listener -o parser JSONFilter.g4
.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-unit
test-unit: ## Run unit tests
test-unit: generate
$(call print-target)
@go test $(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 -timeout 1500s
.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: dkr-build-antlr
dkr-build-antlr: ## build ANTLRv4 docker image and generate parser based on given grammar
@docker build -t antlr4-generator:dev -f ./docker/Dockerfile.antlr .
@docker run --rm -u $(id -u ${USER}):$(id -g ${USER}) -v $(pwd)/pkg/parser/jsonfilter:/work -it antlr4-generator:dev
.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
@python3 -u .github/scripts/docs-generator/query-page-generator/query-page-generator.py \
-p ./assets/queries/ \
-o ./docs/queries/ \
-f md \
--t .github/scripts/docs-generator/query-page-generator/templates/query-page-template.md \
--df
@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 scan -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