diff --git a/CHANGELOG.md b/CHANGELOG.md index c8fc89a0..6648199e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,6 +53,10 @@ Change line format: ## Unreleased (master) +### Fixed + +* Golang releases without patch version not being installed ; Ref: https://github.com/syndbg/goenv/pull/75 + ## 2.0.0beta8 ### Added diff --git a/plugins/go-build/bin/go-build b/plugins/go-build/bin/go-build index 9d73fdee..f6e011b1 100755 --- a/plugins/go-build/bin/go-build +++ b/plugins/go-build/bin/go-build @@ -775,6 +775,14 @@ done [ "${#ARGUMENTS[@]}" -eq 2 ] || usage 1 >&2 DEFINITION_PATH="${ARGUMENTS[0]}" + +# NOTE: Try to capture semantic versions such as `1.11` which don't have a patch version. +# A patch version of 0 will be added, e.g they'll be changed to `1.11.0`. +if grep -q -E "^[0-9]+\.[0-9]+(\s*)$" <<< ${DEFINITION_PATH}; then + DEFINITION_PATH="${DEFINITION_PATH}.0" + echo "Adding patch version 0 to ${DEFINITION_PATH}" +fi + if [ -z "$DEFINITION_PATH" ]; then usage 1 >&2 elif [ ! -f "$DEFINITION_PATH" ]; then diff --git a/plugins/go-build/bin/goenv-install b/plugins/go-build/bin/goenv-install index 1c784146..ee94dd50 100755 --- a/plugins/go-build/bin/goenv-install +++ b/plugins/go-build/bin/goenv-install @@ -120,6 +120,14 @@ unset VERSION_NAME # version is specified by goenv. Show usage instructions if a local # version is not specified. DEFINITION="${ARGUMENTS[0]}" + +# NOTE: Try to capture semantic versions such as `1.11` which don't have a patch version. +# A patch version of 0 will be added, e.g they'll be changed to `1.11.0`. +if grep -q -E "^[0-9]+\.[0-9]+(\s*)$" <<< ${DEFINITION}; then + echo "Adding patch version 0 to ${DEFINITION}" + DEFINITION="${DEFINITION}.0" +fi + [ -n "$DEFINITION" ] || DEFINITION="$(goenv-local 2>/dev/null || true)" [ -n "$DEFINITION" ] || usage 1 >&2 diff --git a/plugins/go-build/bin/goenv-uninstall b/plugins/go-build/bin/goenv-uninstall index ad7e6c6b..195e6136 100755 --- a/plugins/go-build/bin/goenv-uninstall +++ b/plugins/go-build/bin/goenv-uninstall @@ -64,6 +64,13 @@ for script in "${scripts[@]}"; do done VERSION_NAME="${DEFINITION##*/}" +# NOTE: Try to capture semantic versions such as `1.11` which don't have a patch version. +# A patch version of 0 will be added, e.g they'll be changed to `1.11.0`. +if grep -q -E "^[0-9]+\.[0-9]+(\s*)$" <<< ${VERSION_NAME}; then + echo "Adding patch version 0 to ${VERSION_NAME}" + VERSION_NAME="${VERSION_NAME}.0" +fi + PREFIX="${GOENV_ROOT}/versions/${VERSION_NAME}" if [ ! -d "$PREFIX" ]; then diff --git a/plugins/go-build/test/fixtures/definitions/1.2.0 b/plugins/go-build/test/fixtures/definitions/1.2.0 new file mode 100644 index 00000000..b286543b --- /dev/null +++ b/plugins/go-build/test/fixtures/definitions/1.2.0 @@ -0,0 +1,15 @@ +install_darwin_106_32bit "Go Darwin 10.6 32bit 1.2.0" "http://localhost:8090/1.2.0/1.2.0.tar.gz#d7518d03fc9d7ac1d32c49358594ff6517712c3d3de4f80ebaa3229361f38937" + +install_darwin_106_64bit "Go Darwin 10.6 64bit 1.2.0" "http://localhost:8090/1.2.0/1.2.0.tar.gz#d7518d03fc9d7ac1d32c49358594ff6517712c3d3de4f80ebaa3229361f38937" + +install_darwin_108_32bit "Go Darwin 10.8 32bit 1.2.0" "http://localhost:8090/1.2.0/1.2.0.tar.gz#d7518d03fc9d7ac1d32c49358594ff6517712c3d3de4f80ebaa3229361f38937" + +install_darwin_108_64bit "Go Darwin 10.8 64bit 1.2.0" "http://localhost:8090/1.2.0/1.2.0.tar.gz#d7518d03fc9d7ac1d32c49358594ff6517712c3d3de4f80ebaa3229361f38937" + +install_bsd_64bit "Go FreeBSD 64bit 1.2.0" "http://localhost:8090/1.2.0/1.2.0.tar.gz#d7518d03fc9d7ac1d32c49358594ff6517712c3d3de4f80ebaa3229361f38937" + +install_bsd_32bit "Go FreeBSD 32bit 1.2.0" "http://localhost:8090/1.2.0/1.2.0.tar.gz#d7518d03fc9d7ac1d32c49358594ff6517712c3d3de4f80ebaa3229361f38937" + +install_linux_32bit "Go Linux 32bit 1.2.0" "http://localhost:8090/1.2.0/1.2.0.tar.gz#d7518d03fc9d7ac1d32c49358594ff6517712c3d3de4f80ebaa3229361f38937" + +install_linux_64bit "Go Linux 64bit 1.2.0" "http://localhost:8090/1.2.0/1.2.0.tar.gz#d7518d03fc9d7ac1d32c49358594ff6517712c3d3de4f80ebaa3229361f38937" diff --git a/plugins/go-build/test/goenv-install.bats b/plugins/go-build/test/goenv-install.bats index e42597a0..854dde62 100644 --- a/plugins/go-build/test/goenv-install.bats +++ b/plugins/go-build/test/goenv-install.bats @@ -3,9 +3,7 @@ project_root="${PWD%plugins/go-build}" load test_helper -echo $PATH export PATH="${project_root}libexec:$PATH" -echo $PATH @test "has usage instructions" { run goenv-help --usage uninstall @@ -633,3 +631,26 @@ OUT assert [ -x "${GOENV_ROOT}/shims/go" ] } + +@test "adds patch version '0' to definition when version argument is not already installed version and gets installed" { + # NOTE: Create fake definition to install + mkdir -p $GOENV_ROOT/plugins/go-build/share/go-build + cp $BATS_TEST_DIRNAME/fixtures/definitions/1.2.0 $GOENV_ROOT/plugins/go-build/share/go-build + + stub goenv-hooks "install : echo '$HOOK_PATH'/install.bash" + + run goenv-install -f 1.2 + + assert_output <<-OUT +Adding patch version 0 to 1.2 +Downloading 1.2.0.tar.gz... +-> http://localhost:8090/1.2.0/1.2.0.tar.gz +Installing Go Linux 64bit 1.2.0... +Installed Go Linux 64bit 1.2.0 to ${GOENV_ROOT}/versions/1.2.0 + +OUT + assert_success + + assert [ -f "${GOENV_ROOT}/versions/1.2.0/bin/go" ] + run cat "${GOENV_ROOT}/versions/1.2.0/bin/go" +} diff --git a/plugins/go-build/test/goenv-uninstall.bats b/plugins/go-build/test/goenv-uninstall.bats index e27509af..11489ec1 100644 --- a/plugins/go-build/test/goenv-uninstall.bats +++ b/plugins/go-build/test/goenv-uninstall.bats @@ -216,6 +216,18 @@ goenv: version '1.2.3' not installed OUT } +@test "adds patch version '0' to definition when version argument is already installed version and gets uninstalled" { + assert [ ! -e "${GOENV_ROOT}/shims/gofmt" ] + create_executable "1.2.0" "gofmt" + + run goenv-uninstall -f 1.2 + + assert_output <<-OUT +Adding patch version 0 to 1.2 +OUT + assert_success +} + @test "shims get rehashed and version uninstalled when version argument is already installed version" { assert [ ! -e "${GOENV_ROOT}/shims/gofmt" ] create_executable "1.10.3" "gofmt" @@ -234,4 +246,3 @@ OUT assert [ ! -d "${GOENV_ROOT}/versions/1.2.3" ] assert [ ! -e "${GOENV_ROOT}/shims/gofmt" ] } - diff --git a/plugins/go-build/test/http-definitions/1.2.0/1.2.0.tar.gz b/plugins/go-build/test/http-definitions/1.2.0/1.2.0.tar.gz new file mode 100644 index 00000000..1a860197 Binary files /dev/null and b/plugins/go-build/test/http-definitions/1.2.0/1.2.0.tar.gz differ diff --git a/plugins/go-build/test/http-definitions/1.2.0/go/bin/go b/plugins/go-build/test/http-definitions/1.2.0/go/bin/go new file mode 100644 index 00000000..6c073f64 --- /dev/null +++ b/plugins/go-build/test/http-definitions/1.2.0/go/bin/go @@ -0,0 +1 @@ +emptyjustforcontentequality