From dd39fb2290b3c8005779b494aa9d50d2a2e7ce57 Mon Sep 17 00:00:00 2001 From: Austin Guo Date: Fri, 26 Aug 2022 11:44:42 -0700 Subject: [PATCH] Merge pull request #1 from Affirm/fix-tgenv-install-existing Fix tgenv install existing --- libexec/tgenv-install | 17 +++- list_all_versions_offline | 161 ++++++++++++++++++++++------------- test/test_install_and_use.sh | 2 +- test/test_list.sh | 12 +-- 4 files changed, 122 insertions(+), 70 deletions(-) diff --git a/libexec/tgenv-install b/libexec/tgenv-install index 43e1cb9..e83f317 100755 --- a/libexec/tgenv-install +++ b/libexec/tgenv-install @@ -27,9 +27,22 @@ else regex="^${version_requested}$" fi +echo "${version}" +echo "${regex}" + [ -n "${version}" ] || error_and_die "Version is not specified" -version="$(tgenv-list-remote | grep -e "${regex}" | head -n 1)" -[ -n "${version}" ] || error_and_die "No versions matching '${1}' found in remote" +# if the version is already installed on this host, don't attempt to fetch remote +# just switch to this version and save an API call +dst_path="${TGENV_ROOT}/versions/${version}" +if [[ -e "${dst_path}" ]]; then + echo "Terragrunt v${version} is already installed" + tgenv-use "${version}" + exit 0 +# otherwise if the version is not already installed, find it in the remote versions and install it +else + version="$(tgenv-list-remote | grep -e "${regex}" | head -n 1)" + [ -n "${version}" ] || error_and_die "No versions matching '${1}' found in remote" +fi dst_path="${TGENV_ROOT}/versions/${version}" if [ -f "${dst_path}/terragrunt" ]; then diff --git a/list_all_versions_offline b/list_all_versions_offline index 9a624b8..860974f 100644 --- a/list_all_versions_offline +++ b/list_all_versions_offline @@ -1,61 +1,100 @@ -0.18.2 -0.13.19 -0.13.18 -0.13.17 -0.13.16 -0.13.15 -0.13.14 -0.13.13 -0.13.12 -0.13.11 -0.13.10 -0.13.9 -0.13.8 -0.13.7 -0.13.6 -0.13.5 -0.13.4 -0.13.3 -0.13.2 -0.13.1 -0.13.0 -0.12.25 -0.12.24 -0.12.23 -0.12.22 -0.12.21 -0.12.20 -0.12.19 -0.12.18 -0.12.17 -0.12.16 -0.12.15 -0.12.14 -0.12.13 -0.12.12 -0.12.11 -0.12.10 -0.12.9 -0.12.8 -0.12.7 -0.12.6 -0.12.5 -0.12.4 -0.12.3 -0.12.2 -0.12.1 -0.12.0 -0.11.1 -0.11.0 -0.10.3 -0.10.2 -0.10.1 -0.10.0 -0.9.9 -0.9.8 -0.9.7 -0.9.6 -0.9.5 -0.9.4 -0.9.3 -0.9.2 +0.38.7 +0.38.6 +0.38.5 +0.38.4 +0.38.3 +0.38.2 +0.38.1 +0.38.0 +0.37.4 +0.37.3 +0.37.2 +0.37.1 +0.37.0 +0.36.12 +0.36.11 +0.36.10 +0.36.9 +0.36.8 +0.36.7 +0.36.6 +0.36.5 +0.36.4 +0.36.3 +0.36.2 +0.36.1 +0.36.0 +0.35.20 +0.35.19 +0.35.18 +0.35.17 +0.35.16 +0.35.15 +0.35.14 +0.35.13 +0.35.12 +0.35.11 +0.35.10 +0.35.9 +0.35.8 +0.35.7 +0.35.6 +0.35.5 +0.35.4 +0.35.3 +0.35.2 +0.35.1 +0.35.0 +0.34.3 +0.34.2 +0.34.1 +0.34.0 +0.33.2 +0.33.1 +0.33.0 +0.32.6 +0.32.5 +0.32.4 +0.32.3 +0.32.2 +0.32.1 +0.32.0 +0.31.11 +0.31.10 +0.31.9 +0.31.8 +0.31.7 +0.31.6 +0.31.5 +0.31.4 +0.31.3 +0.31.2 +0.31.1 +0.31.0 +0.30.7 +0.30.6 +0.30.5 +0.30.4 +0.30.3 +0.30.2 +0.30.1 +0.30.0 +0.29.10 +0.29.9 +0.29.8 +0.29.7 +0.29.6 +0.29.5 +0.29.4 +0.29.3 +0.29.2 +0.29.1 +0.29.0 +0.28.24 +0.28.23 +0.28.22 +0.28.21 +0.28.20 +0.28.19 +0.28.18 +0.28.17 diff --git a/test/test_install_and_use.sh b/test/test_install_and_use.sh index 280e64d..7f931f5 100755 --- a/test/test_install_and_use.sh +++ b/test/test_install_and_use.sh @@ -39,7 +39,7 @@ v=$(tgenv list-remote | grep 0.11.1 | head -n 1) echo "### Install specific version" cleanup || error_and_die "Cleanup failed?!" -v=0.9.9 +v=0.35.13 ( tgenv install ${v} || exit 1 tgenv use ${v} || exit 1 diff --git a/test/test_list.sh b/test/test_list.sh index 09b5fc0..806e833 100755 --- a/test/test_list.sh +++ b/test/test_list.sh @@ -19,17 +19,17 @@ source $(dirname $0)/helpers.sh \ echo "### List local versions" cleanup || error_and_die "Cleanup failed?!" -for v in 0.12.15 0.12.9 0.11.1 0.10.0 0.9.3; do +for v in 0.35.13 0.35.14 0.35.15 0.35.16 0.35.17; do tgenv install ${v} || error_and_proceed "Install of version ${v} failed" done result=$(tgenv list) expected="$(cat << EOS -0.12.15 -0.12.9 -0.11.1 -0.10.0 -0.9.3 +0.35.17 +0.35.16 +0.35.15 +0.35.14 +0.35.13 EOS )"