-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
128 lines (100 loc) · 3.77 KB
/
Makefile
File metadata and controls
128 lines (100 loc) · 3.77 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
116
117
118
119
120
121
122
123
124
125
126
127
128
PROJECT := opensight-golang-libraries
REGISTRY := docker-gps.greenbone.net
# Define submodules
PKG_DIR := pkg
.PHONY: all
all: build test
.PHONY: help
help: ## show this help.
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-30s\033[0m %s\n", $$1, $$2}'
.EXPORT_ALL_VARIABLES:
GOPRIVATE=github.com/greenbone
GOIMPORTS = go run golang.org/x/tools/cmd/goimports@latest
GOFUMPT = go run mvdan.cc/gofumpt@latest
GOLANGCI-LINT = go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
GO-MOD-OUTDATED = go run github.com/psampaz/go-mod-outdated@latest
GO-MOD-UPGRADE = go run github.com/oligot/go-mod-upgrade@latest
SWAG = github.com/swaggo/swag/cmd/swag@v1.16.2
INSTALL_GOMARKDOC = go install github.com/princjef/gomarkdoc/cmd/gomarkdoc@latest
MOCKERY = github.com/vektra/mockery/v3@v3.5.1
OS="$(shell go env var GOOS | xargs)"
ALL_GO_DIRS := $(shell find $(PKG_DIR) -name '*.go' -exec dirname {} \; | sort -u)
# Clean up
.PHONY: clean
clean:
go clean -i ./...
.PHONY: go-version
go-version: ## prints the golang version used
@ go version
.PHONY: go-mod-cleanup
go-mod-cleanup: ## cleans up the Go modules
go mod tidy && go mod download
go mod verify
.PHONY: format
format: ## format and tidy
@echo "\033[36m Format code \033[0m"
$(GOIMPORTS) -l -w .
GOFUMPT_SPLIT_LONG_LINES=on $(GOFUMPT) -l -w ./pkg
go fmt ./...
generate-code: ## create mocks and enums
@ echo "\033[36m Generate enums \033[0m"
go get github.com/abice/go-enum
go generate ./...
@ echo "\033[36m Generate mocks \033[0m"
go run $(MOCKERY) --log-level warn
.PHONY: lint
lint: format ## lint go code
$(GOLANGCI-LINT) run
.PHONY: build-common
build-common: go-version clean go-mod-cleanup lint ## execute common build tasks
.PHONY: build
build: build-common ## build go library packages
go build -trimpath ./...
.PHONY: test
test: ## run short tests
go test -short ./...
.PHONY: test-codecov
test-codecov:
go test -cover -coverprofile=cov-unit-tests.out ./...
.PHONY: start-opensearch-test-service
start-opensearch-test-service:
docker compose -f ./pkg/openSearch/ostesting/compose.yml -p opensearch-test up -d --wait --wait-timeout=120
.PHONY: stop-opensearch-test-service
stop-opensearch-test-service:
docker compose -f ./pkg/openSearch/ostesting/compose.yml -p opensearch-test down -v
.PHONY: run-opensearch-tests
run-opensearch-tests:
TEST_OPENSEARCH=1 go test ./pkg/openSearch/osquery ./pkg/openSearch/osquery -p 1 -coverprofile=cov-os-tests.out
# test-opensearch runs whole opensearch execution with docker setup and cleanup
# we want to stop-opensearch-test-service regardless of the result of run-opensearch-tests
# and return the result of run-opensearch-tests
.PHONY: test-opensearch
test-opensearch:
$(MAKE) start-opensearch-test-service
$(MAKE) run-opensearch-tests; \
status=$$?; \
$(MAKE) stop-opensearch-test-service; \
exit $$status
.PHONY: start-postgres-test-service
start-postgres-test-service:
docker compose -f ./internal/pgtesting/compose.yml -p postgres-test up -d --wait
.PHONY: stop-postgres-test-service
stop-postgres-test-service:
docker compose -f ./internal/pgtesting/compose.yml -p postgres-test down
.PHONY: run-postgres-tests
run-postgres-tests:
TEST_POSTGRES=1 go test ./pkg/postgres/query/... -coverprofile=cov-pg-tests.out
.PHONY: test-postgres
test-postgres:
$(MAKE) start-postgres-test-service
$(MAKE) run-postgres-tests; \
status=$$?; \
$(MAKE) stop-postgres-test-service; \
exit $$status
.PHONY: generate_docs
generate_docs: check_tools
gomarkdoc -e --output '{{.Dir}}/README.md' \
--exclude-dirs .,./pkg/configReader/helper,./pkg/dbcrypt/config,./pkg/openSearch/openSearchClient/config,./pkg/notifications/mocks \
./pkg/...
check_tools:
@command -v gomarkdoc >/dev/null || $(INSTALL_GOMARKDOC)