Unverified Commit c4648ab9 authored by Samruddhi Khandale's avatar Samruddhi Khandale Committed by GitHub

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
parent 173c7ca3
{ {
"id": "go", "id": "go",
"version": "1.1.0", "version": "1.1.1",
"name": "Go", "name": "Go",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/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.", "description": "Installs Go and common Go utilities. Auto-detects latest version and installs needed dependencies.",
......
...@@ -142,7 +142,8 @@ if ! cat /etc/group | grep -e "^golang:" > /dev/null 2>&1; then ...@@ -142,7 +142,8 @@ if ! cat /etc/group | grep -e "^golang:" > /dev/null 2>&1; then
fi fi
usermod -a -G golang "${USERNAME}" usermod -a -G golang "${USERNAME}"
mkdir -p "${TARGET_GOROOT}" "${TARGET_GOPATH}" 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 # Use a temporary locaiton for gpg keys to avoid polluting image
export GNUPGHOME="/tmp/tmp-gnupg" export GNUPGHOME="/tmp/tmp-gnupg"
mkdir -p ${GNUPGHOME} mkdir -p ${GNUPGHOME}
...@@ -186,7 +187,7 @@ if [ "${TARGET_GO_VERSION}" != "none" ] && ! type go > /dev/null 2>&1; then ...@@ -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 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 rm -rf /tmp/go.tar.gz /tmp/go.tar.gz.asc /tmp/tmp-gnupg
else else
echo "Go already installed. Skipping." echo "(!) Go is already installed with version ${TARGET_GO_VERSION}. Skipping."
fi fi
# Install Go tools that are isImportant && !replacedByGopls based on # Install Go tools that are isImportant && !replacedByGopls based on
...@@ -218,8 +219,10 @@ if [ "${INSTALL_GO_TOOLS}" = "true" ]; then ...@@ -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 (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 # Move Go tools into path and clean up
if [ -d /tmp/gotools/bin ]; then
mv /tmp/gotools/bin/* ${TARGET_GOPATH}/bin/ mv /tmp/gotools/bin/* ${TARGET_GOPATH}/bin/
rm -rf /tmp/gotools rm -rf /tmp/gotools
fi
# Install golangci-lint from precompiled binares # Install golangci-lint from precompiled binares
if [ "$GOLANGCILINT_VERSION" = "latest" ] || [ "$GOLANGCILINT_VERSION" = "" ]; then if [ "$GOLANGCILINT_VERSION" = "latest" ] || [ "$GOLANGCILINT_VERSION" = "" ]; then
......
...@@ -5,9 +5,9 @@ set -e ...@@ -5,9 +5,9 @@ set -e
# Optional: Import test library # Optional: Import test library
source dev-container-features-test-lib source dev-container-features-test-lib
check "mkcert version" mkcert --version | grep "v1.4.2" check "mkcert version" bash -c "mkcert --version | grep v1.4.2"
check "mkcert is installed at correct path" which mkcert | grep "/go/bin/mkcert" check "mkcert is installed at correct path" bash -c "which mkcert | grep /go/bin/mkcert"
check "golangci-lint version" golangci-lint --version | grep "golangci-lint has version 1.50.0" check "golangci-lint version" bash -c "golangci-lint --version | grep 'golangci-lint has version 1.50.0'"
# Report result # Report result
reportResults reportResults
#!/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
...@@ -8,5 +8,13 @@ ...@@ -8,5 +8,13 @@
} }
}, },
"postCreateCommand": "go install filippo.io/mkcert@v1.4.2" "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"
}
}
} }
} }
...@@ -7,7 +7,7 @@ source dev-container-features-test-lib ...@@ -7,7 +7,7 @@ source dev-container-features-test-lib
check "version" go version check "version" go version
check "revive version" revive --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 # Report result
reportResults reportResults
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment