Repository navigation
Expand file tree
/
Copy pathcommon.mk
More file actions
57 lines (49 loc) · 2.43 KB
/
Copy pathcommon.mk
File metadata and controls
57 lines (49 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# common.mk — shared by every KARTIKrocks Go library.
#
# Source of truth: https://github.com/KARTIKrocks/go-build-tools
# Do NOT edit this file in a consuming repo; the copy there is overwritten by
# the sync PR. Change it here, merge, and the sync opens a PR in each repo.
#
# Consumers add this near the top of their Makefile:
#
# include common.mk
#
# and keep only repo-specific targets (lint, test, vuln, ...) in their own file.
# Tool versions. Renovate bumps these (see renovate.json).
GOLANGCI_LINT_VERSION := v2.15.0
GOIMPORTS_VERSION := v0.52.0
GOVULNCHECK_VERSION := v1.9.0
# Including this file defines targets before the consumer's own, which would
# otherwise make `setup` the default goal.
.DEFAULT_GOAL := all
.PHONY: setup print-golangci-lint-version print-govulncheck-version
# check_tool <binary> <module> <version>
# Succeeds only if <binary> on PATH was built from <module>@<version>. Reads the
# module version embedded in the binary, so an older tool already installed
# elsewhere on PATH is detected instead of silently used.
check_tool = go version -m "$$(command -v $(1) 2>/dev/null)" 2>/dev/null | grep -Eq '^[[:space:]]+mod[[:space:]]+$(2)[[:space:]]+$(3)([[:space:]]|$$)'
# install_tool <binary> <module> <version> <package>
define install_tool
@$(call check_tool,$(1),$(2),$(3)) || { \
echo "Installing $(1) $(3)..."; \
go install $(4)@$(3); \
$(call check_tool,$(1),$(2),$(3)) || { \
echo "error: $$(command -v $(1) || echo '$(1) not found') is not $(3) after install."; \
echo " Make sure $$(go env GOPATH)/bin (or GOBIN) comes first on PATH."; \
exit 1; \
}; \
}
endef
## Install development tools at the pinned versions (reinstalls on mismatch)
setup:
$(call install_tool,golangci-lint,github.com/golangci/golangci-lint/v2,$(GOLANGCI_LINT_VERSION),github.com/golangci/golangci-lint/v2/cmd/golangci-lint)
$(call install_tool,goimports,golang.org/x/tools,$(GOIMPORTS_VERSION),golang.org/x/tools/cmd/goimports)
$(call install_tool,govulncheck,golang.org/x/vuln,$(GOVULNCHECK_VERSION),golang.org/x/vuln/cmd/govulncheck)
## Print the pinned linter version. CI resolves golangci-lint-action's version
## input from this rather than hardcoding a second copy of the number.
print-golangci-lint-version:
@echo $(GOLANGCI_LINT_VERSION)
## Print the pinned scanner version. CI installs govulncheck with this rather
## than hardcoding a second copy of the number.
print-govulncheck-version:
@echo $(GOVULNCHECK_VERSION)