Luca Prete | 1b823d6 | 2018-12-13 17:33:47 -0800 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 3 | # Copyright 2018-2024 Open Networking Foundation (ONF) and the ONF Contributors |
Luca Prete | 1b823d6 | 2018-12-13 17:33:47 -0800 | [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 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 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, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | # helmrepo.sh |
Zack Williams | 48542de | 2018-12-19 17:26:41 -0700 | [diff] [blame] | 18 | # creates or updates a helm repo for publishing on the guide website |
| 19 | # Reference: https://github.com/helm/charts/blob/master/test/repo-sync.sh |
Luca Prete | 1b823d6 | 2018-12-13 17:33:47 -0800 | [diff] [blame] | 20 | |
| 21 | set -eu -o pipefail |
| 22 | |
Joey Armstrong | e9b327e | 2023-06-22 17:09:52 -0400 | [diff] [blame] | 23 | ##-------------------## |
| 24 | ##---] GLOBALS [---## |
| 25 | ##-------------------## |
Zack Williams | 48542de | 2018-12-19 17:26:41 -0700 | [diff] [blame] | 26 | |
Luca Prete | 1b823d6 | 2018-12-13 17:33:47 -0800 | [diff] [blame] | 27 | # when not running under Jenkins, use current dir as workspace |
| 28 | WORKSPACE=${WORKSPACE:-.} |
| 29 | |
Zack Williams | 48542de | 2018-12-19 17:26:41 -0700 | [diff] [blame] | 30 | # directory to compare against, doesn't need to be present |
| 31 | OLD_REPO_DIR="${OLD_REPO_DIR:-cord-charts-repo}" |
| 32 | NEW_REPO_DIR="${NEW_REPO_DIR:-chart_repo}" |
Luca Prete | 1b823d6 | 2018-12-13 17:33:47 -0800 | [diff] [blame] | 33 | |
Luca Prete | 138c776 | 2018-12-14 14:16:14 -0800 | [diff] [blame] | 34 | PUBLISH_URL="${PUBLISH_URL:-charts.opencord.org}" |
Luca Prete | 1b823d6 | 2018-12-13 17:33:47 -0800 | [diff] [blame] | 35 | |
Joey Armstrong | e9b327e | 2023-06-22 17:09:52 -0400 | [diff] [blame] | 36 | ## ----------------------------------------------------------------------- |
| 37 | ## Intent: Dispay called function with given output |
| 38 | ## ----------------------------------------------------------------------- |
| 39 | function func_echo() |
| 40 | { |
| 41 | echo "** ${FUNCNAME[1]}: $*" |
| 42 | return |
| 43 | } |
| 44 | |
| 45 | ## ----------------------------------------------------------------------- |
| 46 | ## Intent: Display given text and exit with shell error status. |
| 47 | ## ----------------------------------------------------------------------- |
| 48 | function error() |
| 49 | { |
Joey Armstrong | 2a07964 | 2023-07-31 15:12:37 -0400 | [diff] [blame] | 50 | echo -e "** ${BASH_SOURCE[0]##*/}::${FUNCNAME[1]} ERROR: $*" |
Joey Armstrong | e9b327e | 2023-06-22 17:09:52 -0400 | [diff] [blame] | 51 | exit 1 |
| 52 | } |
| 53 | |
| 54 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 2a07964 | 2023-07-31 15:12:37 -0400 | [diff] [blame] | 55 | ## Intent: Detect pre-existing versioned packages. |
| 56 | ## ----------------------------------------------------------------------- |
| 57 | function check_packages() |
| 58 | { |
| 59 | local dir="$1"; shift |
| 60 | |
| 61 | readarray -t package_paths < <(find "${dir}" -name '*.tgz' -print) |
| 62 | declare -p package_paths |
| 63 | |
| 64 | # --------------------------------------------- |
| 65 | # Check for versioned package collision. |
| 66 | # --------------------------------------------- |
| 67 | for package_path in "${package_paths[@]}"; |
| 68 | do |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 69 | package="${package_path##*/}" # basename |
| 70 | |
| 71 | if [ -f "${OLD_REPO_DIR}/${package}" ]; then |
| 72 | echo |
| 73 | echo "PACKAGE: $package" |
| 74 | /bin/ls -l "$package_path" |
| 75 | /bin/ls -l "${OLD_REPO_DIR}/${package}" |
| 76 | error "Package: ${package} with same version already exists in ${OLD_REPO_DIR}" |
| 77 | fi |
Joey Armstrong | 2a07964 | 2023-07-31 15:12:37 -0400 | [diff] [blame] | 78 | done |
| 79 | |
| 80 | return |
| 81 | } |
| 82 | |
| 83 | ## ----------------------------------------------------------------------- |
Joey Armstrong | e9b327e | 2023-06-22 17:09:52 -0400 | [diff] [blame] | 84 | ## Intent: Gather a list of Chart.yaml files from the filesystem. |
| 85 | ## ----------------------------------------------------------------------- |
| 86 | function get_chart_yaml() |
| 87 | { |
| 88 | local dir="$1" ; shift |
| 89 | declare -n ref=$1 ; shift |
| 90 | |
| 91 | readarray -t _charts < <(find "$dir" -name Chart.yaml -print | sort) |
| 92 | ref=("${_charts[@]}") |
| 93 | return |
| 94 | } |
| 95 | |
| 96 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 2a07964 | 2023-07-31 15:12:37 -0400 | [diff] [blame] | 97 | ## Intent: Given a helm chart line extract and return *version. |
| 98 | ## ----------------------------------------------------------------------- |
| 99 | function getVersion() |
| 100 | { |
| 101 | # shellcheck disable=SC2178 |
| 102 | local -n ref=$1; shift # declare -A |
| 103 | local line="$1"; shift |
| 104 | |
| 105 | [[ -v debug ]] && func_echo "LINE: $line" |
| 106 | |
| 107 | # foo=${string#"$prefix"} |
| 108 | |
| 109 | line="${line%\#*}" # Snip comments |
| 110 | line="${line//[[:blank:]]}" # Prune whitespace |
| 111 | |
| 112 | # version : x.y.z |
| 113 | readarray -d':' -t _fields < <(printf '%s' "$line") |
| 114 | |
| 115 | local key="${_fields[0]}" |
| 116 | local val="${_fields[1]}" |
Eric Ball | 0d7a0e6 | 2024-11-14 13:07:04 -0800 | [diff] [blame] | 117 | # shellcheck disable=SC2004 |
Joey Armstrong | 2a07964 | 2023-07-31 15:12:37 -0400 | [diff] [blame] | 118 | ref[$key]="$val" |
| 119 | |
| 120 | return |
| 121 | } |
| 122 | |
| 123 | ## ----------------------------------------------------------------------- |
Joey Armstrong | e9b327e | 2023-06-22 17:09:52 -0400 | [diff] [blame] | 124 | ## Intent: Update helm package dependencies |
| 125 | ## ----------------------------------------------------------------------- |
| 126 | function helm_deps_update() |
| 127 | { |
| 128 | local dest="$1"; shift # helm --destination |
| 129 | |
| 130 | if [[ -v dry_run ]]; then |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 131 | func_echo "helm package --dependency-update --destination $dest $chartdir" |
Joey Armstrong | e9b327e | 2023-06-22 17:09:52 -0400 | [diff] [blame] | 132 | else |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 133 | helm package --dependency-update --destination "$dest" "$chartdir" |
Joey Armstrong | e9b327e | 2023-06-22 17:09:52 -0400 | [diff] [blame] | 134 | fi |
| 135 | return |
| 136 | } |
| 137 | |
| 138 | ## ----------------------------------------------------------------------- |
| 139 | ## Intent: Update helm package index |
| 140 | ## ----------------------------------------------------------------------- |
| 141 | function helm_index_publish() |
| 142 | { |
| 143 | local repo_dir="$1"; shift # helm --destination |
| 144 | |
| 145 | if [[ -v dry_run ]]; then |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 146 | func_echo "helm repo index $repo_dir --url https://${PUBLISH_URL}" |
Joey Armstrong | 2a07964 | 2023-07-31 15:12:37 -0400 | [diff] [blame] | 147 | |
| 148 | elif [[ -v no_publish ]]; then |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 149 | func_echo "[SKIP] helm publishing due to --no-publish" |
| 150 | |
Joey Armstrong | e9b327e | 2023-06-22 17:09:52 -0400 | [diff] [blame] | 151 | else |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 152 | ## ------------------------------------------------ |
| 153 | ## Helm updates are guarded by jenkins |
| 154 | ## Revision control should reinforce that assertion |
| 155 | ## ------------------------------------------------ |
| 156 | case "$USER" in |
| 157 | jenkins) |
| 158 | helm repo index "$repo_dir" --url https://"${PUBLISH_URL}" |
| 159 | ;; |
| 160 | *) |
| 161 | func_echo "[SKIP] helm publishing due to ($USER != jenkins)" |
| 162 | ;; |
| 163 | esac |
Joey Armstrong | e9b327e | 2023-06-22 17:09:52 -0400 | [diff] [blame] | 164 | fi |
Joey Armstrong | 2a07964 | 2023-07-31 15:12:37 -0400 | [diff] [blame] | 165 | |
Joey Armstrong | e9b327e | 2023-06-22 17:09:52 -0400 | [diff] [blame] | 166 | return |
| 167 | } |
| 168 | |
| 169 | ## ----------------------------------------------------------------------- |
| 170 | ## Intent: Update helm package index |
| 171 | ## ----------------------------------------------------------------------- |
| 172 | function helm_index_merge() |
| 173 | { |
| 174 | local old_repo="$1" ; shift |
| 175 | local new_repo="$1" ; shift |
| 176 | |
| 177 | declare -a cmd=() |
| 178 | cmd+=('helm' 'repo' 'index') |
| 179 | cmd+=('--url' "https://${PUBLISH_URL}") |
| 180 | cmd+=('--merge' "${old_repo}/index.yaml" "$new_repo") |
| 181 | |
| 182 | if [[ -v dry_run ]]; then |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 183 | func_echo "${cmd[@]}" |
Joey Armstrong | e9b327e | 2023-06-22 17:09:52 -0400 | [diff] [blame] | 184 | else |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 185 | "${cmd[@]}" |
Joey Armstrong | e9b327e | 2023-06-22 17:09:52 -0400 | [diff] [blame] | 186 | fi |
| 187 | return |
| 188 | } |
| 189 | |
| 190 | ## ----------------------------------------------------------------------- |
| 191 | ## Intent: Given a Chart.yaml file path return test directory where stored |
| 192 | ## ----------------------------------------------------------------------- |
| 193 | function chart_path_to_test_dir() |
| 194 | { |
| 195 | local val="$1" ; shift |
| 196 | |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 197 | # shellcheck disable=SC2178 |
| 198 | declare -n ref=$1 ; shift # indirect var |
Joey Armstrong | e9b327e | 2023-06-22 17:09:52 -0400 | [diff] [blame] | 199 | |
| 200 | val="${val%/Chart.yaml}" # dirname: prune /Chart.yaml |
| 201 | val="${val##*/}" # basename: test directory |
| 202 | |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 203 | # shellcheck disable=SC2034,SC2178 |
Joey Armstrong | e9b327e | 2023-06-22 17:09:52 -0400 | [diff] [blame] | 204 | ref="$val" # Return value to caller |
| 205 | return |
| 206 | } |
| 207 | |
| 208 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 2a07964 | 2023-07-31 15:12:37 -0400 | [diff] [blame] | 209 | ## Intent: Given Chart.yaml files create a new indexed chart repository |
Joey Armstrong | e9b327e | 2023-06-22 17:09:52 -0400 | [diff] [blame] | 210 | ## ----------------------------------------------------------------------- |
| 211 | function create_helm_repo_new() |
| 212 | { |
| 213 | local repo_dir="$1"; shift # NEW_REPO_DIR |
| 214 | local work_dir="$1"; shift # WORKSPACE |
| 215 | |
| 216 | echo "Creating new helm repo: ${repo_dir}" |
| 217 | |
| 218 | declare -a charts=() |
| 219 | get_chart_yaml "$work_dir" charts |
| 220 | |
| 221 | local chart |
| 222 | for chart in "${charts[@]}"; |
| 223 | do |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 224 | echo |
| 225 | func_echo "Chart.yaml: $chart" |
Joey Armstrong | 2a07964 | 2023-07-31 15:12:37 -0400 | [diff] [blame] | 226 | |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 227 | chartdir='' |
| 228 | chart_path_to_test_dir "$chart" chartdir |
| 229 | func_echo " Chart.dir: $chartdir" |
Joey Armstrong | 2a07964 | 2023-07-31 15:12:37 -0400 | [diff] [blame] | 230 | |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 231 | helm_deps_update "${repo_dir}" |
Joey Armstrong | e9b327e | 2023-06-22 17:09:52 -0400 | [diff] [blame] | 232 | done |
Joey Armstrong | 2a07964 | 2023-07-31 15:12:37 -0400 | [diff] [blame] | 233 | |
Joey Armstrong | e9b327e | 2023-06-22 17:09:52 -0400 | [diff] [blame] | 234 | helm_index_publish "${repo_dir}" |
Joey Armstrong | 2a07964 | 2023-07-31 15:12:37 -0400 | [diff] [blame] | 235 | |
| 236 | return |
| 237 | } |
| 238 | |
| 239 | ## ----------------------------------------------------------------------- |
| 240 | ## Intent: Compare version stings extracted from Chart.yaml delta. |
| 241 | ## o attribute version:x.y.z must be changed to enable change |
| 242 | ## detection and chart loading. |
| 243 | ## ----------------------------------------------------------------------- |
| 244 | function validate_changes() |
| 245 | { |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 246 | local chart="$1"; shift |
Joey Armstrong | 2a07964 | 2023-07-31 15:12:37 -0400 | [diff] [blame] | 247 | # shellcheck disable=SC2178 |
| 248 | local -n ref=$1; shift |
| 249 | |
| 250 | local msg |
| 251 | ## ------------------------------------------- |
| 252 | ## Validation logic: all keys collected exist |
| 253 | ## Chart version must change to enable loading |
| 254 | ## ------------------------------------------- |
| 255 | local key0 |
| 256 | for key0 in "${!ref[@]}"; |
| 257 | do |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 258 | local key="${key0:1}" |
| 259 | # shellcheck disable=SC2034 |
| 260 | local old="-${key}" |
| 261 | local new="+${key}" |
Joey Armstrong | 2a07964 | 2023-07-31 15:12:37 -0400 | [diff] [blame] | 262 | |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 263 | ## Key/val paris are diff deltas: |
| 264 | ## -version : 1.2.3 |
| 265 | ## +version : 4.5.6 |
| 266 | if [[ ! -v ref['-version'] ]]; then |
Eric Ball | ed4451c | 2024-11-13 14:57:55 -0800 | [diff] [blame] | 267 | msg='Modify version to publish chart changes' |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 268 | elif [[ ! -v ref["$new"] ]]; then |
Eric Ball | ed4451c | 2024-11-13 14:57:55 -0800 | [diff] [blame] | 269 | msg="Failed to detect +${key} change in attributes" |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 270 | else |
| 271 | continue |
| 272 | fi |
Joey Armstrong | 2a07964 | 2023-07-31 15:12:37 -0400 | [diff] [blame] | 273 | |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 274 | local -i failed=1 |
| 275 | cat <<ERR |
Joey Armstrong | 2a07964 | 2023-07-31 15:12:37 -0400 | [diff] [blame] | 276 | |
| 277 | ** ----------------------------------------------------------------------- |
| 278 | ** Chart dir: $chartdir |
| 279 | ** Chart.yml: $chart |
| 280 | ** Error: $msg |
| 281 | ** ----------------------------------------------------------------------- |
| 282 | ERR |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 283 | func_echo "$(declare -p versions | sed -e 's/\[/\n\[/g')" |
Joey Armstrong | 2a07964 | 2023-07-31 15:12:37 -0400 | [diff] [blame] | 284 | done |
| 285 | |
| 286 | if [[ -v failed ]]; then |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 287 | false |
Joey Armstrong | 2a07964 | 2023-07-31 15:12:37 -0400 | [diff] [blame] | 288 | else |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 289 | true |
Joey Armstrong | 2a07964 | 2023-07-31 15:12:37 -0400 | [diff] [blame] | 290 | fi |
| 291 | |
Joey Armstrong | e9b327e | 2023-06-22 17:09:52 -0400 | [diff] [blame] | 292 | return |
| 293 | } |
| 294 | |
| 295 | ##----------------## |
| 296 | ##---] MAIN [---## |
| 297 | ##----------------## |
| 298 | |
| 299 | while [ $# -gt 0 ]; do |
| 300 | arg="$1"; shift |
| 301 | |
| 302 | case "$arg" in |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 303 | -*debug) declare -g -i debug=1 ;; |
| 304 | -*dry*) declare -g -i dry_run=1 ;; |
| 305 | -*no-publish) declare -g -i no_publish=1 ;; |
| 306 | -*help) |
| 307 | cat <<EOH |
Joey Armstrong | e9b327e | 2023-06-22 17:09:52 -0400 | [diff] [blame] | 308 | Usage: $0 |
| 309 | --debug Enable debug mode |
| 310 | --dry-run Simulate helm calls |
| 311 | EOH |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 312 | ;; |
Joey Armstrong | 2a07964 | 2023-07-31 15:12:37 -0400 | [diff] [blame] | 313 | |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 314 | -*) echo "[SKIP] unknown switch [$arg]" ;; |
| 315 | *) echo "[SKIP] unknown argument [$arg]" ;; |
Joey Armstrong | e9b327e | 2023-06-22 17:09:52 -0400 | [diff] [blame] | 316 | esac |
| 317 | done |
| 318 | |
| 319 | |
| 320 | echo "# helmrepo.sh, using helm: $(helm version -c) #" |
| 321 | |
Zack Williams | 48542de | 2018-12-19 17:26:41 -0700 | [diff] [blame] | 322 | # create and clean NEW_REPO_DIR |
| 323 | mkdir -p "${NEW_REPO_DIR}" |
| 324 | rm -f "${NEW_REPO_DIR}"/* |
Luca Prete | 94d9519 | 2018-12-14 09:56:00 -0800 | [diff] [blame] | 325 | |
Zack Williams | 48542de | 2018-12-19 17:26:41 -0700 | [diff] [blame] | 326 | # if OLD_REPO_DIR doesn't exist, generate packages and index in NEW_REPO_DIR |
| 327 | if [ ! -d "${OLD_REPO_DIR}" ] |
| 328 | then |
Joey Armstrong | e9b327e | 2023-06-22 17:09:52 -0400 | [diff] [blame] | 329 | create_helm_repo_new "$NEW_REPO_DIR" "$WORKSPACE" |
| 330 | echo |
| 331 | echo "# helmrepo.sh Success! Generated new repo index in ${NEW_REPO_DIR}" |
Luca Prete | 1b823d6 | 2018-12-13 17:33:47 -0800 | [diff] [blame] | 332 | |
Zack Williams | 48542de | 2018-12-19 17:26:41 -0700 | [diff] [blame] | 333 | else |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 334 | # OLD_REPO_DIR exists, check for new charts and update only with changes |
| 335 | echo "Found existing helm repo: ${OLD_REPO_DIR}, attempting update" |
Luca Prete | 1b823d6 | 2018-12-13 17:33:47 -0800 | [diff] [blame] | 336 | |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 337 | # Loop and create chart packages, only if changed |
| 338 | declare -a charts=() |
| 339 | get_chart_yaml "$WORKSPACE" charts |
Joey Armstrong | e9b327e | 2023-06-22 17:09:52 -0400 | [diff] [blame] | 340 | |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 341 | for chart in "${charts[@]}"; |
| 342 | do |
| 343 | echo |
| 344 | func_echo "Chart.yaml: $chart" |
Luca Prete | 1b823d6 | 2018-12-13 17:33:47 -0800 | [diff] [blame] | 345 | |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 346 | chartdir='' |
| 347 | chart_path_to_test_dir "$chart" chartdir |
| 348 | func_echo " Chart.dir: $chartdir" |
Luca Prete | 05ba35b | 2018-12-14 11:08:12 -0800 | [diff] [blame] | 349 | |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 350 | # See if chart version changed from previous HEAD commit |
| 351 | readarray -t chart_yaml_diff < <(git diff -p HEAD^ -- "$chart") |
Joey Armstrong | 2a07964 | 2023-07-31 15:12:37 -0400 | [diff] [blame] | 352 | |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 353 | if [[ ! -v chart_yaml_diff ]]; then |
| 354 | echo "Chart unchanged, not packaging: '${chartdir}'" |
Luca Prete | 1b823d6 | 2018-12-13 17:33:47 -0800 | [diff] [blame] | 355 | |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 356 | # ------------------------------------------------------------------- |
| 357 | # Assumes that helmlint.sh and chart_version_check.sh have been run |
| 358 | # pre-merge, which ensures that all charts are valid and have their |
| 359 | # version updated in Chart.yaml |
| 360 | # ------------------------------------------------------------------- |
| 361 | elif [ ${#chart_yaml_diff} -gt 0 ]; then |
| 362 | declare -A versions=() |
| 363 | for line in "${chart_yaml_diff[@]}"; |
| 364 | do |
| 365 | [[ -v debug ]] && func_echo "$line" |
Joey Armstrong | e9b327e | 2023-06-22 17:09:52 -0400 | [diff] [blame] | 366 | |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 367 | case "$line" in |
| 368 | # appVersion: "1.0.3" |
| 369 | # version: 1.2.3 |
Eric Ball | ed4451c | 2024-11-13 14:57:55 -0800 | [diff] [blame] | 370 | [-+]*[vV]ersion*:*) getVersion versions "$line" ;; |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 371 | esac |
| 372 | done |
Joey Armstrong | e9b327e | 2023-06-22 17:09:52 -0400 | [diff] [blame] | 373 | |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 374 | # --------------------------------------------------------------- |
| 375 | # [TODO] -- versions['-version']='version string change required' |
| 376 | # --------------------------------------------------------------- |
| 377 | # version: string change initiates a delta forcing helm to update. |
| 378 | # Should it be required by every checkin ? For ex: release may |
| 379 | # accumulate several version edits then publish all when finished. |
| 380 | # |
| 381 | # Danger would be chart changes are not published/tested when |
| 382 | # a dev forgets to update the chart version string. |
| 383 | # --------------------------------------------------------------- |
Joey Armstrong | e9b327e | 2023-06-22 17:09:52 -0400 | [diff] [blame] | 384 | |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 385 | ## --------------------------------------------------------------- |
| 386 | ## Check for required version change and stray attribute deletions |
| 387 | ## We are comparing diff output [-+]verison : x.y |
| 388 | ## +{key} indicates a required attribute exists and was modified |
| 389 | ## --------------------------------------------------------------- |
| 390 | if ! validate_changes "$chart" versions; then |
| 391 | declare -g -i failed=1 |
| 392 | continue |
| 393 | fi |
Joey Armstrong | e9b327e | 2023-06-22 17:09:52 -0400 | [diff] [blame] | 394 | |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 395 | # Always query, version string may not have changed |
| 396 | readarray -t ver < <(grep -oP '(?<= version: )\S+' "$chart") |
| 397 | declare -p ver |
Joey Armstrong | 2a07964 | 2023-07-31 15:12:37 -0400 | [diff] [blame] | 398 | |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 399 | echo "Detected new version of chart ${chartdir}, creating package: ${ver[*]}" |
Joey Armstrong | 2a07964 | 2023-07-31 15:12:37 -0400 | [diff] [blame] | 400 | |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 401 | helm_deps_update "${NEW_REPO_DIR}" |
Joey Armstrong | e9b327e | 2023-06-22 17:09:52 -0400 | [diff] [blame] | 402 | |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 403 | else |
| 404 | echo "Chart unchanged, not packaging: '${chartdir}'" |
| 405 | fi |
| 406 | done |
Joey Armstrong | e9b327e | 2023-06-22 17:09:52 -0400 | [diff] [blame] | 407 | |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 408 | check_packages "$NEW_REPO_DIR" |
Zack Williams | 48542de | 2018-12-19 17:26:41 -0700 | [diff] [blame] | 409 | |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 410 | ## ----------------------------------------------------------------------- |
| 411 | ## ----------------------------------------------------------------------- |
| 412 | # only update index when new charts are added |
| 413 | if [ ${#package_paths[@]} -gt 0 ]; then |
Zack Williams | 48542de | 2018-12-19 17:26:41 -0700 | [diff] [blame] | 414 | |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 415 | # Create updated index.yaml (new version created in NEW_REPO_DIR) |
| 416 | helm_index_merge "${OLD_REPO_DIR}" "${NEW_REPO_DIR}" |
Zack Williams | 48542de | 2018-12-19 17:26:41 -0700 | [diff] [blame] | 417 | |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 418 | # move over packages and index.yaml |
| 419 | mv "${NEW_REPO_DIR}"/*.tgz "${OLD_REPO_DIR}/" |
| 420 | mv "${NEW_REPO_DIR}/index.yaml" "${OLD_REPO_DIR}/index.yaml" |
Zack Williams | 48542de | 2018-12-19 17:26:41 -0700 | [diff] [blame] | 421 | |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 422 | echo "# helmrepo.sh Success! Updated existing repo index in ${OLD_REPO_DIR}" |
Zack Williams | 2f075ea | 2019-01-03 14:20:29 -0700 | [diff] [blame] | 423 | |
Joey Armstrong | 0476e91 | 2024-02-09 16:00:26 -0500 | [diff] [blame] | 424 | else |
| 425 | echo "# helmrepo.sh Success! No new charts added." |
| 426 | fi |
Zack Williams | 48542de | 2018-12-19 17:26:41 -0700 | [diff] [blame] | 427 | fi |
| 428 | |
| 429 | exit 0 |
Joey Armstrong | 2a07964 | 2023-07-31 15:12:37 -0400 | [diff] [blame] | 430 | |
| 431 | # [EOF] |