Skip to content

Commit a89443e

Browse files
authored
chore: standardize cache variables (#287)
1 parent 78b56fa commit a89443e

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

helm-git-plugin.sh

+14-6
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,16 @@ readonly git_quiet
4242
export TMPDIR="${TMPDIR:-/tmp}"
4343

4444
# Cache repos or charts depending on the cache path existing in the environment variables
45-
CACHE_REPOS=$([ -n "${HELM_GIT_REPO_CACHE:-}" ] && echo "true" || echo "false")
46-
CACHE_CHARTS=$([ -n "${HELM_GIT_CHART_CACHE:-}" ] && echo "true" || echo "false")
45+
cache_repos_enabled=0
46+
if [ -n "${HELM_GIT_REPO_CACHE:-}" ]; then
47+
cache_repos_enabled=1
48+
fi
49+
readonly cache_repos_enabled
50+
cache_charts_enabled=0
51+
if [ -n "${HELM_GIT_CHART_CACHE:-}" ]; then
52+
cache_charts_enabled=1
53+
fi
54+
readonly cache_charts_enabled
4755

4856
## Tooling
4957

@@ -151,7 +159,7 @@ git_checkout() {
151159
_git_ref=$4
152160
_git_path=$5
153161

154-
if $CACHE_REPOS; then
162+
if [ "$cache_repos_enabled" = 1 ]; then
155163
_intercepted_repo=$(git_cache_intercept "${_git_repo}" "${_git_ref}") && _git_repo="${_intercepted_repo}"
156164
fi
157165

@@ -372,7 +380,7 @@ main() {
372380
readonly helm_repo_uri="git+${git_repo}@${helm_dir}?ref=${git_ref}&sparse=${git_sparse}&depupdate=${helm_depupdate}&package=${helm_package}"
373381
trace "helm_repo_uri: $helm_repo_uri"
374382

375-
if ${CACHE_CHARTS}; then
383+
if [ "$cache_charts_enabled" = 1 ]; then
376384
_request_hash=$(echo "${_raw_uri}" | md5sum | cut -d " " -f1)
377385

378386
_cache_folder="${HELM_GIT_CHART_CACHE}/${_request_hash}"
@@ -392,7 +400,7 @@ main() {
392400
# shellcheck disable=SC2317
393401
cleanup() {
394402
rm -rf "$git_root_path" "${helm_home_target_path:-}"
395-
${CACHE_CHARTS} || rm -rf "${helm_target_path:-}"
403+
[ "$cache_charts_enabled" = 1 ] || rm -rf "${helm_target_path:-}"
396404
}
397405
trap cleanup EXIT
398406

@@ -412,7 +420,7 @@ main() {
412420
return
413421
fi
414422

415-
if ${CACHE_CHARTS}; then
423+
if [ "$cache_charts_enabled" = 1 ]; then
416424
helm_target_path="${_cache_folder}"
417425
else
418426
helm_target_path="$(mktemp -d "$TMPDIR/helm-git.XXXXXX")"

0 commit comments

Comments
 (0)