Skip to content

Commit e3cfef2

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

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
@@ -230,9 +242,40 @@ install-dev-tools:
230242
&& go install github.com/google/go-licenses/v2@d01822334fba5896920a060f762ea7ecdbd086e8 \
231243
&& go install github.com/incu6us/goimports-reviser/v3@f034195cc8a7ffc7cc70d60aa3a25500874eaf04 \
232244
&& 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"
234246
$(call footer, $@)
235247

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+
236279
##########################
237280
# Testing tasks
238281
##########################

0 commit comments

Comments
 (0)