make lint-chart reporting enhancements

chart_version_check.sh
----------------------
  o shellcheck v0.9.0 cleanups
  o Rewrite empty version stirngs so they are visible in command output.
  o Added get_version_by_git so sources not showing a delta can
    have their chart version displayed during a command run.
  o Fixed a few corner cases where version string not available
    due to flow through conditoinal logic.
  o Chart modified but version unchanged error:
    - Report dir/Chart.yaml VS dir to be clear about file to edit.
    - Also report Chart.yaml version string.

todo.md
-------
  o Capture details of an error reported for future enhancement.
  o Not clear from output why an error was reported:
    + Show your work, display intermediate charts so the dependency
      chain source will be clear.

Change-Id: I49cdee1828d32d67f2efb914300308176529671c
diff --git a/chart_version_check.sh b/chart_version_check.sh
index d428473..e332ec3 100755
--- a/chart_version_check.sh
+++ b/chart_version_check.sh
@@ -55,6 +55,60 @@
 }
 
 ## -----------------------------------------------------------------------
+## Intent: Augment a version string for display.  If the given string
+##         is empty rewrite to make that detail painfully obvious.
+## -----------------------------------------------------------------------
+function version_for_display()
+{
+    local -n ref=$1; shift
+
+    if [[ ${#ref} -eq 0 ]]; then
+        ref='?????????????????' # higlight the problem for reporting
+    fi
+    return
+}
+
+## -----------------------------------------------------------------------
+## Intent: Use git commands to retrieve chart version embedded within a file
+## -----------------------------------------------------------------------
+## Given:
+##   ref     Indirect var for version string return.
+##   path    Repository path to a Chart.yaml file
+##   branch  git branch to retrieve
+##
+## Return:
+##   ref     Extracted version string
+## -----------------------------------------------------------------------
+function get_version_by_git()
+{
+    local -n ref=$1   ; shift
+    local path="$1"   ; shift
+    local branch="$1" ; shift
+    ref=''
+
+    # -----------------------------------------------------------------------
+    # cat "{branch}:{chart}" to stdout: (wanted => 'version : x.y.z')
+    # -----------------------------------------------------------------------
+    readarray -t buffer < <(\
+                            git show "${branch}:${path}" \
+                                | grep '^[[:blank:]]*version[[:blank:]]*:'\
+        )
+
+    # Extract version string
+    if [[ ${#buffer[@]} -ne 1 ]]; then
+        ref='' # Highly forgiving (display only)
+    else
+        local raw="${buffer[0]}"
+
+        # Extract value, split on whitespace, colon, comment or quote
+        readarray -t fields < <(awk -F '[[:blank:]:#"]+' '{print $2}' <<<"$raw")
+        ref="${fields[0]}"
+    fi
+
+    return
+}
+
+## -----------------------------------------------------------------------
 ## Intent: Display a log summary entry then exit with status.
 ## -----------------------------------------------------------------------
 function summary_status_with_exit()
@@ -83,7 +137,7 @@
     echo
     echo "[$status] ${program} ${summary}"
 
-    exit $exit_code
+    exit "$exit_code"
 }
 
 ## -----------------------------------------------------------------------
@@ -327,8 +381,6 @@
 do
     [[ -v debug ]] && echo -e "\nCHART: $chart"
 
-    chart_dir="${chart%/*}"
-
     ## ---------------------------
     ## Detect VERSION file changes
     ## ---------------------------
@@ -336,12 +388,18 @@
     old=''
     new=''
     if version_diff "$chart" "$COMPARISON_BRANCH" 'old' 'new'; then
+        version_for_display new
         suffix="($old => $new)" # display verion deltas in the right margin
         printf '[CHART] %-60s %s\n' "$chart" "$suffix"
         chart_modified=1
     else
+        if [[ ${#old} -eq 0 ]]; then
+            get_version_by_git old "$chart" "$COMPARISON_BRANCH"
+        fi
+        version_for_display old
         suffix="($old)"
         printf '[CHART] %s\n' "$chart"
+        new="$old"
     fi
 
     ## -----------------------------------
@@ -353,7 +411,9 @@
     if report_modified "$chart" 'combo_list';
     then
         if [ $chart_modified -eq 0 ]; then
-            error "Chart modified but version unchanged: ${chart_dir}"
+            version_for_display new
+            suffix="($old)"
+            error "Chart modified but version unchanged: ${chart} ${suffix}"
         fi
     fi
 
diff --git a/todo.md b/todo.md
new file mode 100644
index 0000000..8d4ad07
--- /dev/null
+++ b/todo.md
@@ -0,0 +1,36 @@
+# chart_version_check.md reporting enhancement
+
+## voltha/Chart.yaml
+
+- voltha-adapter-openolt/Chart.yaml version string was updated.
+- Not immediately obvious why voltha/Chart.yaml was in error.
+- Update reporting to display the dependency chain, voltha requires
+  a version bump due to voltha-infra and/or voltha-stack being updated.
+
+| Chart                  | Dependency                |
+| ---------------------- | ------------------------- |
+| voltha                 | voltha-infra voltha-stack |
+| voltha-infra           | voltha-adapter-openolt    |
+| voltha-stack           | voltha-adapter-openolt    |
+| voltha-adapter-openolt | null                      |
+    
+
+> [CHART] voltha/Chart.yaml                                            (2.12.11)
+>     Modified Files (files changed): voltha
+>         voltha-adapter-openolt/templates/_helpers.tpl
+>   voltha-adapter-openolt/templates/openolt-deploy.yaml
+>   voltha-adapter-openolt/templates/openolt-profile-svc.yaml
+>   voltha-adapter-openolt/templates/openolt-svc.yaml
+>   voltha-adapter-openolt/values.yaml
+> 
+>   Files contributing to chart delta:
+>   makefiles/lint/helm/chart.mk
+>   voltha-adapter-openolt/Chart.yaml
+>   voltha-adapter-openolt/templates/_helpers.tpl
+>   voltha-adapter-openolt/templates/openolt-deploy.yaml
+>   voltha-adapter-openolt/templates/openolt-profile-svc.yaml
+>   voltha-adapter-openolt/templates/openolt-svc.yaml
+>   voltha-adapter-openolt/values.yaml
+>   voltha-infra/Chart.yaml
+>   voltha-stack/Chart.yaml
+> [ERROR] Chart modified but version unchanged: voltha/Chart.yaml (2.12.11)