Skip to content

Commit 4e39b02

Browse files
Move install command to function
1 parent 276ffb7 commit 4e39b02

File tree

2 files changed

+20
-40
lines changed

2 files changed

+20
-40
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ install-golangci-lint: FORCE
2727
@if ! hash golangci-lint 2>/dev/null; then printf "\e[1;36m>> Installing golangci-lint (this may take a while)...\e[0m\n"; go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest; fi
2828

2929
install-go-licence-detector: FORCE
30-
@if ! hash go-licence-detector 2>/dev/null; then printf "\e[1;36m>> Installing go-licence-detector...\e[0m\n"; go install go.elastic.co/go-licence-detector@latest; fi
30+
@if ! hash go-licence-detector 2>/dev/null; then printf "\e[1;36m>> Installing go-licence-detector (this may take a while)...\e[0m\n"; go install go.elastic.co/go-licence-detector@latest; fi
3131

3232
install-addlicense: FORCE
33-
@if ! hash addlicense 2>/dev/null; then printf "\e[1;36m>> Installing addlicense...\e[0m\n"; go install github.com/google/addlicense@latest; fi
33+
@if ! hash addlicense 2>/dev/null; then printf "\e[1;36m>> Installing addlicense (this may take a while)...\e[0m\n"; go install github.com/google/addlicense@latest; fi
3434

3535
prepare-static-check: FORCE install-golangci-lint install-go-licence-detector install-addlicense
3636

internal/makefile/makefile.go

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -75,27 +75,27 @@ endif
7575
// Prepare
7676
prepare := category{name: "prepare"}
7777

78+
installTool := func(name, modulePath string) []string {
79+
return []string{
80+
fmt.Sprintf(`@if ! hash %s 2>/dev/null; then`, name) +
81+
fmt.Sprintf(` printf "\e[1;36m>> Installing %s (this may take a while)...\e[0m\n";`, name) +
82+
fmt.Sprintf(` go install %s; fi`, modulePath),
83+
}
84+
}
85+
7886
var prepareStaticRecipe []string
7987
if isGolang {
8088
prepare.addRule(rule{
8189
description: "Install goimports required by goimports/static-check",
8290
phony: true,
8391
target: "install-goimports",
84-
recipe: []string{
85-
`@if ! hash goimports 2>/dev/null; then` +
86-
` printf "\e[1;36m>> Installing goimports (this may take a while)...\e[0m\n";` +
87-
` go install golang.org/x/tools/cmd/goimports@latest; fi`,
88-
},
92+
recipe: installTool("goimports", "golang.org/x/tools/cmd/goimports@latest"),
8993
})
9094
prepare.addRule(rule{
9195
description: "Install golangci-lint required by run-golangci-lint/static-check",
9296
phony: true,
9397
target: "install-golangci-lint",
94-
recipe: []string{
95-
`@if ! hash golangci-lint 2>/dev/null; then` +
96-
` printf "\e[1;36m>> Installing golangci-lint (this may take a while)...\e[0m\n";` +
97-
` go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest; fi`,
98-
},
98+
recipe: installTool("golangci-lint", "github.com/golangci/golangci-lint/cmd/golangci-lint@latest"),
9999
})
100100
prepareStaticRecipe = append(prepareStaticRecipe, "install-golangci-lint")
101101
}
@@ -105,23 +105,15 @@ endif
105105
description: "Install-go-licence-detector required by check-dependency-licenses/static-check",
106106
phony: true,
107107
target: "install-go-licence-detector",
108-
recipe: []string{
109-
`@if ! hash go-licence-detector 2>/dev/null; then` +
110-
` printf "\e[1;36m>> Installing go-licence-detector...\e[0m\n";` +
111-
` go install go.elastic.co/go-licence-detector@latest; fi`,
112-
},
108+
recipe: installTool("go-licence-detector", "go.elastic.co/go-licence-detector@latest"),
113109
})
114110
prepareStaticRecipe = append(prepareStaticRecipe, "install-go-licence-detector")
115111
}
116112
prepare.addRule(rule{
117113
description: "Install addlicense required by check-license-headers/license-headers/static-check",
118114
phony: true,
119115
target: "install-addlicense",
120-
recipe: []string{
121-
`@if ! hash addlicense 2>/dev/null; then ` +
122-
` printf "\e[1;36m>> Installing addlicense...\e[0m\n"; ` +
123-
` go install github.com/google/addlicense@latest; fi`,
124-
},
116+
recipe: installTool("addlicense", "github.com/google/addlicense@latest"),
125117
})
126118
prepareStaticRecipe = append(prepareStaticRecipe, "install-addlicense")
127119
}
@@ -137,36 +129,24 @@ endif
137129
prepare.addRule(rule{
138130
description: "Install controller-gen required by static-check and build-all. This is used in CI before dropping privileges, you should probably install all the tools using your package manager",
139131
phony: true,
140-
recipe: []string{
141-
`@if ! hash controller-gen 2>/dev/null; then` +
142-
` printf "\e[1;36m>> Installing controller-gen...\e[0m\n";` +
143-
` go install sigs.k8s.io/controller-tools/cmd/controller-gen@latest; fi`,
144-
},
145-
target: "install-controller-gen",
132+
target: "install-controller-gen",
133+
recipe: installTool("controller-gen", "sigs.k8s.io/controller-tools/cmd/controller-gen@latest"),
146134
})
147135

148136
prepare.addRule(rule{
149137
description: "Install setup-envtest required by check. This is used in CI before dropping privileges, you should probably install all the tools using your package manager",
150138
phony: true,
151-
recipe: []string{
152-
`@if ! hash setup-envtest 2>/dev/null; then` +
153-
` printf "\e[1;36m>> Installing setup-envtest...\e[0m\n";` +
154-
` go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest; fi`,
155-
},
156-
target: "install-setup-envtest",
139+
target: "install-setup-envtest",
140+
recipe: installTool("setup-envtest", "sigs.k8s.io/controller-runtime/tools/setup-envtest@latest"),
157141
})
158142
}
159143

160144
if sr.UseGinkgo {
161145
prepare.addRule(rule{
162146
description: "Install ginkgo required when using it as test runner. This is used in CI before dropping privileges, you should probably install all the tools using your package manager",
163147
phony: true,
164-
recipe: []string{
165-
`@if ! hash ginkgo 2>/dev/null; then` +
166-
` printf "\e[1;36m>> Installing ginkgo...\e[0m\n";` +
167-
` go install github.com/onsi/ginkgo/v2/ginkgo@latest; fi`,
168-
},
169-
target: "install-ginkgo",
148+
target: "install-ginkgo",
149+
recipe: installTool("ginkgo", "github.com/onsi/ginkgo/v2/ginkgo@latest"),
170150
})
171151
}
172152

0 commit comments

Comments
 (0)