Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GH-54] Fix golang releases without patch version not being installed #75

Merged
merged 1 commit into from
Apr 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions plugins/go-build/bin/go-build
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions plugins/go-build/bin/goenv-install
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions plugins/go-build/bin/goenv-uninstall
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions plugins/go-build/test/fixtures/definitions/1.2.0
Original file line number Diff line number Diff line change
@@ -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"
25 changes: 23 additions & 2 deletions plugins/go-build/test/goenv-install.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
}
13 changes: 12 additions & 1 deletion plugins/go-build/test/goenv-uninstall.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -234,4 +246,3 @@ OUT
assert [ ! -d "${GOENV_ROOT}/versions/1.2.3" ]
assert [ ! -e "${GOENV_ROOT}/shims/gofmt" ]
}

Binary file not shown.
1 change: 1 addition & 0 deletions plugins/go-build/test/http-definitions/1.2.0/go/bin/go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
emptyjustforcontentequality