Zack Williams | 48542de | 2018-12-19 17:26:41 -0700 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Joey Armstrong | f32accb | 2024-03-07 17:05:09 -0500 | [diff] [blame] | 2 | # ----------------------------------------------------------------------- |
| 3 | # Copyright 2018-2024 Open Networking Foundation Contributors |
Zack Williams | 48542de | 2018-12-19 17:26:41 -0700 | [diff] [blame] | 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
Joey Armstrong | f32accb | 2024-03-07 17:05:09 -0500 | [diff] [blame] | 9 | # http:#www.apache.org/licenses/LICENSE-2.0 |
Zack Williams | 48542de | 2018-12-19 17:26:41 -0700 | [diff] [blame] | 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
Joey Armstrong | f32accb | 2024-03-07 17:05:09 -0500 | [diff] [blame] | 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Zack Williams | 48542de | 2018-12-19 17:26:41 -0700 | [diff] [blame] | 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
Joey Armstrong | f32accb | 2024-03-07 17:05:09 -0500 | [diff] [blame] | 16 | # ----------------------------------------------------------------------- |
| 17 | # SPDX-FileCopyrightText: 2018-2024 Open Networking Foundation Contributors |
| 18 | # SPDX-License-Identifier: Apache-2.0 |
| 19 | # ----------------------------------------------------------------------- |
| 20 | # Intent: |
Zack Williams | 48542de | 2018-12-19 17:26:41 -0700 | [diff] [blame] | 21 | # chart_version_check.sh |
| 22 | # checks that changes to a chart include a change to the chart version |
Joey Armstrong | aebf185 | 2022-12-09 08:34:13 -0500 | [diff] [blame] | 23 | # --------------------------------------------------------------------------- |
Zack Williams | 48542de | 2018-12-19 17:26:41 -0700 | [diff] [blame] | 24 | |
| 25 | set -u |
Joey Armstrong | aebf185 | 2022-12-09 08:34:13 -0500 | [diff] [blame] | 26 | # set -euo pipefail |
Zack Williams | 48542de | 2018-12-19 17:26:41 -0700 | [diff] [blame] | 27 | |
Joey Armstrong | aebf185 | 2022-12-09 08:34:13 -0500 | [diff] [blame] | 28 | ##-------------------## |
| 29 | ##---] GLOBALS [---## |
| 30 | ##-------------------## |
| 31 | declare -i -g force_fail=0 |
| 32 | declare -a -g error_stream=() |
Zack Williams | 48542de | 2018-12-19 17:26:41 -0700 | [diff] [blame] | 33 | |
Joey Armstrong | aebf185 | 2022-12-09 08:34:13 -0500 | [diff] [blame] | 34 | # declare -A -g ARGV=() # ARGV['debug']=1 |
| 35 | # declare -i -g debug=1 # uncomment to enable |
Zack Williams | 48542de | 2018-12-19 17:26:41 -0700 | [diff] [blame] | 36 | |
Joey Armstrong | f32accb | 2024-03-07 17:05:09 -0500 | [diff] [blame] | 37 | ##--------------------## |
| 38 | ##---] INCLUDES [---## |
| 39 | ##--------------------## |
| 40 | { |
| 41 | declare pgm |
| 42 | pgm="$(realpath "${BASH_SOURCE[0]}")" |
| 43 | declare libdir="${pgm%.sh}" |
| 44 | |
| 45 | # shellcheck source=chart_version_check/filter_files.sh |
| 46 | # shellcheck disable=SC1091 |
| 47 | source "$libdir/filter_files.sh" |
| 48 | } |
| 49 | |
Joey Armstrong | aebf185 | 2022-12-09 08:34:13 -0500 | [diff] [blame] | 50 | ## ----------------------------------------------------------------------- |
| 51 | ## Intent: Display a program banner for logging |
| 52 | ## ----------------------------------------------------------------------- |
| 53 | # shellcheck disable=SC2120 |
| 54 | function banner() |
| 55 | { |
| 56 | local program="${0##*/}" |
Zack Williams | 48542de | 2018-12-19 17:26:41 -0700 | [diff] [blame] | 57 | |
Joey Armstrong | aebf185 | 2022-12-09 08:34:13 -0500 | [diff] [blame] | 58 | cat <<BANNER |
Zack Williams | 48542de | 2018-12-19 17:26:41 -0700 | [diff] [blame] | 59 | |
Joey Armstrong | aebf185 | 2022-12-09 08:34:13 -0500 | [diff] [blame] | 60 | # ----------------------------------------------------------------------- |
| 61 | # Running: ${program} $@ |
| 62 | # ----------------------------------------------------------------------- |
| 63 | # Now: $(date '+%Y-%m-%d %H:%M:%S') |
| 64 | # Git: $(git --version) |
| 65 | # ----------------------------------------------------------------------- |
Joey Armstrong | b879cf8 | 2024-02-10 12:55:17 -0500 | [diff] [blame] | 66 | # WORKSPACE: $(realpath "${WORKSPACE}") |
| 67 | # WORKSPACE_BRANCH: $(git rev-parse --abbrev-ref HEAD) |
Joey Armstrong | aebf185 | 2022-12-09 08:34:13 -0500 | [diff] [blame] | 68 | # COMPARISON_BRANCH: ${COMPARISON_BRANCH} |
Joey Armstrong | aebf185 | 2022-12-09 08:34:13 -0500 | [diff] [blame] | 69 | # ----------------------------------------------------------------------- |
| 70 | BANNER |
Zack Williams | 48542de | 2018-12-19 17:26:41 -0700 | [diff] [blame] | 71 | |
Joey Armstrong | aebf185 | 2022-12-09 08:34:13 -0500 | [diff] [blame] | 72 | return |
| 73 | } |
Zack Williams | 48542de | 2018-12-19 17:26:41 -0700 | [diff] [blame] | 74 | |
Joey Armstrong | aebf185 | 2022-12-09 08:34:13 -0500 | [diff] [blame] | 75 | ## ----------------------------------------------------------------------- |
Joey Armstrong | f91c437 | 2024-02-09 16:28:02 -0500 | [diff] [blame] | 76 | ## Intent: Augment a version string for display. If the given string |
| 77 | ## is empty rewrite to make that detail painfully obvious. |
| 78 | ## ----------------------------------------------------------------------- |
| 79 | function version_for_display() |
| 80 | { |
| 81 | local -n ref=$1; shift |
| 82 | |
| 83 | if [[ ${#ref} -eq 0 ]]; then |
| 84 | ref='?????????????????' # higlight the problem for reporting |
| 85 | fi |
| 86 | return |
| 87 | } |
| 88 | |
| 89 | ## ----------------------------------------------------------------------- |
| 90 | ## Intent: Use git commands to retrieve chart version embedded within a file |
| 91 | ## ----------------------------------------------------------------------- |
| 92 | ## Given: |
| 93 | ## ref Indirect var for version string return. |
| 94 | ## path Repository path to a Chart.yaml file |
| 95 | ## branch git branch to retrieve |
| 96 | ## |
| 97 | ## Return: |
| 98 | ## ref Extracted version string |
| 99 | ## ----------------------------------------------------------------------- |
| 100 | function get_version_by_git() |
| 101 | { |
| 102 | local -n ref=$1 ; shift |
| 103 | local path="$1" ; shift |
| 104 | local branch="$1" ; shift |
Joey Armstrong | f32accb | 2024-03-07 17:05:09 -0500 | [diff] [blame] | 105 | |
Joey Armstrong | f91c437 | 2024-02-09 16:28:02 -0500 | [diff] [blame] | 106 | ref='' |
| 107 | |
| 108 | # ----------------------------------------------------------------------- |
| 109 | # cat "{branch}:{chart}" to stdout: (wanted => 'version : x.y.z') |
| 110 | # ----------------------------------------------------------------------- |
| 111 | readarray -t buffer < <(\ |
| 112 | git show "${branch}:${path}" \ |
| 113 | | grep '^[[:blank:]]*version[[:blank:]]*:'\ |
| 114 | ) |
| 115 | |
Joey Armstrong | f32accb | 2024-03-07 17:05:09 -0500 | [diff] [blame] | 116 | # ----------------------------------------------------------------------- |
Joey Armstrong | f91c437 | 2024-02-09 16:28:02 -0500 | [diff] [blame] | 117 | # Extract version string |
Joey Armstrong | f32accb | 2024-03-07 17:05:09 -0500 | [diff] [blame] | 118 | # ----------------------------------------------------------------------- |
| 119 | if [[ ${#buffer[@]} -gt 1 ]]; then |
| 120 | cat <<EOM |
| 121 | |
| 122 | ** ----------------------------------------------------------------------- |
| 123 | ** IAM: ${BASH_SOURCE[0]} (LINENO: ${LINENO}) |
| 124 | ** CHART: $path |
| 125 | ** WARNING: Unable to identify chart version, multiple strings detected. |
| 126 | ** : Consider updating the lint tool to be aware of Chart.yaml |
| 127 | ** : record syntax so versions can be extracted for comparison. |
| 128 | ** ----------------------------------------------------------------------- |
| 129 | EOM |
| 130 | ## c_v_c.sh needs to be aware of Chart.yaml record syntax |
| 131 | ## so a version can be targeted. |
| 132 | |
| 133 | # shellcheck disable=SC1003 |
| 134 | declare -p buffer \ |
| 135 | | tr '"' '\n' \ |
| 136 | | grep '\.' \ |
| 137 | | sed -e 's/^[[:blank:]]*//' \ |
| 138 | | awk -F'\\' '{print " "$1}' \ |
| 139 | | sort -nr |
| 140 | echo |
| 141 | |
| 142 | ref='' # Highly forgiving (display only) |
| 143 | elif [[ ${#buffer[@]} -ne 1 ]]; then |
Joey Armstrong | f91c437 | 2024-02-09 16:28:02 -0500 | [diff] [blame] | 144 | ref='' # Highly forgiving (display only) |
| 145 | else |
| 146 | local raw="${buffer[0]}" |
Joey Armstrong | f91c437 | 2024-02-09 16:28:02 -0500 | [diff] [blame] | 147 | # Extract value, split on whitespace, colon, comment or quote |
| 148 | readarray -t fields < <(awk -F '[[:blank:]:#"]+' '{print $2}' <<<"$raw") |
| 149 | ref="${fields[0]}" |
| 150 | fi |
| 151 | |
| 152 | return |
| 153 | } |
| 154 | |
| 155 | ## ----------------------------------------------------------------------- |
Joey Armstrong | aebf185 | 2022-12-09 08:34:13 -0500 | [diff] [blame] | 156 | ## Intent: Display a log summary entry then exit with status. |
| 157 | ## ----------------------------------------------------------------------- |
| 158 | function summary_status_with_exit() |
| 159 | { |
| 160 | local exit_code=$1; shift |
| 161 | local program="${0##*/}" |
| 162 | local summary='' |
| 163 | [[ $# -gt 0 ]] && { summary=" - $1"; shift; } |
Zack Williams | 48542de | 2018-12-19 17:26:41 -0700 | [diff] [blame] | 164 | |
Joey Armstrong | aebf185 | 2022-12-09 08:34:13 -0500 | [diff] [blame] | 165 | ## ----------------------------------- |
| 166 | ## status override courtesy of error() |
| 167 | ## ----------------------------------- |
| 168 | declare -i -g force_fail |
| 169 | if [ $force_fail -eq 1 ]; then exit_code=$force_fail; fi |
Zack Williams | 48542de | 2018-12-19 17:26:41 -0700 | [diff] [blame] | 170 | |
Joey Armstrong | aebf185 | 2022-12-09 08:34:13 -0500 | [diff] [blame] | 171 | ## -------------------------- |
| 172 | ## Set summary display string |
| 173 | ## -------------------------- |
| 174 | case "$exit_code" in |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 175 | 0) status='PASS' ;; |
| 176 | *) status='FAIL' ;; |
Joey Armstrong | aebf185 | 2022-12-09 08:34:13 -0500 | [diff] [blame] | 177 | esac |
| 178 | |
| 179 | [[ $# -gt 0 ]] && formatStream "$@" |
| 180 | |
| 181 | echo |
| 182 | echo "[$status] ${program} ${summary}" |
| 183 | |
Joey Armstrong | f91c437 | 2024-02-09 16:28:02 -0500 | [diff] [blame] | 184 | exit "$exit_code" |
Joey Armstrong | aebf185 | 2022-12-09 08:34:13 -0500 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | ## ----------------------------------------------------------------------- |
| 188 | ## Intent: Display an error and configure report summary_status as FAIL |
| 189 | ## ----------------------------------------------------------------------- |
| 190 | function error() |
| 191 | { |
| 192 | declare -i -g force_fail=1 |
| 193 | declare -a -g error_stream |
| 194 | |
| 195 | # shellcheck disable=SC2124 |
| 196 | local error="[ERROR] $@" |
| 197 | error_stream+=("$error") |
| 198 | echo "$error" |
| 199 | return |
| 200 | } |
| 201 | |
| 202 | ## ----------------------------------------------------------------------- |
| 203 | ## Intent: Given a list (header and data) format contents as a log entry |
| 204 | ## ----------------------------------------------------------------------- |
| 205 | ## Usage: displayList --banner "List of something" "${data_stream[@]}" |
| 206 | ## ----------------------------------------------------------------------- |
| 207 | function displayList() |
| 208 | { |
| 209 | local indent='' |
| 210 | while [ $# -gt 0 ]; do |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 211 | local arg="$1" |
| 212 | case "$arg" in |
| 213 | -*banner) shift; echo "$1" ;; |
| 214 | -*indent) shift; indent="$1" ;; |
| 215 | -*tab-2) echo -n ' ' ;; |
| 216 | -*tab-4) echo -n ' ' ;; |
| 217 | -*tab-6) echo -n ' ' ;; |
| 218 | -*tab-8) echo -n ' ' ;; |
| 219 | -*newline) echo; ;; |
| 220 | -*tab) echo -n ' ' ;; |
| 221 | *) break ;; |
| 222 | esac |
| 223 | shift |
Joey Armstrong | aebf185 | 2022-12-09 08:34:13 -0500 | [diff] [blame] | 224 | done |
| 225 | |
| 226 | for line in "$@"; |
| 227 | do |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 228 | echo -e " ${indent}$line" |
Joey Armstrong | aebf185 | 2022-12-09 08:34:13 -0500 | [diff] [blame] | 229 | done |
| 230 | return |
| 231 | } |
| 232 | |
| 233 | ## ----------------------------------------------------------------------- |
| 234 | ## Intent: Program init, provide defaults for globals, etc. |
| 235 | ## ----------------------------------------------------------------------- |
| 236 | function init() |
| 237 | { |
| 238 | # when not running under Jenkins, use current dir as workspace |
| 239 | # o [TODO] - Perform a secondary username check to guard against a |
| 240 | # jenkins/bash env hiccup leaving WORKSPACE= temporarily undefined. |
| 241 | WORKSPACE=${WORKSPACE:-.} |
| 242 | COMPARISON_BRANCH="${COMPARISON_BRANCH:-opencord/master}" |
| 243 | return |
| 244 | } |
| 245 | |
| 246 | ## ----------------------------------------------------------------------- |
| 247 | ## Intent: Remove quotes, whitespace & garbage from a string |
| 248 | ## ----------------------------------------------------------------------- |
| 249 | ## ..seealso: https://www.regular-expressions.info/posixbrackets.html |
| 250 | ## ----------------------------------------------------------------------- |
| 251 | function filter_codes() |
| 252 | { |
| 253 | declare -n val="$1"; shift # indirect |
| 254 | val="${val//[\"\'[:blank:][:cntrl:]]}" # [:punct:] contains hyphen |
| 255 | return |
| 256 | } |
| 257 | |
| 258 | ## ----------------------------------------------------------------------- |
| 259 | ## Intent: Detect and report VERSION file changes |
| 260 | ## ----------------------------------------------------------------------- |
| 261 | ## :param path: Path to a Chart.yaml file. |
| 262 | ## :type path: str |
| 263 | ## |
| 264 | ## :param branch: Comparsion baranch (?-remote-?) |
| 265 | ## :type branch: str |
| 266 | ## |
| 267 | ## :return: true if embedded version string was modified. |
| 268 | ## :rtype: int |
| 269 | ## ----------------------------------------------------------------------- |
| 270 | ## ..note: What about change detection for: apiVersion, appVersion (?) |
| 271 | ## ----------------------------------------------------------------------- |
| 272 | function version_diff() |
| 273 | { |
| 274 | local path="$1"; shift |
| 275 | local branch="$1"; shift |
| 276 | |
| 277 | declare -n old_var="$1"; shift # indirect |
| 278 | declare -n new_var="$1"; shift # indirect |
| 279 | |
| 280 | old_var='' |
| 281 | new_var='' |
| 282 | readarray -t delta < <(git diff -p "$branch" -- "$path") |
| 283 | |
| 284 | local modified=0 |
| 285 | if [ ${#delta[@]} -gt 0 ]; then # modified |
| 286 | |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 287 | #---------------------------------------- |
| 288 | # diff --git a/voltha-adapter-openolt/Chart.yaml [...] |
| 289 | # --- a/voltha-adapter-openolt/Chart.yaml |
| 290 | # +++ b/voltha-adapter-openolt/Chart.yaml |
| 291 | # @@ -14,7 +14,7 @@ |
| 292 | # --- |
| 293 | # -version: "2.11.3" (====> 2.11.3) |
| 294 | # +version: "2.11.8" (====> 2.11.8) |
| 295 | #---------------------------------------- |
| 296 | local line |
| 297 | for line in "${delta[@]}"; |
| 298 | do |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 299 | case "$line" in |
Eric Ball | ed4451c | 2024-11-13 14:57:55 -0800 | [diff] [blame^] | 300 | -version*:*) |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 301 | modified=1 |
Eric Ball | ed4451c | 2024-11-13 14:57:55 -0800 | [diff] [blame^] | 302 | readarray -t tmp <<< "${line#*: }" |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 303 | # shellcheck disable=SC2034 |
| 304 | old_var="${tmp[0]}" |
| 305 | filter_codes 'old_var' |
| 306 | ;; |
Eric Ball | ed4451c | 2024-11-13 14:57:55 -0800 | [diff] [blame^] | 307 | +version*:*) |
| 308 | readarray -t tmp <<< "${line#*: }" |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 309 | # shellcheck disable=SC2034 |
| 310 | new_var="${tmp[0]}" |
| 311 | filter_codes 'new_var' |
| 312 | ;; |
| 313 | esac |
| 314 | done |
Joey Armstrong | aebf185 | 2022-12-09 08:34:13 -0500 | [diff] [blame] | 315 | fi |
| 316 | |
| 317 | [ $modified -ne 0 ] # set $? for if/then/elif use: "if version_diff; then" |
| 318 | return |
| 319 | } |
| 320 | |
| 321 | ## ----------------------------------------------------------------------- |
| 322 | ## Intent: Gather a list of Chart.yaml files from the workspace. |
| 323 | ## ----------------------------------------------------------------------- |
| 324 | function gather_charts() |
| 325 | { |
| 326 | declare -n varname="$1"; shift |
| 327 | readarray -t varname < <(find . -name 'Chart.yaml' -print) |
Joey Armstrong | f32accb | 2024-03-07 17:05:09 -0500 | [diff] [blame] | 328 | filter_files varname |
Joey Armstrong | aebf185 | 2022-12-09 08:34:13 -0500 | [diff] [blame] | 329 | |
| 330 | local idx |
| 331 | for (( idx=0; idx<${#varname[@]}; idx++ )); |
| 332 | do |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 333 | local val="${varname[idx]}" |
| 334 | if [ ${#val} -lt 2 ]; then continue; fi |
Joey Armstrong | aebf185 | 2022-12-09 08:34:13 -0500 | [diff] [blame] | 335 | |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 336 | # Normalize: remove './' to support path comparison |
| 337 | if [[ "${val:0:2}" == './' ]]; then |
| 338 | varname[idx]="${val:2:${#val}}" |
| 339 | [[ -v debug ]] && echo "[$idx] ${varname[$idx]}" |
| 340 | fi |
Joey Armstrong | aebf185 | 2022-12-09 08:34:13 -0500 | [diff] [blame] | 341 | done |
| 342 | |
| 343 | [[ -v debug ]] && declare -p varname |
| 344 | return |
| 345 | } |
| 346 | |
| 347 | ## ----------------------------------------------------------------------- |
| 348 | ## Intent: Given a chart file and complete list of modified files |
| 349 | ## display a list of files modified in the chart directory. |
| 350 | ## ----------------------------------------------------------------------- |
| 351 | ## :param chart: path to a Chart.yaml file |
| 352 | ## :type chart: str |
| 353 | ## |
| 354 | ## :param varname: A list files modified in a git sandbox. |
| 355 | ## :type varname: list, indirect |
| 356 | ## ----------------------------------------------------------------------- |
| 357 | function report_modified() |
| 358 | { |
| 359 | local chart="$1"; shift |
| 360 | local dir="${chart%/*}" |
| 361 | # shellcheck disable=SC2178 |
| 362 | declare -n varname="$1"; shift |
| 363 | |
| 364 | ## --------------------------------------------- |
| 365 | ## Gather files contained in the chart directory |
| 366 | ## --------------------------------------------- |
| 367 | declare -a found=() |
| 368 | for val in "${varname[@]}"; |
| 369 | do |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 370 | case "$val" in |
Joey Armstrong | f32accb | 2024-03-07 17:05:09 -0500 | [diff] [blame] | 371 | *'/Chart.yaml') ;; # special case |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 372 | "${dir}"*) found+=("$val") ;; |
| 373 | esac |
Joey Armstrong | aebf185 | 2022-12-09 08:34:13 -0500 | [diff] [blame] | 374 | done |
| 375 | |
| 376 | ## -------------------------------------------- |
| 377 | ## Display results when modified files detected |
| 378 | ## -------------------------------------------- |
| 379 | if [ ${#found[@]} -gt 0 ]; then |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 380 | declare -a stream=() |
| 381 | stream+=('--tab-4') |
| 382 | stream+=('--banner' "Files Changed: $dir") |
| 383 | stream+=('--tab-6') # really --tab-8 |
| 384 | stream+=("${found[@]}") |
| 385 | displayList "${stream[@]}" |
Joey Armstrong | aebf185 | 2022-12-09 08:34:13 -0500 | [diff] [blame] | 386 | fi |
| 387 | |
| 388 | [ ${#found[@]} -gt 0 ] # set $? for if/else |
| 389 | return |
| 390 | } |
| 391 | |
| 392 | ## ----------------------------------------------------------------------- |
| 393 | ## Intent: Gather a list of Chart.yaml files from the workspace. |
| 394 | ## ----------------------------------------------------------------------- |
| 395 | declare -a -g charts=() |
| 396 | declare -a -g changes_remote=() |
| 397 | declare -a -g untracked_files=() |
| 398 | function gather_state() |
| 399 | { |
| 400 | local branch="$1"; shift |
| 401 | |
| 402 | gather_charts 'charts' |
| 403 | [[ -v debug ]] && declare -p charts |
| 404 | |
| 405 | readarray -t changes_remote < <(git diff --name-only "$branch") |
Joey Armstrong | f32accb | 2024-03-07 17:05:09 -0500 | [diff] [blame] | 406 | filter_files changes_remote |
Joey Armstrong | aebf185 | 2022-12-09 08:34:13 -0500 | [diff] [blame] | 407 | [[ -v debug ]] && declare -p changes_remote |
| 408 | |
| 409 | readarray -t untracked_files < <(git ls-files -o --exclude-standard) |
Joey Armstrong | f32accb | 2024-03-07 17:05:09 -0500 | [diff] [blame] | 410 | filter_files untracked_files |
Joey Armstrong | aebf185 | 2022-12-09 08:34:13 -0500 | [diff] [blame] | 411 | [[ -v debug ]] && declare -p untracked_files |
| 412 | |
| 413 | return |
| 414 | } |
| 415 | |
| 416 | # shellcheck disable=SC1073 |
| 417 | ##----------------## |
| 418 | ##---] MAIN [---## |
| 419 | ##----------------## |
| 420 | init |
| 421 | # shellcheck disable=SC2119 |
| 422 | banner |
| 423 | gather_state "$COMPARISON_BRANCH" |
| 424 | |
| 425 | chart='' |
| 426 | for chart in "${charts[@]}"; |
Zack Williams | 48542de | 2018-12-19 17:26:41 -0700 | [diff] [blame] | 427 | do |
Joey Armstrong | aebf185 | 2022-12-09 08:34:13 -0500 | [diff] [blame] | 428 | [[ -v debug ]] && echo -e "\nCHART: $chart" |
Zack Williams | 48542de | 2018-12-19 17:26:41 -0700 | [diff] [blame] | 429 | |
Joey Armstrong | aebf185 | 2022-12-09 08:34:13 -0500 | [diff] [blame] | 430 | ## --------------------------- |
| 431 | ## Detect VERSION file changes |
| 432 | ## --------------------------- |
| 433 | declare -i chart_modified=0 |
| 434 | old='' |
| 435 | new='' |
| 436 | if version_diff "$chart" "$COMPARISON_BRANCH" 'old' 'new'; then |
Joey Armstrong | f91c437 | 2024-02-09 16:28:02 -0500 | [diff] [blame] | 437 | version_for_display new |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 438 | suffix="($old => $new)" # display verion deltas in the right margin |
| 439 | printf '[CHART] %-60s %s\n' "$chart" "$suffix" |
| 440 | chart_modified=1 |
Zack Williams | 48542de | 2018-12-19 17:26:41 -0700 | [diff] [blame] | 441 | else |
Joey Armstrong | f91c437 | 2024-02-09 16:28:02 -0500 | [diff] [blame] | 442 | if [[ ${#old} -eq 0 ]]; then |
| 443 | get_version_by_git old "$chart" "$COMPARISON_BRANCH" |
| 444 | fi |
| 445 | version_for_display old |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 446 | suffix="($old)" |
| 447 | printf '[CHART] %s\n' "$chart" |
Joey Armstrong | f91c437 | 2024-02-09 16:28:02 -0500 | [diff] [blame] | 448 | new="$old" |
Zack Williams | 48542de | 2018-12-19 17:26:41 -0700 | [diff] [blame] | 449 | fi |
Zack Williams | 48542de | 2018-12-19 17:26:41 -0700 | [diff] [blame] | 450 | |
Joey Armstrong | aebf185 | 2022-12-09 08:34:13 -0500 | [diff] [blame] | 451 | ## ----------------------------------- |
| 452 | ## Report modified files for the chart |
| 453 | ## ----------------------------------- |
| 454 | declare -a combo_list=() |
| 455 | combo_list+=("${changes_remote[@]}") |
| 456 | combo_list+=("${untracked_files[@]}") |
| 457 | if report_modified "$chart" 'combo_list'; |
| 458 | then |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 459 | if [ $chart_modified -eq 0 ]; then |
Joey Armstrong | f91c437 | 2024-02-09 16:28:02 -0500 | [diff] [blame] | 460 | version_for_display new |
| 461 | suffix="($old)" |
| 462 | error "Chart modified but version unchanged: ${chart} ${suffix}" |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 463 | fi |
Joey Armstrong | aebf185 | 2022-12-09 08:34:13 -0500 | [diff] [blame] | 464 | fi |
Zack Williams | 48542de | 2018-12-19 17:26:41 -0700 | [diff] [blame] | 465 | |
Joey Armstrong | aebf185 | 2022-12-09 08:34:13 -0500 | [diff] [blame] | 466 | done |
| 467 | |
| 468 | ## --------------------------- |
| 469 | ## Report summary: local edits |
| 470 | ## --------------------------- |
Joey Armstrong | 0f8656b | 2022-12-21 11:29:36 -0500 | [diff] [blame] | 471 | if [[ -x changes_remote ]] && [ ${#changes_remote} -gt 0 ]; then # local_edits |
Joey Armstrong | aebf185 | 2022-12-09 08:34:13 -0500 | [diff] [blame] | 472 | displayList \ |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 473 | '--newline' \ |
| 474 | '--banner' 'Changed Files:' \ |
| 475 | "${changes_remote[@]}" |
Zack Williams | 48542de | 2018-12-19 17:26:41 -0700 | [diff] [blame] | 476 | fi |
| 477 | |
Joey Armstrong | aebf185 | 2022-12-09 08:34:13 -0500 | [diff] [blame] | 478 | ## ------------------------------- |
| 479 | ## Report summary: untracked files |
| 480 | ## ------------------------------- |
Joey Armstrong | b41d8cc | 2023-01-03 10:49:10 -0500 | [diff] [blame] | 481 | if [ ${#untracked_files[@]} -gt 0 ]; then |
Joey Armstrong | aebf185 | 2022-12-09 08:34:13 -0500 | [diff] [blame] | 482 | displayList \ |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 483 | '--newline' \ |
| 484 | '--banner' 'Untracked Files:' \ |
| 485 | "${untracked_files[@]}" |
Joey Armstrong | aebf185 | 2022-12-09 08:34:13 -0500 | [diff] [blame] | 486 | fi |
Zack Williams | 48542de | 2018-12-19 17:26:41 -0700 | [diff] [blame] | 487 | |
Joey Armstrong | aebf185 | 2022-12-09 08:34:13 -0500 | [diff] [blame] | 488 | ## --------------------------------- |
| 489 | ## Report summary: problems detected |
| 490 | ## --------------------------------- |
| 491 | declare -a -g error_stream |
| 492 | if [ ${#error_stream[@]} -gt 0 ]; then |
| 493 | displayList \ |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 494 | '--newline' \ |
| 495 | '--banner' 'Error Sumamry:' \ |
| 496 | "${error_stream[@]}" |
Joey Armstrong | aebf185 | 2022-12-09 08:34:13 -0500 | [diff] [blame] | 497 | fi |
Zack Williams | 48542de | 2018-12-19 17:26:41 -0700 | [diff] [blame] | 498 | |
Joey Armstrong | aebf185 | 2022-12-09 08:34:13 -0500 | [diff] [blame] | 499 | summary_status_with_exit $? |
| 500 | |
| 501 | # ----------------------------------------------------------------------- |
| 502 | # Running: chart_version_check.sh |
| 503 | # ----------------------------------------------------------------------- |
| 504 | # Now: 2022-12-09 03:10:52 |
| 505 | # Git: git version 2.34.1 |
| 506 | # ----------------------------------------------------------------------- |
| 507 | # COMPARISON_BRANCH: origin/master |
| 508 | # WORKSPACE: . |
| 509 | # ----------------------------------------------------------------------- |
| 510 | # [CHART] voltha-adapter-openolt/Chart.yaml (2.11.3 => 2.11.8) |
| 511 | # [CHART] voltha-tracing/Chart.yaml |
| 512 | # [CHART] voltha/Chart.yaml |
| 513 | # Files Changed: voltha-tracing |
| 514 | # voltha-tracing/values.yaml |
| 515 | # [ERROR] Chart modified but version unchanged: voltha-tracing |
| 516 | # [CHART] voltha/Chart.yaml |
| 517 | # ----------------------------------------------------------------------- |
| 518 | |
| 519 | # [SEE ALSO |
| 520 | # --------------------------------------------------------------------------- |
| 521 | # https://www.regular-expressions.info/posixbrackets.html (character classes) |
| 522 | # --------------------------------------------------------------------------- |