11#! /bin/bash
22
3- # Copyright 2024-2025 Hewlett Packard Enterprise Development LP
3+ # Copyright 2024-2026 Hewlett Packard Enterprise Development LP
44# Other additional copyright holders may be indicated within.
55#
66# The entirety of this work is licensed under the Apache License,
@@ -277,6 +277,48 @@ verify_crd_conversions() {
277277 fi
278278}
279279
280+ verify_clean_build () {
281+ local repo_url=" $1 "
282+ local default_branch=" $2 "
283+ local indent=" $3 "
284+
285+ msg " ${indent} Verifying clean build on GitHub for $default_branch ..."
286+ # shellcheck disable=SC2054
287+ local gh_cmd=(gh run list --repo " $repo_url " --branch " $default_branch " --limit 1 --json status,conclusion -q ' .[0] | {"status":.status,"conclusion":.conclusion}' )
288+ local build_json
289+ build_json=$( " ${gh_cmd[@]} " 2>&1 )
290+ if echo " $build_json " | grep -q " connection reset by peer" ; then
291+ # Retry, but only once.
292+ sleep 1
293+ build_json=$( " ${gh_cmd[@]} " 2>&1 )
294+ fi
295+ local conclusion status
296+ conclusion=$( echo " $build_json " | grep -o ' "conclusion": *"[^"]*"' | sed ' s/.*": *"\(.*\)"/\1/' )
297+ status=$( echo " $build_json " | grep -o ' "status": *"[^"]*"' | sed ' s/.*": *"\(.*\)"/\1/' )
298+ if [[ -z " $conclusion " ]]; then
299+ do_fail " ${indent} Build is not yet completed (status: $status )"
300+ fi
301+ if [[ " $conclusion " != " success" ]]; then
302+ do_fail " ${indent} Build conclusion for $default_branch : $conclusion (expected: success)"
303+ fi
304+ }
305+
306+ # A master branch should have only one chart, and it must be in the charts/
307+ # directory. The chart-releases/ directory will be present only in the release
308+ # branch.
309+ verify_master_one_chart () {
310+ local indent=" $1 "
311+
312+ if [[ -d chart-releases ]]; then
313+ do_fail " ${indent} Expected no chart-releases/ in master branch; the master branch should use charts/ for its charts."
314+ fi
315+ if [[ -d charts ]]; then
316+ if [[ $( find charts/ -maxdepth 1 -mindepth 1 -type d | wc -l | tr -d ' ' ) != 1 ]]; then
317+ do_fail " ${indent} Expected exactly one chart version in charts/ directory."
318+ fi
319+ fi
320+ }
321+
280322# Peer modules refers to the other DWS/NNF modules listed in go.mod.
281323check_peer_modules () {
282324 local indent=" $1 "
@@ -470,11 +512,35 @@ find_latest_release(){
470512 echo " $latest_tag "
471513}
472514
515+ # Update the helm chart version dir in the release branch repo, from the one
516+ # found in the master branch.
517+ update_release_helm_chart_dir () {
518+ local release_ver=" $1 "
519+ local indent=" $2 "
520+
521+ if [[ -d charts ]]; then
522+ if [[ ! -d chart-releases ]]; then
523+ mkdir chart-releases || do_fail " ${indent} Unable to create chart-releases/ directory for release branch."
524+ fi
525+ if [[ $( find chart-releases/ -maxdepth 1 -mindepth 1 -type d | wc -l) -gt 0 ]]; then
526+ git rm -rf chart-releases/* / || echo " No charts to remove"
527+ fi
528+ cp -r charts/* chart-releases/ || do_fail " ${indent} Unable to copy chart from charts/ to chart-releases/ for release branch."
529+ # Rename the chart version dir from its existing chart-releases/v* to
530+ # the new chart-releases/v$release_ver.
531+ # We let the chart version match the app version; the chart and the app
532+ # live in the same repo, so this kind of makes sense.
533+ chartvdir=$( find chart-releases -maxdepth 1 -type d -name ' v*' | head -n 1)
534+ mv " $chartvdir " " chart-releases/v$release_ver " || do_fail " ${indent} Unable to rename chart directory"
535+ fi
536+ }
537+
473538# Update versions where the release is referring to itself.
474539update_own_release_references () {
475540 local repo_short_name=" $1 "
476541 local vrelease_ver=" $2 "
477- local indent=" $3 "
542+ local branch=" $3 "
543+ local indent=" $4 "
478544 local release_ver
479545
480546 # Strip the leading 'v'.
@@ -494,11 +560,15 @@ update_own_release_references() {
494560 # This one also has a helm chart. Use `yq -i e` to do an in-place edit
495561 # with the yq that is written in Go. The yq written in Python uses
496562 # `-yi`.
497- chartvalues=" charts/lustre-csi-driver/values.yaml"
498- yq -i e -M ' (.deployment.tag) = "' " $release_ver " ' "' " $chartvalues " || do_fail " ${indent} Unable to update release version in helm chart"
499- chart=" charts/lustre-csi-driver/Chart.yaml"
500- yq -i e -M ' (.appVersion) = "' " $release_ver " ' "' " $chart " || do_fail " ${indent} Unable to update appVersion in helm chart"
501- git add " $chartvalues " " $chart "
563+ update_release_helm_chart_dir " $release_ver " " $indent "
564+ make helm-app-version CHART_DIR=chart-releases VERSION=" $release_ver " || do_fail " ${indent} Unable to update app version in helm chart"
565+ # Use the chart-releases/v* dir name as the chart version:
566+ make helm-chart-version CHART_DIR=chart-releases || do_fail " ${indent} Unable to update helm chart version"
567+ # Make the new chart package and chart repo index, so when this is
568+ # pushed, github will act like a chart repo.
569+ make helm-repackage CHART_DIR=chart-releases || do_fail " ${indent} Unable to repackage the helm chart"
570+ make helm-reindex CHART_DIR=chart-releases CHART_BRANCH=" $branch " || do_fail " ${indent} Unable to reindex the helm chart"
571+ git add chart-releases
502572 ;;
503573 lustre_fs_operator)
504574 k_yaml=" config/manager"
@@ -663,13 +733,16 @@ check_repo_master() {
663733 msg " Repo $repo_name /$default_branch :"
664734 begin_with_clean_workarea " $repo_name " " $indent "
665735
736+ verify_clean_build " $repo_url " " $default_branch " " $indent "
737+
666738 clone_checkout_fresh_workarea " $repo_name " " $repo_url " " $default_branch " " $indent "
667739
668740 if [[ $repo_short_name != nnf_deploy ]] && [[ $repo_short_name != nnf_ec ]]; then
669741 check_auto_gens " $indent "
670742 fi
671743 verify_clean_workarea " $indent "
672744 verify_crd_conversions " $indent "
745+ verify_master_one_chart " $indent "
673746
674747 check_peer_modules " $indent "
675748 verify_clean_workarea " $indent "
@@ -696,6 +769,9 @@ check_repo_release_vX() {
696769 msg " Merge default branch $default_branch "
697770 begin_with_clean_workarea " $repo_name " " $indent "
698771
772+ verify_clean_build " $repo_url " " $default_branch " " $indent "
773+ verify_clean_build " $repo_url " " $branch " " $indent "
774+
699775 clone_checkout_fresh_workarea " $repo_name " " $repo_url " " $branch " " $indent "
700776
701777 latest_release=$( git describe --match=" v*" --abbrev=0 HEAD) || do_fail " ${indent} Failure getting latest release tag."
@@ -795,7 +871,7 @@ check_repo_release_vX() {
795871
796872 if [[ $( git log --oneline " $branch ...HEAD" | wc -l) -gt 0 ]]; then
797873 # We have updates, so let's designate a new release.
798- update_own_release_references " $repo_short_name " " $new_release " " $indent "
874+ update_own_release_references " $repo_short_name " " $new_release " " $branch " " $ indent"
799875 has_changes=true
800876 else
801877 msg " ${indent} No new changes to release for $repo_name ."
0 commit comments