[VOL-5026] - Build and (pre-) deploy repo:voltha-go
Makefile
--------
o Refactor test and mod-* targets per voltha-openolt-adatpter/Makefile.
o Logic moved into makefiles/analysis/{coverage,sca}.mk
o Inline ( set -euo pipefail && cmd | tee log) in test-coverage.
o Improve error handling, "cmd | tee" will silently mask shell exit status.
o make test failing locally (docker image: cpu profile acces denied).
o Local problem, send a job through jenkins for accurate status.
makefiles/
----------
o Copy in library makefiles
o Esp docker/include.mk
compose/*/*.yaml
----------------
o Update copyright notice
db/*/*.go
rw_core/*/*.go
--------------
o Run gofmt -s -w on source to fix latent linting problmes that fail jobs.
Change-Id: If7cd349822edd0e604ac4daf27d315f528c6bcf6
diff --git a/makefiles/analysis/coverage.mk b/makefiles/analysis/coverage.mk
new file mode 100644
index 0000000..2505c65
--- /dev/null
+++ b/makefiles/analysis/coverage.mk
@@ -0,0 +1,117 @@
+# -*- makefile -*-
+# -----------------------------------------------------------------------
+# Copyright 2016-2023 Open Networking Foundation (ONF) and the ONF Contributors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# -----------------------------------------------------------------------
+
+$(if $(DEBUG),$(warning ENTER))
+
+# tests-dir := ./tests/results
+# tests-coverage := $(tests-dir)/go-test-coverage
+# tests-results := $(tests-dir)/go-test-results
+
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
+test-coverage-init:
+ $(RM) -r tests/results
+ @mkdir -p ./tests/results
+
+ # Chicken-n-egg problem: See Dockerfile.rw_core
+ # required by testing
+ # does not exist during build
+ @touch ./tests/results/go-test-coverage.out
+
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
+test-coverage: test-coverage-init
+
+ $(call banner-enter,$@)
+
+ $(RM) -r tests/results
+ @mkdir -p ./tests/results
+ @touch $(tests-coverage).out
+
+ @$(if $(LOCAL_FIX_PERMS),chmod 777 tests/results)
+
+ $(HIDE) $(MAKE) --no-print-directory test-go-coverage
+ $(HIDE) $(MAKE) --no-print-directory test-junit
+ $(HIDE) $(MAKE) --no-print-directory test-cobertura
+
+ @$(if $(LOCAL_FIX_PERMS),chmod 775 tests/results) # yes this may not run
+
+ $(call banner-leave,$@)
+
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
+test-go-coverage:
+ $(call banner-enter,$@)
+ @$(if $(LOCAL_FIX_PERMS),chmod 777 tests/results)
+
+ # Cannot simply tee output else go exit status lost
+ (\
+ set -euo pipefail\
+ && ${GO} test -mod=vendor -v -coverprofile "./tests/results/go-test-coverage.out" -covermode count ./... 2>&1\
+) | tee ./tests/results/go-test-results.out
+
+ @$(if $(LOCAL_FIX_PERMS),chmod 775 tests/results)
+ $(call banner-leave,$@)
+
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
+test-junit:
+ $(call banner-enter,$@)
+ @$(if $(LOCAL_FIX_PERMS),chmod 777 tests/results)
+
+ ${GO_JUNIT_REPORT} \
+ < ./tests/results/go-test-results.out \
+ > ./tests/results/go-test-results.xml
+
+ @$(if $(LOCAL_FIX_PERMS),chmod 775 tests/results)
+ $(call banner-leave,$@)
+
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
+test-cobertura:
+ $(call banner-enter,$@)
+ @$(if $(LOCAL_FIX_PERMS),chmod 777 tests/results)
+
+ ${GOCOVER_COBERTURA} \
+ < ./tests/results/go-test-coverage.out \
+ > ./tests/results/go-test-coverage.xml
+
+ @$(if $(LOCAL_FIX_PERMS),chmod 775 tests/results)
+ $(call banner-leave,$@)
+
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
+help ::
+ @echo '[TEST: coverage]'
+ @echo ' coverage Generate test coverage reports'
+ @echo ' test-go-coverage Generate a coverage report for vendor/'
+ @echo ' test-junit Digest go coverage, generate junit'
+ @echo ' test-cobertura Digest coverage and junit reports'
+
+
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
+clean-coverage :
+ $(RM) -r ./tests/results
+
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
+clean :: clean-coverage
+
+$(if $(DEBUG),$(warning LEAVE))
+
+# [EOF]
diff --git a/makefiles/analysis/include.mk b/makefiles/analysis/include.mk
new file mode 100644
index 0000000..f6e6a78
--- /dev/null
+++ b/makefiles/analysis/include.mk
@@ -0,0 +1,28 @@
+# -*- makefile -*-
+# -----------------------------------------------------------------------
+# Copyright 2016-2023 Open Networking Foundation (ONF) and the ONF Contributors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# SPDX-FileCopyrightText: 2016-2023 Open Networking Foundation (ONF) and the ONF Contributors
+# SPDX-License-Identifier: Apache-2.0
+# -----------------------------------------------------------------------
+
+$(if $(DEBUG),$(warning ENTER))
+
+include $(MAKEDIR)/analysis/sca.mk
+include $(MAKEDIR)/analysis/coverage.mk
+
+$(if $(DEBUG),$(warning LEAVE))
+
+# [EOF]
diff --git a/makefiles/analysis/sca.mk b/makefiles/analysis/sca.mk
new file mode 100644
index 0000000..19d7f91
--- /dev/null
+++ b/makefiles/analysis/sca.mk
@@ -0,0 +1,52 @@
+# -*- makefile -*-
+# -----------------------------------------------------------------------
+# Copyright 2016-2023 Open Networking Foundation (ONF) and the ONF Contributors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# -----------------------------------------------------------------------
+
+$(if $(DEBUG),$(warning ENTER))
+
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
+sca:
+ $(call banner-enter,$@)
+
+ @$(RM) -r ./sca-report
+ @mkdir -p ./sca-report
+ @echo "Running static code analysis..."
+ @${GOLANGCI_LINT} run --deadline=6m --out-format junit-xml ./... \
+ | tee ./sca-report/sca-report.xml
+ @echo ""
+ @echo "Static code analysis OK"
+
+ $(call banner-leave,$@)
+
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
+clean-sca :
+ @$(RM) -r ./sca-report
+ $(RM) ./sca-report/sca-report.xml
+
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
+clean :: clean-sca
+
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
+help ::
+ @echo ' sca Runs static code analysis with the golangci-lint tool'
+
+$(if $(DEBUG),$(warning LEAVE))
+
+# [EOF]