Skip to content

Commit b8eb7a4

Browse files
feat(make): simplifies local tooling installation (#203)
To make targets such as `test` or `lint` self-contained we can leverage Makefile target resolutions and install tools to local `./bin` folder when they are not present. This way we can also ensure consistency as both CI and local dev loop will be using exact same versions. This PR introduces `Makefile.tools.mk` where all project-specific tools are defined and installed on demand. Dependent `.PHONY` targets can simply request binary to exist. As a consequence github actions are also simplified as `make` takes care of setting up tooling with right versions instead, reducing the risk of versions drift between the enviroments. Unused composite actions has been removed: - `.github/actions/go-test/action.yml` - this is now handled as `make test` - `.github/actions/push-image/action.yml` was not referred across workflows. The actual push is part of `.github/actions/push-image/action.yml` Signed-off-by: Bartosz Majsak <[email protected]>
1 parent cb27f87 commit b8eb7a4

File tree

5 files changed

+57
-73
lines changed

5 files changed

+57
-73
lines changed

.github/actions/go-test/action.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.

.github/actions/push-image/action.yml

Lines changed: 0 additions & 16 deletions
This file was deleted.

.github/workflows/ci-pr-checks.yaml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: Set up go with cache
1919
uses: actions/setup-go@v5
2020
with:
21-
go-version: '1.24.0'
21+
go-version-file: ./go.mod
2222
cache-dependency-path: ./go.sum
2323

2424
- name: Install libzmq dependencies (kvcache/kvevents)
@@ -32,16 +32,11 @@ jobs:
3232
- name: Run lint checks
3333
uses: golangci/golangci-lint-action@v8
3434
with:
35-
version: 'v2.1.6'
35+
version: 'v2.4.0'
3636
args: "--config=./.golangci.yml"
3737

3838
- name: Run go test
3939
shell: bash
4040
run: |
41-
echo "Installing Ginkgo..."
42-
go install github.com/onsi/ginkgo/ginkgo@latest
43-
export PATH=$PATH:$(go env GOPATH)/bin
44-
echo "Ginkgo installed:"
45-
ginkgo version
4641
echo "Running tests with Ginkgo..."
4742
make test

Makefile

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
LOCALBIN ?= $(shell pwd)/bin
16+
$(LOCALBIN):
17+
mkdir -p $(LOCALBIN)
18+
19+
# Project-specific Go tooling is defined in Makefile.tools.mk.
20+
include Makefile.tools.mk
21+
1522
# Makefile for the llm-d-inference-sim project
1623

1724
SHELL := /usr/bin/env bash
@@ -75,12 +82,12 @@ format: ## Format Go source files
7582
@gofmt -l -w $(SRC)
7683

7784
.PHONY: test
78-
test: check-ginkgo download-tokenizer download-zmq ## Run tests
85+
test: $(GINKGO) download-tokenizer download-zmq ## Run tests
7986
@printf "\033[33;1m==== Running tests ====\033[0m\n"
8087
ifdef GINKGO_FOCUS
81-
CGO_ENABLED=1 ginkgo -ldflags="$(GO_LDFLAGS)" -v -r --focus="$(GINKGO_FOCUS)"
88+
CGO_ENABLED=1 $(GINKGO) -ldflags="$(GO_LDFLAGS)" -v -r --focus="$(GINKGO_FOCUS)"
8289
else
83-
CGO_ENABLED=1 ginkgo -ldflags="$(GO_LDFLAGS)" -v -r
90+
CGO_ENABLED=1 $(GINKGO) -ldflags="$(GO_LDFLAGS)" -v -r
8491
endif
8592

8693
.PHONY: post-deploy-test
@@ -89,16 +96,16 @@ post-deploy-test: ## Run post deployment tests
8996
@echo "Post-deployment tests passed."
9097

9198
.PHONY: lint
92-
lint: check-golangci-lint check-golangci-lint-version ## Run lint
99+
lint: $(GOLANGCI_LINT) ## Run lint
93100
@printf "\033[33;1m==== Running linting ====\033[0m\n"
94-
golangci-lint run
101+
$(GOLANGCI_LINT) run
95102

96103
##@ Build
97104

98105
.PHONY: build
99106
build: check-go download-tokenizer download-zmq
100107
@printf "\033[33;1m==== Building ====\033[0m\n"
101-
go build -ldflags="$(GO_LDFLAGS)" -o bin/$(PROJECT_NAME) cmd/$(PROJECT_NAME)/main.go
108+
go build -ldflags="$(GO_LDFLAGS)" -o $(LOCALBIN)/$(PROJECT_NAME) cmd/$(PROJECT_NAME)/main.go
102109

103110
##@ Container Build/Push
104111

@@ -163,40 +170,12 @@ env: ## Print environment variables
163170
@echo "IMG=$(IMG)"
164171
@echo "CONTAINER_TOOL=$(CONTAINER_TOOL)"
165172

166-
167173
##@ Tools
168-
.PHONY: check-tools
169-
check-tools:
170-
check-go \
171-
check-ginkgo \
172-
check-golangci-lint \
173-
check-container-tool \
174-
check-helm
175-
@echo "✅ All required tools are installed."
176-
177174
.PHONY: check-go
178175
check-go:
179176
@command -v go >/dev/null 2>&1 || { \
180177
echo "❌ Go is not installed. Install it from https://golang.org/dl/"; exit 1; }
181178

182-
.PHONY: check-ginkgo
183-
check-ginkgo:
184-
@command -v ginkgo >/dev/null 2>&1 || { \
185-
echo "❌ ginkgo is not installed. Install with: go install github.com/onsi/ginkgo/v2/ginkgo@latest"; exit 1; }
186-
187-
.PHONY: check-golangci-lint
188-
check-golangci-lint:
189-
@command -v golangci-lint >/dev/null 2>&1 || { \
190-
echo "❌ golangci-lint is not installed. Install from https://golangci-lint.run/docs/welcome/install/"; exit 1; }
191-
192-
.PHONY: check-golangci-lint-version
193-
check-golangci-lint-version:
194-
@version=$$(golangci-lint --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -n 1); \
195-
if [[ $$version != 2.* ]]; then \
196-
echo "❌ golangci-lint version 2.x is required. Current version: $$version"; \
197-
exit 1; \
198-
fi
199-
200179
.PHONY: check-container-tool
201180
check-container-tool:
202181
@command -v $(CONTAINER_TOOL) >/dev/null 2>&1 || { \
@@ -208,7 +187,6 @@ check-helm:
208187
@command -v helm >/dev/null 2>&1 || { \
209188
echo "❌ helm is not installed. Install it from https://helm.sh/docs/intro/install/"; exit 1; }
210189

211-
212190
.PHONY: check-builder
213191
check-builder:
214192
@if [ -z "$(BUILDER)" ]; then \

Makefile.tools.mk

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright 2025 The llm-d-inference-sim Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
16+
# $1 - target path with name of binary
17+
# $2 - package url which can be installed
18+
# $3 - specific version of package
19+
# Source: https://github.com/kubernetes-sigs/kubebuilder/blob/3fd04199acb4556376dc17a7393bfd43bcd40c26/Makefile#L237-L251
20+
define go-install-tool
21+
@[ -f "$(1)-$(3)" ] && [ "$$(readlink -- "$(1)" 2>/dev/null)" = "$(1)-$(3)" ] || { \
22+
set -e; \
23+
package=$(2)@$(3) ;\
24+
echo "Downloading $${package}" ;\
25+
rm -f $(1) ;\
26+
GOBIN=$(LOCALBIN) go install $${package} ;\
27+
mv $(1) $(1)-$(3) ;\
28+
} ;\
29+
ln -sf $$(realpath $(1)-$(3)) $(1)
30+
endef
31+
32+
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
33+
GOLANGCI_LINT_VERSION = v2.4.0
34+
GINKGO = $(LOCALBIN)/ginkgo
35+
GINKGO_VERSION = v2.25.3
36+
37+
$(GINKGO): $(LOCALBIN)
38+
$(call go-install-tool,$(GINKGO),github.com/onsi/ginkgo/v2/ginkgo,$(GINKGO_VERSION))
39+
@GOBIN=$(LOCALBIN) go install -mod=readonly github.com/onsi/ginkgo/v2/ginkgo
40+
41+
$(GOLANGCI_LINT): $(LOCALBIN)
42+
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))

0 commit comments

Comments
 (0)