@@ -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
@@ -237,9 +249,40 @@ install-dev-tools:
237
249
&& go install github.com/google/go-licenses/v2@d01822334fba5896920a060f762ea7ecdbd086e8 \
238
250
&& go install github.com/incu6us/goimports-reviser/v3@f034195cc8a7ffc7cc70d60aa3a25500874eaf04 \
239
251
&& 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"
241
253
$(call footer, $@ )
242
254
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
+
243
286
# #########################
244
287
# Testing tasks
245
288
# #########################
0 commit comments