VOL-2057 Ensure Makefile variables set correctly when tools are missing;
Add `make sca` target

Change-Id: I8d09bc6051966ed49feb4d6e782c422540dfdf97
diff --git a/Makefile b/Makefile
index 3fe545a..f92780c 100644
--- a/Makefile
+++ b/Makefile
@@ -178,18 +178,44 @@
 
 lint: lint-style lint-sanity lint-dep lint-dockerfile
 
-GO_JUNIT_REPORT:=$(shell which go-junit-report)
-GOCOVER_COBERTURA:=$(shell which gocover-cobertura)
+# Rules to automatically install golangci-lint
+GOLANGCI_LINT_TOOL?=$(shell which golangci-lint)
+ifeq (,$(GOLANGCI_LINT_TOOL))
+GOLANGCI_LINT_TOOL=$(GOPATH)/bin/golangci-lint
+golangci_lint_tool_install:
+	# Same version as installed by Jenkins ci-management
+	# Note that install using `go get` is not recommended as per https://github.com/golangci/golangci-lint
+	curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(GOPATH)/bin v1.17.0
+else
+golangci_lint_tool_install:
+endif
 
-test:
+# Rules to automatically install go-junit-report
+GO_JUNIT_REPORT?=$(shell which go-junit-report)
 ifeq (,$(GO_JUNIT_REPORT))
+GO_JUNIT_REPORT=$(GOPATH)/bin/go-junit-report
+go_junit_install:
 	go get -u github.com/jstemmer/go-junit-report
-	@GO_JUNIT_REPORT=$(GOPATH)/bin/go-junit-report
+else
+go_junit_install:
 endif
+
+# Rules to automatically install gocover-covertura
+GOCOVER_COBERTURA?=$(shell which gocover-cobertura)
 ifeq (,$(GOCOVER_COBERTURA))
-	go get -u github.com/t-yuki/gocover-cobertura
 	@GOCOVER_COBERTURA=$(GOPATH)/bin/gocover-cobertura
+gocover_cobertura_install:
+	go get -u github.com/t-yuki/gocover-cobertura
+else
+gocover_cobertura_install:
 endif
+
+sca: golangci_lint_tool_install
+	rm -rf ./sca-report
+	@mkdir -p ./sca-report
+	$(GOLANGCI_LINT_TOOL) run --out-format junit-xml ./... 2>&1 | tee ./sca-report/sca-report.xml
+
+test: go_junit_install gocover_cobertura_install
 	@mkdir -p ./tests/results
 	@go test -v -coverprofile ./tests/results/go-test-coverage.out -covermode count ./... 2>&1 | tee ./tests/results/go-test-results.out ;\
 	RETURN=$$? ;\
@@ -203,5 +229,6 @@
 
 distclean: clean
 	rm -rf ${VENVDIR}
+	rm -rf ./sca_report
 
 # end file