[VOL-5285] - JJB Upgrade toward v5

Makefile
--------
  o Added a repository makefile with convenience targets (make test)

chart_version_check.sh
-----------------------------------
  o Copyright notice updated to onf v1.1
  o More temp filename filtering added.
  o Improve reporting for a cryptic error source.
  o Version diffs rely on simple string comparison which can be
    confused by composite charts like voltha-infra/ and voltha-stack/
    when multiple chart versions are modified.
  o Yaml parsing needed for a real fix, in the interim identify the
    problem and display strings that contributed to detection.

chart_version_check/filter_files.sh
-----------------------------------
  o Added helper library filter_files().
  o Given a list of files return the list with garbage removed.

test/bats/chart_version_check.sh
--------------------------------
  o Added a bats unit test for filter_files().

Change-Id: I8d724579976adf62d47786fcad16d21d0759a5ab
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..53ca588
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,54 @@
+# -*- makefile -*-
+# -----------------------------------------------------------------------
+# Copyright 2024 Open Networking Foundation 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: 2024 Open Networking Foundation Contributors
+# SPDX-License-Identifier: Apache-2.0
+# -----------------------------------------------------------------------
+
+.DEFAULT_GOAL := help
+
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
+all :
+
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
+test ::
+  ifdef BATS
+	$(MAKE) -C test/bats $@
+  endif
+
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
+clean ::
+
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
+sterile :: clean
+
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
+help ::
+	@echo 'Usage: $(MAKE) [options] [target] ...'
+
+	@printf '  %-33.33s %s\n' 'test' 'Run available test suites'
+	@printf '  %-33.33s %s\n' '  BATS=1' 'Launch bats test suites (WIP)'
+
+	@printf '\n[CLEAN]\n'
+	@printf '  %-33.33s %s\n' 'clean'   'Remove makefile generated targets'
+	@printf '  %-33.33s %s\n' 'sterile' 'Revert sandbox to a pristine state'
+
+# [EOF]
diff --git a/chart_version_check.sh b/chart_version_check.sh
index cccd183..1d1b33c 100755
--- a/chart_version_check.sh
+++ b/chart_version_check.sh
@@ -1,19 +1,23 @@
 #!/usr/bin/env bash
-# ---------------------------------------------------------------------------
-# Copyright 2018-2024 Open Networking Foundation (ONF) and the ONF Contributors
+# -----------------------------------------------------------------------
+# Copyright 2018-2024 Open Networking Foundation 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
+# 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 WARRANTIESS OR CONDITIONS OF ANY KIND, either express or implied.
+# 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: 2018-2024 Open Networking Foundation Contributors
+# SPDX-License-Identifier: Apache-2.0
+# -----------------------------------------------------------------------
+# Intent:
 # chart_version_check.sh
 # checks that changes to a chart include a change to the chart version
 # ---------------------------------------------------------------------------
@@ -30,6 +34,19 @@
 # declare -A -g ARGV=() # ARGV['debug']=1
 # declare -i -g debug=1 # uncomment to enable
 
+##--------------------##
+##---]  INCLUDES  [---##
+##--------------------##
+{
+    declare pgm
+    pgm="$(realpath "${BASH_SOURCE[0]}")"
+    declare libdir="${pgm%.sh}"
+
+    # shellcheck source=chart_version_check/filter_files.sh
+    # shellcheck disable=SC1091
+    source "$libdir/filter_files.sh"
+}
+
 ## -----------------------------------------------------------------------
 ## Intent: Display a program banner for logging
 ## -----------------------------------------------------------------------
@@ -85,6 +102,7 @@
     local -n ref=$1   ; shift
     local path="$1"   ; shift
     local branch="$1" ; shift
+
     ref=''
 
     # -----------------------------------------------------------------------
@@ -95,12 +113,37 @@
                                 | grep '^[[:blank:]]*version[[:blank:]]*:'\
         )
 
+    # -----------------------------------------------------------------------
     # Extract version string
-    if [[ ${#buffer[@]} -ne 1 ]]; then
+    # -----------------------------------------------------------------------
+    if [[ ${#buffer[@]} -gt 1 ]]; then
+        cat <<EOM
+
+** -----------------------------------------------------------------------
+**     IAM: ${BASH_SOURCE[0]} (LINENO: ${LINENO})
+**   CHART: $path
+** WARNING: Unable to identify chart version, multiple strings detected.
+**        : Consider updating the lint tool to be aware of Chart.yaml
+**        : record syntax so versions can be extracted for comparison.
+** -----------------------------------------------------------------------
+EOM
+        ## c_v_c.sh needs to be aware of Chart.yaml record syntax
+        ## so a version can be targeted.
+
+        # shellcheck disable=SC1003 
+        declare -p buffer \
+            | tr '"' '\n' \
+            | grep '\.' \
+            | sed -e 's/^[[:blank:]]*//' \
+            | awk -F'\\' '{print "    "$1}' \
+            | sort -nr
+        echo
+
+        ref='' # Highly forgiving (display only)
+    elif [[ ${#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]}"
@@ -283,6 +326,7 @@
 {
     declare -n varname="$1"; shift
     readarray -t varname < <(find . -name 'Chart.yaml' -print)
+    filter_files varname
 
     local idx
     for (( idx=0; idx<${#varname[@]}; idx++ ));
@@ -325,7 +369,7 @@
     for val in "${varname[@]}";
     do
         case "$val" in
-            */Chart.yaml) ;; # special case
+            *'/Chart.yaml')            ;; # special case
             "${dir}"*) found+=("$val") ;;
         esac
     done
@@ -360,9 +404,11 @@
     [[ -v debug ]] && declare -p charts
 
     readarray -t changes_remote < <(git diff --name-only "$branch")
+    filter_files changes_remote
     [[ -v debug ]] && declare -p changes_remote
 
     readarray -t untracked_files < <(git ls-files -o --exclude-standard)
+    filter_files untracked_files
     [[ -v debug ]] && declare -p untracked_files
 
     return
diff --git a/chart_version_check/filter_files.sh b/chart_version_check/filter_files.sh
new file mode 100644
index 0000000..390e78c
--- /dev/null
+++ b/chart_version_check/filter_files.sh
@@ -0,0 +1,62 @@
+#!/usr/bin/env bash
+# -----------------------------------------------------------------------
+# Copyright 2017-2024 Open Networking Foundation 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: 2017-2024 Open Networking Foundation Contributors
+# SPDX-License-Identifier: Apache-2.0
+# -----------------------------------------------------------------------
+
+# -----------------------------------------------------------------------
+# Intent: This function will remove junk files (editor temp files, etc)
+#         from a given list of files.
+# -----------------------------------------------------------------------
+function filter_files()
+{
+    local -n ref=$1; shift
+    [[ ${#ref[@]} -eq 0 ]] && { return; }
+
+    local -a fyls=("${ref[@]}")
+    ref=()
+
+    ## ------------------------------------------------------
+    ## Iterate by index to avoid whitespace filename problems
+    ## ------------------------------------------------------
+    local max=$((${#fyls[@]} - 1))
+    local idx
+    for idx in $(seq 0 $max);
+    do
+        local val="${fyls[$idx]}"
+        local tmp="${val//[[:blank:]]}"
+        if [[ ${#tmp} -eq 0 ]]; then
+            continue
+        fi
+
+        case "$val" in
+
+            # Skip editor temp files
+            *'#'*) continue ;;
+            *'~') continue  ;;
+
+            # Else gather for processing
+            *) ref+=("$val") ;;
+        esac
+    done
+
+    return
+}
+
+# : # ($?==0) for source $script
+
+# [EOF]
diff --git a/test/bats/chart_version_check.bats b/test/bats/chart_version_check.bats
new file mode 100755
index 0000000..3731018
--- /dev/null
+++ b/test/bats/chart_version_check.bats
@@ -0,0 +1,93 @@
+#!/usr/bin/env bats
+# -----------------------------------------------------------------------
+# Copyright 2024 Open Networking Foundation 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: 2024 Open Networking Foundation Contributors
+# SPDX-License-Identifier: Apache-2.0
+# -----------------------------------------------------------------------
+
+bats_require_minimum_version 1.5.0
+
+# This runs before each of the following tests are executed.
+setup() {
+    source '../../chart_version_check/filter_files.sh'
+}
+
+## -----------------------------------------------------------------------
+## Intent: Validate the filter_files function
+## -----------------------------------------------------------------------
+@test 'Validate filter_files()' {
+
+    local -a good=() # control
+    good+=('bar.c')
+    good+=('tans.c')
+
+    local -a bad=() # garbage
+    bad+=('bar.c~')
+    bad+=('.#bar.c')
+    bad+=('#bar.c#')
+
+    ## Generate a list of files and paths to filter
+    local -a src=()
+    for dir in '' 'foo/';
+    do
+        for fyl in "${good[@]}" "${bad[@]}";
+        do
+            src+=("${dir}${fyl}")
+        done
+    done
+
+    local -a got=("${src[@]}")
+
+    # Run is quarky, test ($?==0) and set -e
+    if false; then
+        run ! filter_files got
+    else
+        filter_files got
+        local status=$?
+        [ $status -eq 0 ]
+    fi
+
+    ## -----------------------------------------
+    ## Compare by size, filtered list is smaller
+    ## -----------------------------------------
+    [ ${#src[@]} -eq 10 ]
+    [ ${#got[@]} -eq 4 ]
+
+    ## -----------------------------------------
+    ## Also sanity check strings since we are
+    ## not (yet) comparing list contents.
+    ## -----------------------------------------
+    [[ ! "${got[*]}" == *'#'* ]]
+    [[ ! "${got[*]}" == *'~'* ]]
+
+    local val
+
+    ## Verify control values were not filtered
+    for val in "${good[@]}";
+    do
+        [[ "${src[*]}" == *"$val"* ]]
+        [[ "${got[*]}" == *"$val"* ]]
+    done
+
+    ## Verify garbage exists and was filtered
+    for val in "${bad[@]}";
+    do
+        [[ "${src[*]}" == *"$val"* ]]
+        [[ ! "${got[*]}" == *"$val"* ]]
+    done
+}
+
+# [EOF]
diff --git a/test/bats/makefile b/test/bats/makefile
new file mode 100644
index 0000000..2951c00
--- /dev/null
+++ b/test/bats/makefile
@@ -0,0 +1,68 @@
+# -*- makefile -*-
+# -----------------------------------------------------------------------
+# Copyright 2024 Open Networking Foundation 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: 2024 Open Networking Foundation Contributors
+# SPDX-License-Identifier: Apache-2.0
+# -----------------------------------------------------------------------
+# Intent: This test suite will validate repo:helm-repo-tools scripts
+# -----------------------------------------------------------------------
+
+null	:=#
+space	:=$(null) $(null)
+HIDE	?= @
+
+src = $(wildcard *.bats)
+bats := $(subst .bats,$(null),$(src))
+.PHONY: $(bats)
+
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
+all:
+
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
+test : bats
+
+bats : $(bats)
+
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
+$(bats) :
+	$(HIDE)./$@.bats
+
+## -----------------------------------------------------------------------
+## Intent: Display target help
+## -----------------------------------------------------------------------
+help ::
+	@echo 'Usage: $(MAKE) [options] [target] ...'
+	@printf '  %-33.33s %s\n' 'test' 'Launch available test suites'
+	@printf '  %-33.33s %s\n' 'bats' 'Launch available bats test suites'
+
+	@echo
+	@echo '[TEST: by name]'
+	@$(MAKE) --no-print-directory help-bats
+
+	@echo
+	@echo '[HELP]'
+	@printf '  %-33.33s %s\n' 'help'      'Display target usage'
+	@printf '  %-33.33s %s\n' 'help-bats' 'Display a list of test suites'
+
+help-bats := $(addprefix help--,$(bats))
+help-bats : $(help-bats)
+$(help-bats) :
+	@printf '  $(MAKE) %-33.33s %s\n' "$(lastword $(subst -,$(space),$@))" ''
+
+# [EOF]