@@ -51,6 +51,18 @@ GO_BUILD_FLAGS ?=
51
51
# #########################
52
52
# Helpers
53
53
# #########################
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
+
54
66
ifdef VERBOSE
55
67
VERBOSE_FLAG := -v
56
68
VERBOSE_FLAG_LONG := --verbose
@@ -230,9 +242,40 @@ install-dev-tools:
230
242
&& go install github.com/google/go-licenses/v2@d01822334fba5896920a060f762ea7ecdbd086e8 \
231
243
&& go install github.com/incu6us/goimports-reviser/v3@f034195cc8a7ffc7cc70d60aa3a25500874eaf04 \
232
244
&& go install gotest.tools/gotestsum@ac6dad9c7d87b969004f7749d1942938526c9716
233
- @echo " Remember to add GOROOT /bin to your path"
245
+ @echo " Remember to add \$ $HOME /go /bin to your path"
234
246
$(call footer, $@ )
235
247
248
+ GO_VERSION ?= stable
249
+ GO_VERSION_SELECTOR =
250
+ GO_VERSION_SELECTOR = .version | startswith("go$(GO_VERSION ) ")
251
+ ifeq ($(GO_VERSION ) ,canary)
252
+ GO_VERSION_SELECTOR = .stable==false
253
+ endif
254
+ ifeq ($(GO_VERSION ) ,stable)
255
+ GO_VERSION_SELECTOR = .stable==true
256
+ endif
257
+ ifeq ($(GO_VERSION ) ,)
258
+ GO_VERSION_SELECTOR = .stable==true
259
+ endif
260
+
261
+ GO_INSTALL_DESTINATION ?= /opt/$(BINARY ) -dev-tools
262
+
263
+ install-go :
264
+ $(call title, $@ )
265
+ @mkdir -p $(GO_INSTALL_DESTINATION )
266
+ @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" | \
267
+ jq -rc ' map(select($(GO_VERSION_SELECTOR)))[0].files | map(select(.os=="$(OS)" and .arch=="$(ARCH)"))[0].filename' ) | \
268
+ tar xzC $(GO_INSTALL_DESTINATION ) || exit ; \
269
+ else \
270
+ echo " Install already detected, doing nothing." ; \
271
+ fi
272
+ @echo Remember to add to your profile: export PATH=" $( GO_INSTALL_DESTINATION) /go/bin:\$ $HOME /go/bin:\$ $PATH "
273
+ $(call footer, $@ )
274
+
275
+ install-go-resolve-version :
276
+ @curl -fsSL --proto " =https" --tlsv1.2 " https://go.dev/dl/?mode=json&include=all" | \
277
+ jq -rc ' map(select($(GO_VERSION_SELECTOR)))[0].version' | sed s/go//
278
+
236
279
# #########################
237
280
# Testing tasks
238
281
# #########################
0 commit comments