From fc4a549a2da61be8aa2ddf20a5c3439cf33aacff Mon Sep 17 00:00:00 2001 From: Bartosz Majsak Date: Thu, 18 Sep 2025 09:52:41 +0200 Subject: [PATCH] feat(make): simplifies local tooling installation 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 --- .github/actions/go-test/action.yml | 15 --------- .github/actions/push-image/action.yml | 16 --------- .github/workflows/ci-pr-checks.yaml | 9 ++--- Makefile | 48 ++++++++------------------- Makefile.tools.mk | 42 +++++++++++++++++++++++ 5 files changed, 57 insertions(+), 73 deletions(-) delete mode 100644 .github/actions/go-test/action.yml delete mode 100644 .github/actions/push-image/action.yml create mode 100644 Makefile.tools.mk diff --git a/.github/actions/go-test/action.yml b/.github/actions/go-test/action.yml deleted file mode 100644 index c1de448a..00000000 --- a/.github/actions/go-test/action.yml +++ /dev/null @@ -1,15 +0,0 @@ -name: Go Test -description: Run Ginkgo tests -runs: - using: "composite" - steps: - - run: | - echo "Installing Ginkgo..." - go install github.com/onsi/ginkgo/ginkgo@latest - export PATH=$PATH:$(go env GOPATH)/bin - echo "Ginkgo installed:" - ginkgo version - echo "Running tests with Ginkgo..." - go env -w GOFLAGS=-buildvcs=false - make test - shell: bash diff --git a/.github/actions/push-image/action.yml b/.github/actions/push-image/action.yml deleted file mode 100644 index ebbe635b..00000000 --- a/.github/actions/push-image/action.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: Push Docker Image -description: Push built image to container registry -inputs: - image-name: - required: true - tag: - required: true - registry: - required: true -runs: - using: "composite" - steps: - - name: Push image - run: | - docker push ${{ inputs.registry }}/${{ inputs.image-name }}:${{ inputs.tag }} - shell: bash diff --git a/.github/workflows/ci-pr-checks.yaml b/.github/workflows/ci-pr-checks.yaml index 776cc259..806996be 100644 --- a/.github/workflows/ci-pr-checks.yaml +++ b/.github/workflows/ci-pr-checks.yaml @@ -18,7 +18,7 @@ jobs: - name: Set up go with cache uses: actions/setup-go@v5 with: - go-version: '1.24.0' + go-version-file: ./go.mod cache-dependency-path: ./go.sum - name: Install libzmq dependencies (kvcache/kvevents) @@ -32,16 +32,11 @@ jobs: - name: Run lint checks uses: golangci/golangci-lint-action@v8 with: - version: 'v2.1.6' + version: 'v2.4.0' args: "--config=./.golangci.yml" - name: Run go test shell: bash run: | - echo "Installing Ginkgo..." - go install github.com/onsi/ginkgo/ginkgo@latest - export PATH=$PATH:$(go env GOPATH)/bin - echo "Ginkgo installed:" - ginkgo version echo "Running tests with Ginkgo..." make test diff --git a/Makefile b/Makefile index f2856f61..9af6abe9 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. +LOCALBIN ?= $(shell pwd)/bin +$(LOCALBIN): + mkdir -p $(LOCALBIN) + +# Project-specific Go tooling is defined in Makefile.tools.mk. +include Makefile.tools.mk + # Makefile for the llm-d-inference-sim project SHELL := /usr/bin/env bash @@ -75,12 +82,12 @@ format: ## Format Go source files @gofmt -l -w $(SRC) .PHONY: test -test: check-ginkgo download-tokenizer download-zmq ## Run tests +test: $(GINKGO) download-tokenizer download-zmq ## Run tests @printf "\033[33;1m==== Running tests ====\033[0m\n" ifdef GINKGO_FOCUS - CGO_ENABLED=1 ginkgo -ldflags="$(GO_LDFLAGS)" -v -r --focus="$(GINKGO_FOCUS)" + CGO_ENABLED=1 $(GINKGO) -ldflags="$(GO_LDFLAGS)" -v -r --focus="$(GINKGO_FOCUS)" else - CGO_ENABLED=1 ginkgo -ldflags="$(GO_LDFLAGS)" -v -r + CGO_ENABLED=1 $(GINKGO) -ldflags="$(GO_LDFLAGS)" -v -r endif .PHONY: post-deploy-test @@ -89,16 +96,16 @@ post-deploy-test: ## Run post deployment tests @echo "Post-deployment tests passed." .PHONY: lint -lint: check-golangci-lint check-golangci-lint-version ## Run lint +lint: $(GOLANGCI_LINT) ## Run lint @printf "\033[33;1m==== Running linting ====\033[0m\n" - golangci-lint run + $(GOLANGCI_LINT) run ##@ Build .PHONY: build build: check-go download-tokenizer download-zmq @printf "\033[33;1m==== Building ====\033[0m\n" - go build -ldflags="$(GO_LDFLAGS)" -o bin/$(PROJECT_NAME) cmd/$(PROJECT_NAME)/main.go + go build -ldflags="$(GO_LDFLAGS)" -o $(LOCALBIN)/$(PROJECT_NAME) cmd/$(PROJECT_NAME)/main.go ##@ Container Build/Push @@ -163,40 +170,12 @@ env: ## Print environment variables @echo "IMG=$(IMG)" @echo "CONTAINER_TOOL=$(CONTAINER_TOOL)" - ##@ Tools -.PHONY: check-tools -check-tools: - check-go \ - check-ginkgo \ - check-golangci-lint \ - check-container-tool \ - check-helm - @echo "✅ All required tools are installed." - .PHONY: check-go check-go: @command -v go >/dev/null 2>&1 || { \ echo "❌ Go is not installed. Install it from https://golang.org/dl/"; exit 1; } -.PHONY: check-ginkgo -check-ginkgo: - @command -v ginkgo >/dev/null 2>&1 || { \ - echo "❌ ginkgo is not installed. Install with: go install github.com/onsi/ginkgo/v2/ginkgo@latest"; exit 1; } - -.PHONY: check-golangci-lint -check-golangci-lint: - @command -v golangci-lint >/dev/null 2>&1 || { \ - echo "❌ golangci-lint is not installed. Install from https://golangci-lint.run/docs/welcome/install/"; exit 1; } - -.PHONY: check-golangci-lint-version -check-golangci-lint-version: - @version=$$(golangci-lint --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -n 1); \ - if [[ $$version != 2.* ]]; then \ - echo "❌ golangci-lint version 2.x is required. Current version: $$version"; \ - exit 1; \ - fi - .PHONY: check-container-tool check-container-tool: @command -v $(CONTAINER_TOOL) >/dev/null 2>&1 || { \ @@ -208,7 +187,6 @@ check-helm: @command -v helm >/dev/null 2>&1 || { \ echo "❌ helm is not installed. Install it from https://helm.sh/docs/intro/install/"; exit 1; } - .PHONY: check-builder check-builder: @if [ -z "$(BUILDER)" ]; then \ diff --git a/Makefile.tools.mk b/Makefile.tools.mk new file mode 100644 index 00000000..31e52ca7 --- /dev/null +++ b/Makefile.tools.mk @@ -0,0 +1,42 @@ +# Copyright 2025 The llm-d-inference-sim Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist +# $1 - target path with name of binary +# $2 - package url which can be installed +# $3 - specific version of package +# Source: https://github.com/kubernetes-sigs/kubebuilder/blob/3fd04199acb4556376dc17a7393bfd43bcd40c26/Makefile#L237-L251 +define go-install-tool +@[ -f "$(1)-$(3)" ] && [ "$$(readlink -- "$(1)" 2>/dev/null)" = "$(1)-$(3)" ] || { \ +set -e; \ +package=$(2)@$(3) ;\ +echo "Downloading $${package}" ;\ +rm -f $(1) ;\ +GOBIN=$(LOCALBIN) go install $${package} ;\ +mv $(1) $(1)-$(3) ;\ +} ;\ +ln -sf $$(realpath $(1)-$(3)) $(1) +endef + +GOLANGCI_LINT = $(LOCALBIN)/golangci-lint +GOLANGCI_LINT_VERSION = v2.4.0 +GINKGO = $(LOCALBIN)/ginkgo +GINKGO_VERSION = v2.25.3 + +$(GINKGO): $(LOCALBIN) + $(call go-install-tool,$(GINKGO),github.com/onsi/ginkgo/v2/ginkgo,$(GINKGO_VERSION)) + @GOBIN=$(LOCALBIN) go install -mod=readonly github.com/onsi/ginkgo/v2/ginkgo + +$(GOLANGCI_LINT): $(LOCALBIN) + $(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))