Skip to content

Commit

Permalink
ci(release/script): avoid unbound var access
Browse files Browse the repository at this point in the history
Ensure helm dep var is set before we use it (cleanup).
Rename it to capitals to make clear its global.

Signed-off-by: Tiago Castro <tiagolobocastro@gmail.com>
  • Loading branch information
tiagolobocastro committed Apr 10, 2024
1 parent 858e066 commit 592aed7
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
CI=${CI-}

set -euo pipefail
trap 'cleanup_and_exit "$?"' EXIT

# Test if the image already exists in dockerhub
dockerhub_tag_exists() {
curl --silent -f -lSL https://hub.docker.com/v2/repositories/$1/tags/$2 1>/dev/null 2>&1
Expand All @@ -34,7 +34,7 @@ cleanup_and_exit() {
local -r status=${1}

# Remove helm subcharts, if `helm dependency update` was run.
if [ "$_helm_dependencies_updated" = "true" ]; then
if [ "$HELM_DEPS_UPDATED" = "true" ]; then
echo "Cleaning up helm chart dependencies..."
for dep_chart in "$CHART_DIR"/charts/*; do
if [ "$dep_chart" = "$CHART_DIR/charts/crds" ]; then
Expand Down Expand Up @@ -99,6 +99,9 @@ DEFAULT_BINARIES="kubectl-plugin"
BUILD_BINARIES=
BIN_TARGET_PLAT="linux-musl"
BINARY_OUT_LINK="."
# This variable will be used to flag if the helm chart dependencies have been
# been updated.
HELM_DEPS_UPDATED="false"

# Check if all needed tools are installed
curl --version >/dev/null
Expand Down Expand Up @@ -192,6 +195,8 @@ while [ "$#" -gt 0 ]; do
esac
done

trap 'cleanup_and_exit "$?"' EXIT

cd $SCRIPTDIR/..

if [ -z "$IMAGES" ]; then
Expand Down Expand Up @@ -243,9 +248,6 @@ if [ -n "$BUILD_BINARIES" ]; then
done
fi

# This variable will be used to flag if the helm chart dependencies have been
# been updated.
_helm_dependencies_updated="false"
for name in $IMAGES; do
image_basename=$($NIX_EVAL -f . images.$BUILD_TYPE.$name.imageName | xargs)
image=$image_basename
Expand All @@ -257,7 +259,7 @@ for name in $IMAGES; do
fi
fi

if [ "$_helm_dependencies_updated" = "false" ]; then
if [ "$HELM_DEPS_UPDATED" = "false" ]; then
for helm_chart_user in ${IMAGES_THAT_REQUIRE_HELM_CHART[@]}; do
if [ "$name" = "$helm_chart_user" ]; then
echo "Updating helm chart dependencies..."
Expand All @@ -276,7 +278,7 @@ for name in $IMAGES; do
done

# Set flag to true
_helm_dependencies_updated="true"
HELM_DEPS_UPDATED="true"
break
fi
done
Expand Down

0 comments on commit 592aed7

Please sign in to comment.