diff options
author | Samruddhi Khandale <skhandale@microsoft.com> | 2022-11-23 20:33:50 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-23 20:33:50 +0300 |
commit | c4648ab98cdeeb520e7e629c5db4a471ec802954 (patch) | |
tree | f7f10e225e46f4ce4b6a71e5564345abb1b13e30 | |
parent | 173c7ca3c7ad646e6b9732b5af8d45f08606182e (diff) |
go: fix bug - Go doesn't update version if go is already installed (#303)
* go: fix bug - Go doesn't update version if go is already installed
* Update tests with bash -c
-rw-r--r-- | src/go/devcontainer-feature.json | 2 | ||||
-rwxr-xr-x | src/go/install.sh | 11 | ||||
-rw-r--r-- | test/go/install_go_tool_in_postCreate.sh | 6 | ||||
-rw-r--r-- | test/go/install_go_twice.sh | 11 | ||||
-rw-r--r-- | test/go/scenarios.json | 8 | ||||
-rwxr-xr-x | test/go/test.sh | 2 |
6 files changed, 31 insertions, 9 deletions
diff --git a/src/go/devcontainer-feature.json b/src/go/devcontainer-feature.json index c83b4f0..b2aa30b 100644 --- a/src/go/devcontainer-feature.json +++ b/src/go/devcontainer-feature.json @@ -1,6 +1,6 @@ { "id": "go", - "version": "1.1.0", + "version": "1.1.1", "name": "Go", "documentationURL": "https://github.com/devcontainers/features/tree/main/src/go", "description": "Installs Go and common Go utilities. Auto-detects latest version and installs needed dependencies.", diff --git a/src/go/install.sh b/src/go/install.sh index f561144..844411f 100755 --- a/src/go/install.sh +++ b/src/go/install.sh @@ -142,7 +142,8 @@ if ! cat /etc/group | grep -e "^golang:" > /dev/null 2>&1; then fi usermod -a -G golang "${USERNAME}" mkdir -p "${TARGET_GOROOT}" "${TARGET_GOPATH}" -if [ "${TARGET_GO_VERSION}" != "none" ] && ! type go > /dev/null 2>&1; then + +if [[ "${TARGET_GO_VERSION}" != "none" ]] && [[ "$(go version)" != *"${TARGET_GO_VERSION}"* ]]; then # Use a temporary locaiton for gpg keys to avoid polluting image export GNUPGHOME="/tmp/tmp-gnupg" mkdir -p ${GNUPGHOME} @@ -186,7 +187,7 @@ if [ "${TARGET_GO_VERSION}" != "none" ] && ! type go > /dev/null 2>&1; then tar -xzf /tmp/go.tar.gz -C "${TARGET_GOROOT}" --strip-components=1 rm -rf /tmp/go.tar.gz /tmp/go.tar.gz.asc /tmp/tmp-gnupg else - echo "Go already installed. Skipping." + echo "(!) Go is already installed with version ${TARGET_GO_VERSION}. Skipping." fi # Install Go tools that are isImportant && !replacedByGopls based on @@ -218,8 +219,10 @@ if [ "${INSTALL_GO_TOOLS}" = "true" ]; then (echo "${GO_TOOLS}" | xargs -n 1 go ${go_install_command} -v )2>&1 | tee -a /usr/local/etc/vscode-dev-containers/go.log # Move Go tools into path and clean up - mv /tmp/gotools/bin/* ${TARGET_GOPATH}/bin/ - rm -rf /tmp/gotools + if [ -d /tmp/gotools/bin ]; then + mv /tmp/gotools/bin/* ${TARGET_GOPATH}/bin/ + rm -rf /tmp/gotools + fi # Install golangci-lint from precompiled binares if [ "$GOLANGCILINT_VERSION" = "latest" ] || [ "$GOLANGCILINT_VERSION" = "" ]; then diff --git a/test/go/install_go_tool_in_postCreate.sh b/test/go/install_go_tool_in_postCreate.sh index dbb086c..54637d9 100644 --- a/test/go/install_go_tool_in_postCreate.sh +++ b/test/go/install_go_tool_in_postCreate.sh @@ -5,9 +5,9 @@ set -e # Optional: Import test library source dev-container-features-test-lib -check "mkcert version" mkcert --version | grep "v1.4.2" -check "mkcert is installed at correct path" which mkcert | grep "/go/bin/mkcert" -check "golangci-lint version" golangci-lint --version | grep "golangci-lint has version 1.50.0" +check "mkcert version" bash -c "mkcert --version | grep v1.4.2" +check "mkcert is installed at correct path" bash -c "which mkcert | grep /go/bin/mkcert" +check "golangci-lint version" bash -c "golangci-lint --version | grep 'golangci-lint has version 1.50.0'" # Report result reportResults diff --git a/test/go/install_go_twice.sh b/test/go/install_go_twice.sh new file mode 100644 index 0000000..8f6ef54 --- /dev/null +++ b/test/go/install_go_twice.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +check "go-version" bash -c "go version | grep 1.19" + +# Report result +reportResults diff --git a/test/go/scenarios.json b/test/go/scenarios.json index b3fe49c..86e1270 100644 --- a/test/go/scenarios.json +++ b/test/go/scenarios.json @@ -8,5 +8,13 @@ } }, "postCreateCommand": "go install filippo.io/mkcert@v1.4.2" + }, + "install_go_twice": { + "image": "mcr.microsoft.com/devcontainers/go:1.18", + "features": { + "go": { + "version": "1.19" + } + } } } diff --git a/test/go/test.sh b/test/go/test.sh index ee9f171..ccae6da 100755 --- a/test/go/test.sh +++ b/test/go/test.sh @@ -7,7 +7,7 @@ source dev-container-features-test-lib check "version" go version check "revive version" revive --version -check "revive is installed at correct path" which revive | grep "/go/bin/revive" +check "revive is installed at correct path" bash -c "which revive | grep /go/bin/revive" # Report result reportResults
\ No newline at end of file |