[VOL-3156] Adding Makefile and tests

Change-Id: I510eb8fc9f81191333d23dd8bb80377106d1f792
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..f838eae
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,76 @@
+# Copyright 2020-present Open Networking Foundation
+#
+# 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.
+
+# Makefile for device-management-interface
+default: test
+
+# set default shell options
+SHELL = bash -e -o pipefail
+
+# tool containers
+VOLTHA_TOOLS_VERSION ?= 2.0.0
+
+PROTOC    = docker run --rm --user $$(id -u):$$(id -g) -v ${CURDIR}:/app $(shell test -t 0 && echo "-it") voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION}-protoc protoc
+PROTOC_SH = docker run --rm --user $$(id -u):$$(id -g) -v ${CURDIR}:/go/src/github.com/opencord/device-management-interface/v3 $(shell test -t 0 && echo "-it") --workdir=/go/src/github.com/opencord/device-management-interface/v3 voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION}-protoc sh -c
+GO        = docker run --rm --user $$(id -u):$$(id -g) -v ${CURDIR}:/app $(shell test -t 0 && echo "-it") -v gocache:/.cache -v gocache-${VOLTHA_TOOLS_VERSION}:/go/pkg voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION}-golang go
+
+# Function to extract the last path component from go_package line in .proto files
+define go_package_path
+$(shell grep go_package $(1) | sed -n 's/.*\/\(.*\)";/\1/p')
+endef
+
+# Variables
+PROTO_FILES := $(sort $(wildcard protos/dmi/*.proto))
+
+PROTO_GO_DEST_DIR := go
+PROTO_GO_PB:= $(foreach f, $(PROTO_FILES), $(patsubst protos/dmi/%.proto,$(PROTO_GO_DEST_DIR)/$(call go_package_path,$(f))/%.pb.go,$(f)))
+# Force pb file to be regenrated every time.  Otherwise the make process assumes generated version is still valid
+.PHONY: dmi.pb
+
+print:
+	@echo "Proto files: $(PROTO_FILES)"
+	@echo "Go PB files: $(PROTO_GO_PB)"
+
+# Generic targets
+protos: go-protos
+
+build: protos
+
+test: go-test
+
+venv_protos:
+	virtualenv -p python3 $@;\
+	source ./$@/bin/activate ; set -u ;\
+	pip install grpcio-tools googleapis-common-protos
+
+# Go targets
+go-protos: dmi.pb
+	@echo "Creating *.go.pb files"
+	@${PROTOC_SH} " \
+	  set -e -o pipefail; \
+	  for x in ${PROTO_FILES}; do \
+	    echo \$$x; \
+	    protoc --go_out=plugins=grpc:/go/src -I protos \$$x; \
+	  done"
+
+dmi.pb:
+	@echo "Creating $@"
+	@${PROTOC} -I protos \
+	  --include_imports --include_source_info \
+	  --descriptor_set_out=$@ \
+	  ${PROTO_FILES}
+
+go-test:
+	test/test-go-proto-consistency.sh
+	${GO} mod verify
diff --git a/VERSION b/VERSION
new file mode 100644
index 0000000..772a55e
--- /dev/null
+++ b/VERSION
@@ -0,0 +1 @@
+0.0.1-dev
\ No newline at end of file
diff --git a/test/test-go-proto-consistency.sh b/test/test-go-proto-consistency.sh
new file mode 100755
index 0000000..1858d51
--- /dev/null
+++ b/test/test-go-proto-consistency.sh
@@ -0,0 +1,52 @@
+#!/usr/bin/env bash
+
+# Copyright 2020-present Open Networking Foundation.
+#
+# 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.
+
+# test-go-proto-consistency.sh
+#
+# This test validates that go proto outputs are committed to git.  It does this
+# by regenerating them and validating whether git thinks they are the same. If
+# they become out of sync, there can be problems for consumers of the protos.
+
+set -eu -o pipefail
+
+git status > /dev/null
+STAGED="$(git diff-index --quiet HEAD -- || echo 'staged')"
+UNTRACKED="$(git ls-files --exclude-standard --others)"
+
+if [ "$STAGED" == "staged" ] || [ "$UNTRACKED" != "" ]; then
+    echo "Please commit or ignore local changes before executing this test"
+    git status
+    exit 1
+fi
+
+# delete and regenerate go protos
+rm -rf go/dmi.pb go/*/*.pb.go go_temp
+make go-protos
+
+# Running git status ensures correct git diff-index picks up changes
+git status > /dev/null
+STAGED_POST="$(git diff-index --quiet HEAD -- || echo "staged")"
+UNTRACKED_POST="$(git ls-files --exclude-standard --others)"
+
+if [ "$STAGED_POST" == "staged" ] || [ "$UNTRACKED_POST" != "" ] ; then
+    echo "You have go proto build outputs that are not committed."
+    echo "Check git status and commit updated files."
+    git status
+    exit 1
+else
+    echo "Test successful. All go proto build outputs are committed"
+    exit 0
+fi
\ No newline at end of file