Skip to content

Commit f815672

Browse files
committed
Improve multi-arch handling within the same git checkout
Signed-off-by: Thomas Stromberg <[email protected]>
1 parent c63f3ae commit f815672

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

Makefile.tmpl

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
# http://github.com/tinkerbell/lint-install
44

55
{{ if .Go }}GOLINT_VERSION ?= v1.42.0{{ end }}
6-
{{ if .Dockerfile}}HADOLINT_VERSION ?= v2.7.0{{ end }}
7-
{{ if .Shell}}SHELLCHECK_VERSION ?= v0.7.2{{ end }}
6+
{{- if .Dockerfile}}HADOLINT_VERSION ?= v2.7.0{{ end }}
7+
{{- if .Shell}}SHELLCHECK_VERSION ?= v0.7.2{{ end }}
88
LINT_OS := $(shell uname)
99
LINT_ARCH := $(shell uname -m)
1010

11-
# shellcheck and hadolint don't have arm64 native binaries: use Rosetta instead
11+
# shellcheck and hadolint lack arm64 native binaries: rely on x86-64 emulation
1212
ifeq ($(LINT_OS),Darwin)
1313
ifeq ($(LINT_ARCH),arm64)
1414
LINT_ARCH=x86_64
@@ -18,25 +18,29 @@ endif
1818
{{ if .Shell }}LINT_LOWER_OS = $(shell echo $(LINT_OS) | tr '[:upper:]' '[:lower:]'){{ end }}
1919
{{ if .Go }}GOLINT_CONFIG:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))/.golangci.yml{{ end }}
2020

21-
lint: {{ if .Shell }}out/linters/shellcheck-$(SHELLCHECK_VERSION)/shellcheck {{ end }}{{ if .Dockerfile }}out/linters/hadolint-$(HADOLINT_VERSION) {{ end }}{{ if .Go}}out/linters/golangci-lint-$(GOLINT_VERSION){{ end }}
21+
lint: {{ if .Shell }}out/linters/shellcheck-$(SHELLCHECK_VERSION)-$(LINT_ARCH)/shellcheck {{ end }}{{ if .Dockerfile }}out/linters/hadolint-$(HADOLINT_VERSION)-$(LINT_ARCH) {{ end }}{{ if .Go}}out/linters/golangci-lint-$(GOLINT_VERSION)-$(LINT_ARCH){{ end }}
2222
{{- range .Commands }}
2323
{{ .}}{{ end}}
24-
{{ if .Shell}}
25-
out/linters/shellcheck-$(SHELLCHECK_VERSION)/shellcheck:
24+
25+
{{ if .Shell -}}
26+
out/linters/shellcheck-$(SHELLCHECK_VERSION)-$(LINT_ARCH)/shellcheck:
2627
mkdir -p out/linters
27-
curl -sfL https://github.com/koalaman/shellcheck/releases/download/v0.7.2/shellcheck-$(SHELLCHECK_VERSION).$(LINT_LOWER_OS).$(LINT_ARCH).tar.xz | tar -C out/linters -xJf -
28-
{{- end }}
29-
{{ if .Dockerfile}}
30-
out/linters/hadolint-$(HADOLINT_VERSION):
28+
curl -sSfL https://github.com/koalaman/shellcheck/releases/download/v0.7.2/shellcheck-$(SHELLCHECK_VERSION).$(LINT_LOWER_OS).$(LINT_ARCH).tar.xz | tar -C out/linters -xJf -
29+
mv shellcheck-$(SHELLCHECK_VERSION) shellcheck-$(SHELLCHECK_VERSION)-$(LINT_ARCH)
30+
31+
{{ end -}}
32+
{{ if .Dockerfile -}}
33+
out/linters/hadolint-$(HADOLINT_VERSION)-$(LINT_ARCH):
3134
mkdir -p out/linters
32-
curl -sfL https://github.com/hadolint/hadolint/releases/download/v2.6.1/hadolint-$(LINT_OS)-$(LINT_ARCH) > out/linters/hadolint-$(HADOLINT_VERSION)
33-
chmod u+x out/linters/hadolint-$(HADOLINT_VERSION)
34-
{{- end }}
35-
{{ if .Go }}
36-
out/linters/golangci-lint-$(GOLINT_VERSION):
35+
curl -sfL https://github.com/hadolint/hadolint/releases/download/v2.6.1/hadolint-$(LINT_OS)-$(LINT_ARCH) > out/linters/hadolint-$(HADOLINT_VERSION)-$(LINT_ARCH)
36+
chmod u+x out/linters/hadolint-$(HADOLINT_VERSION)-$(LINT_ARCH)
37+
38+
{{ end -}}
39+
{{ if .Go -}}
40+
out/linters/golangci-lint-$(GOLINT_VERSION)-$(LINT_ARCH):
3741
mkdir -p out/linters
38-
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b out/linters $(GOLINT_VERSION)
39-
mv out/linters/golangci-lint out/linters/golangci-lint-$(GOLINT_VERSION)
40-
{{- end }}
42+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b out/linters $(GOLINT_VERSION)
43+
mv out/linters/golangci-lint out/linters/golangci-lint-$(GOLINT_VERSION)-$(LINT_ARCH)
4144

45+
{{ end -}}
4246
# END: lint-install {{.Args}}

lint-install.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func goLintCmd(root string, level string) string {
187187
}
188188

189189
if len(found) == 1 && found[0] == root {
190-
return fmt.Sprintf("out/linters/golangci-lint-$(GOLINT_VERSION) run%s", suffix)
190+
return fmt.Sprintf("out/linters/golangci-lint-$(GOLINT_VERSION)-$(LINT_ARCH) run%s", suffix)
191191
}
192192

193193
return fmt.Sprintf(`find . -name go.mod | xargs -n1 dirname | xargs -n1 -I{} sh -c "cd {} && golangci-lint run -c $(GOLINT_CONFIG)"%s`, suffix)
@@ -199,7 +199,7 @@ func shellLintCmd(_ string, level string) string {
199199
if level == "warn" {
200200
suffix = " || true"
201201
}
202-
return fmt.Sprintf(`out/linters/shellcheck-$(SHELLCHECK_VERSION)/shellcheck $(shell find . -name "*.sh")%s`, suffix)
202+
return fmt.Sprintf(`out/linters/shellcheck-$(SHELLCHECK_VERSION)-$(LINT_ARCH)/shellcheck $(shell find . -name "*.sh")%s`, suffix)
203203
}
204204

205205
// dockerLintCmd returns the appropriate docker lint command for a project.
@@ -208,7 +208,7 @@ func dockerLintCmd(_ string, level string) string {
208208
if level == "warn" {
209209
threshold = "none"
210210
}
211-
return fmt.Sprintf(`out/linters/hadolint-$(HADOLINT_VERSION) -t %s $(shell find . -name "*Dockerfile")`, threshold)
211+
return fmt.Sprintf(`out/linters/hadolint-$(HADOLINT_VERSION)-$(LINT_ARCH) -t %s $(shell find . -name "*Dockerfile")`, threshold)
212212
}
213213

214214
// main creates peanut butter & jelly sandwiches with utmost precision.

0 commit comments

Comments
 (0)