Skip to content

Commit

Permalink
Fix Helm Chart check retries (#338)
Browse files Browse the repository at this point in the history
* Fix Helm Chart check retries

* Fix arg passing
  • Loading branch information
josvazg authored Aug 1, 2024
1 parent dc92d7f commit 478332a
Showing 1 changed file with 31 additions and 16 deletions.
47 changes: 31 additions & 16 deletions .github/actions/releaser/cr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set -o nounset
set -o pipefail

mark_latest=${MARK_LATEST:-true}
skip_execution=${SKIP_EXECUTION:-false}

main() {
local version=${VERSION:-v1.2.1}
Expand Down Expand Up @@ -76,8 +77,6 @@ release_charts_inside_folders() {
check_charts_released() {
local folders=("$@")
local unreleased_charts=()
local retries=5
local delay=5

prepare_helm_repo

Expand All @@ -92,18 +91,7 @@ check_charts_released() {
chart_version=$(read_chart_version "${charts_dir}/${folder}")
echo "Checking if \"$charts_dir/$folder\" has been released to the repo"

local released=false
for ((i=0; i<retries; i++)); do
if chart_released "${chart_name}" "${chart_version}"; then
released=true
break
fi
echo "Retrying in ${delay} seconds... ($((i+1))/$retries)"
sleep "${delay}"
update_helm_repo
done

if [ "$released" = false ]; then
if ! check_chart_version_released "${chart_name}" "${chart_version}"; then
unreleased_charts+=("$chart_name")
fi
done
Expand All @@ -120,6 +108,24 @@ check_charts_released() {
fi
}

check_chart_version_released() {
local chart_name=$1
local chart_version=$2
local retries=5
local delay=1
for ((i=0; i<retries; i++)); do
if chart_released "${chart_name}" "${chart_version}"; then
return 0
fi
echo "$(date -u --iso-8601=seconds): Retrying in ${delay} seconds... ($((i+1))/$retries)"
sleep "${delay}"
delay=$((delay*2))
echo "$(date -u --iso-8601=seconds): Retrying..."
reset_helm_repo
done
return 1
}

read_chart_name() {
local chart_path=$1
awk '/^name: /{print $2}' "$chart_path/Chart.yaml"
Expand All @@ -130,6 +136,11 @@ read_chart_version() {
awk '/^version: /{print $2}' "$chart_path/Chart.yaml"
}

reset_helm_repo() {
helm repo remove mongodb
prepare_helm_repo
}

update_helm_repo(){
helm repo update mongodb
}
Expand Down Expand Up @@ -227,5 +238,9 @@ update_index() {
cr index "${args[@]}"
}

mapfile -t target< <(echo "$1" )
main "${target[@]}"
if [[ "${skip_execution}" == "true" ]]; then
echo "Skipping execution as per SKIP_EXECUTION=${skip_execution}"
else
mapfile -t target< <(echo "$1" )
main "${target[@]}"
fi

0 comments on commit 478332a

Please sign in to comment.