[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]
diff --git a/makefiles/docker/include.mk b/makefiles/docker/include.mk
index a56a85f..3326b27 100644
--- a/makefiles/docker/include.mk
+++ b/makefiles/docker/include.mk
@@ -19,14 +19,12 @@
VOLTHA_TOOLS_VERSION ?= 2.4.0
-include $(MAKEDIR)/docker/versions.mk
-
# ---------------------------
# Macros: command refactoring
# ---------------------------
docker-iam ?= --user $$(id -u):$$(id -g)# # override for local use
docker-run = docker run --rm $(docker-iam)# # Docker command stem
-docker-run-is = $(docker-run) $(is-stdin) # Attach streams when interactive
+docker-run-is = $(docker-run) $(is-stdin)# # Attach streams when interactive
docker-run-app = $(docker-run-is) -v ${CURDIR}:/app# # w/filesystem mount
# -----------------------------------------------------------------------
@@ -67,6 +65,23 @@
endif
PROTOC_SH += $(vee-citools)-protoc sh -c
+# Usage: GO_JUNIT_REPORT := $(call get-docker-go-junit-repo)
+# get-docker-go-junit-repo = $(docker-run-app) $(vee-citools)-go-junit-report go-junit-report
+# GO_JUNIT_REPORT ?= $(call get-docker-go-junit-repo)
+
+# Usage: GOCOVER_COBERTURA := $(call get-docker-gocover-cobertura)
+# get-docker-gocover-cobertura = $(docker-run-app)/src/github.com/opencord/voltha-openolt-adapter $(vee-citools)-gocover-cobertura gocover-cobertura
+# GOCOVER_COBERTURA ?= $(call get-docker-gocover-cobertura)
+
+GO_JUNIT_REPORT = $(docker-run) -v ${CURDIR}:/app -i $(vee-citools)-go-junit-report go-junit-report
+GOCOVER_COBERTURA = $(docker-run) -v ${CURDIR}:/app/src/github.com/opencord/voltha-openolt-adapter -i $(vee-citools)-gocover-cobertura gocover-cobertura
+
+get-golangci-lint = $(docker-run-app) -v gocache:/.cache $(vee-golang) $(vee-citools)-golangci-lint golangci-lint
+GOLANGCI_LINT ?= $(call get-golangci-lint)
+
+get-docker-hadolint = $(docker-run-app) $(vee-citools)-hadolint hadolint
+HADOLINT ?= $(call get-docker-hadolint)
+
$(if $(DEBUG),$(warning LEAVE))
# [EOF]
diff --git a/makefiles/include.mk b/makefiles/include.mk
index 2e4af37..c82b882 100644
--- a/makefiles/include.mk
+++ b/makefiles/include.mk
@@ -32,6 +32,7 @@
onf-mk-abs ?= $(abspath $(lastword $(MAKEFILE_LIST)))
onf-mk-top := $(subst /include.mk,$(null),$(onf-mk-abs))
ONF_MAKEDIR := $(onf-mk-top)
+MAKEDIR := $(ONF_MAKEDIR)
include $(ONF_MAKEDIR)/consts.mk
include $(ONF_MAKEDIR)/help/include.mk # render target help
@@ -49,7 +50,7 @@
##---------------------##
##---] ON_DEMAND [---##
##---------------------##
-$(if $(USE_DOCKER_MK),$(eval $(ONF_MAKEDIR)/docker/include.mk))
+$(if $(USE_DOCKER_MK),$(eval include $(ONF_MAKEDIR)/docker/include.mk))
##-------------------##
##---] TARGETS [---##
diff --git a/makefiles/lint/include.mk b/makefiles/lint/include.mk
index 95059fe..17efafa 100644
--- a/makefiles/lint/include.mk
+++ b/makefiles/lint/include.mk
@@ -1,6 +1,6 @@
# -*- makefile -*-
# -----------------------------------------------------------------------
-# Copyright 2022 Open Networking Foundation (ONF) and the ONF Contributors
+# Copyright 2012-2023 Open Networking Foundation (ONF) and the ONF Contributors
# -----------------------------------------------------------------------
# https://gerrit.opencord.org/plugins/gitiles/onf-make
# ONF.makefile.version = 1.1
diff --git a/makefiles/python/include.mk b/makefiles/python/include.mk
index 70b5ca1..f46aea0 100644
--- a/makefiles/python/include.mk
+++ b/makefiles/python/include.mk
@@ -1,6 +1,6 @@
# -*- makefile -*-
# -----------------------------------------------------------------------
-# Copyright 2022 Open Networking Foundation (ONF) and the ONF Contributors
+# Copyright 2022-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.
@@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-# SPDX-FileCopyrightText: 2022 Open Networking Foundation (ONF) and the ONF Contributors
+# SPDX-FileCopyrightText: 2022-2023 Open Networking Foundation (ONF) and the ONF Contributors
# SPDX-License-Identifier: Apache-2.0
# -----------------------------------------------------------------------
diff --git a/makefiles/python/test/include.mk b/makefiles/python/test/include.mk
index 12afc3e..026fe68 100644
--- a/makefiles/python/test/include.mk
+++ b/makefiles/python/test/include.mk
@@ -1,6 +1,6 @@
# -*- makefile -*-
# -----------------------------------------------------------------------
-# Copyright 2022 Open Networking Foundation (ONF) and the ONF Contributors
+# Copyright 2022-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.
@@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-# SPDX-FileCopyrightText: 2022 Open Networking Foundation (ONF) and the ONF Contributors
+# SPDX-FileCopyrightText: 2022-2023 Open Networking Foundation (ONF) and the ONF Contributors
# SPDX-License-Identifier: Apache-2.0
# -----------------------------------------------------------------------
diff --git a/makefiles/targets/check.mk b/makefiles/targets/check.mk
index 2145343..aa1b0d0 100644
--- a/makefiles/targets/check.mk
+++ b/makefiles/targets/check.mk
@@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-# SPDX-FileCopyrightText: 2022 Open Networking Foundation (ONF) and the ONF Contributors
+# SPDX-FileCopyrightText: 2022-2023 Open Networking Foundation (ONF) and the ONF Contributors
# SPDX-License-Identifier: Apache-2.0
# -----------------------------------------------------------------------
diff --git a/makefiles/targets/clean.mk b/makefiles/targets/clean.mk
index f504dec..f787e5c 100644
--- a/makefiles/targets/clean.mk
+++ b/makefiles/targets/clean.mk
@@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-# SPDX-FileCopyrightText: 2022 Open Networking Foundation (ONF) and the ONF Contributors
+# SPDX-FileCopyrightText: 2022-2023 Open Networking Foundation (ONF) and the ONF Contributors
# SPDX-License-Identifier: Apache-2.0
# -----------------------------------------------------------------------
diff --git a/makefiles/targets/sterile.mk b/makefiles/targets/sterile.mk
index 1eb7035..c661f53 100644
--- a/makefiles/targets/sterile.mk
+++ b/makefiles/targets/sterile.mk
@@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-# SPDX-FileCopyrightText: 2022 Open Networking Foundation (ONF) and the ONF Contributors
+# SPDX-FileCopyrightText: 2022-2023 Open Networking Foundation (ONF) and the ONF Contributors
# SPDX-License-Identifier: Apache-2.0
# -----------------------------------------------------------------------
diff --git a/makefiles/targets/test.mk b/makefiles/targets/test.mk
index d70fa4a..2f68086 100644
--- a/makefiles/targets/test.mk
+++ b/makefiles/targets/test.mk
@@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-# SPDX-FileCopyrightText: 2022 Open Networking Foundation (ONF) and the ONF Contributors
+# SPDX-FileCopyrightText: 2022-2023 Open Networking Foundation (ONF) and the ONF Contributors
# SPDX-License-Identifier: Apache-2.0
# -----------------------------------------------------------------------
diff --git a/makefiles/targets/tox.mk b/makefiles/targets/tox.mk
index b3a638b..44da921 100644
--- a/makefiles/targets/tox.mk
+++ b/makefiles/targets/tox.mk
@@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-# SPDX-FileCopyrightText: 2022 Open Networking Foundation (ONF) and the ONF Contributors
+# SPDX-FileCopyrightText: 2022-2023 Open Networking Foundation (ONF) and the ONF Contributors
# SPDX-License-Identifier: Apache-2.0
# -----------------------------------------------------------------------
diff --git a/makefiles/utils/include.mk b/makefiles/utils/include.mk
index 84f684b..5a7678f 100644
--- a/makefiles/utils/include.mk
+++ b/makefiles/utils/include.mk
@@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-# SPDX-FileCopyrightText: 2022 Open Networking Foundation (ONF) and the ONF Contributors
+# SPDX-FileCopyrightText: 2022-2023 Open Networking Foundation (ONF) and the ONF Contributors
# SPDX-License-Identifier: Apache-2.0
# -----------------------------------------------------------------------