Skip to content

Commit 5522092

Browse files
committed
Add install-golang make task
Signed-off-by: apostasie <[email protected]>
1 parent 544ceb0 commit 5522092

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

Makefile

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ GO_BUILD_FLAGS ?=
5151
##########################
5252
# Helpers
5353
##########################
54+
ARCH := amd64
55+
ifeq ($(shell uname -m), aarch64)
56+
ARCH = arm64
57+
endif
58+
OS := linux
59+
ifeq ($(shell uname -s), Darwin)
60+
OS = darwin
61+
endif
62+
ifeq ($(shell uname -s), FreeBSD)
63+
OS = freebsd
64+
endif
65+
5466
ifdef VERBOSE
5567
VERBOSE_FLAG := -v
5668
VERBOSE_FLAG_LONG := --verbose
@@ -237,9 +249,40 @@ install-dev-tools:
237249
&& go install github.com/google/go-licenses/v2@d01822334fba5896920a060f762ea7ecdbd086e8 \
238250
&& go install github.com/incu6us/goimports-reviser/v3@f034195cc8a7ffc7cc70d60aa3a25500874eaf04 \
239251
&& go install gotest.tools/gotestsum@ac6dad9c7d87b969004f7749d1942938526c9716
240-
@echo "Remember to add GOROOT/bin to your path"
252+
@echo "Remember to add \$$HOME/go/bin to your path"
241253
$(call footer, $@)
242254

255+
GO_VERSION ?= stable
256+
GO_VERSION_SELECTOR =
257+
GO_VERSION_SELECTOR = .version | startswith("go$(GO_VERSION)")
258+
ifeq ($(GO_VERSION),canary)
259+
GO_VERSION_SELECTOR = .stable==false
260+
endif
261+
ifeq ($(GO_VERSION),stable)
262+
GO_VERSION_SELECTOR = .stable==true
263+
endif
264+
ifeq ($(GO_VERSION),)
265+
GO_VERSION_SELECTOR = .stable==true
266+
endif
267+
268+
GO_INSTALL_DESTINATION ?= /opt/$(BINARY)-dev-tools
269+
270+
install-go:
271+
$(call title, $@)
272+
@mkdir -p $(GO_INSTALL_DESTINATION)
273+
@if [ ! -e $(GO_INSTALL_DESTINATION)/go ]; then curl -fsSL --proto '=https' --tlsv1.2 https://go.dev/dl/$(shell curl -fsSL --proto "=https" --tlsv1.3 "https://go.dev/dl/?mode=json&include=all" | \
274+
jq -rc 'map(select($(GO_VERSION_SELECTOR)))[0].files | map(select(.os=="$(OS)" and .arch=="$(ARCH)"))[0].filename') | \
275+
tar xzC $(GO_INSTALL_DESTINATION) || exit; \
276+
else \
277+
echo "Install already detected, doing nothing."; \
278+
fi
279+
@echo Remember to add to your profile: export PATH="$(GO_INSTALL_DESTINATION)/go/bin:\$$HOME/go/bin:\$$PATH"
280+
$(call footer, $@)
281+
282+
install-go-resolve-version:
283+
@curl -fsSL --proto "=https" --tlsv1.2 "https://go.dev/dl/?mode=json&include=all" | \
284+
jq -rc 'map(select($(GO_VERSION_SELECTOR)))[0].version' | sed s/go//
285+
243286
##########################
244287
# Testing tasks
245288
##########################

0 commit comments

Comments
 (0)