From ebb07d66ace8d9941231bb21a81f8fdb7f83f37e Mon Sep 17 00:00:00 2001 From: Martin Necas Date: Fri, 25 Aug 2023 15:08:20 +0200 Subject: [PATCH] Update makefile with the local bin installs Signed-off-by: Martin Necas --- .github/workflows/check-pull-request.yaml | 3 --- .gitignore | 4 ++- Makefile | 32 ++++++++++++++++++----- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/.github/workflows/check-pull-request.yaml b/.github/workflows/check-pull-request.yaml index 87c41361..281d4b9f 100644 --- a/.github/workflows/check-pull-request.yaml +++ b/.github/workflows/check-pull-request.yaml @@ -78,9 +78,6 @@ jobs: with: go-version: '1.20' - - name: Setup Goimports - run: go install golang.org/x/tools/cmd/goimports@v0.4.0 - - name: Generate code run: make generate diff --git a/.gitignore b/.gitignore index e3e0dc30..c5d66237 100644 --- a/.gitignore +++ b/.gitignore @@ -2,10 +2,12 @@ /.idea/ /.vscode/ /examples/* -/metamodel /model/ /vendor/ !/examples/*.go !/examples/*.yaml !/examples/go.mod !/examples/go.sum + +# Local bin directory +bin diff --git a/Makefile b/Makefile index 409fd2ec..66e5b0c0 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,15 @@ model_url:=https://github.com/openshift-online/ocm-api-model.git # Details of the metamodel to use: metamodel_version:=v0.0.59 +MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST))) +PROJECT_PATH := $(patsubst %/,%,$(dir $(MKFILE_PATH))) +LOCAL_BIN_PATH := $(PROJECT_PATH)/bin +# Add the project-level bin directory into PATH. Needed in order +# for `go generate` to use project-level bin directory binaries first +export PATH := $(LOCAL_BIN_PATH):$(PATH) +GINKGO := $(LOCAL_BIN_PATH)/ginkgo +METAMODEL := $(LOCAL_BIN_PATH)/metamodel + # Additional flags to pass to the `ginkgo` command. This is used in the GitHub # actions environment to skip tests that are sensitive to the speed of the # machine: the leadership flag and retry tests. @@ -36,9 +45,18 @@ examples: go build $${i} || exit 1; \ done +.PHONY: ginkgo-install +ginkgo-install: + @GOBIN=$(LOCAL_BIN_PATH) go install github.com/onsi/ginkgo/v2/ginkgo@v2.1.4 + +# Needed for the golang metamodel generator. +.PHONY: goimports-install +goimports-install: + @GOBIN=$(LOCAL_BIN_PATH) go install golang.org/x/tools/cmd/goimports@v0.4.0 + .PHONY: test tests -test tests: - ginkgo run -r $(ginkgo_flags) +test tests: ginkgo-install + $(GINKGO) run -r $(ginkgo_flags) .PHONY: fmt fmt: @@ -50,7 +68,7 @@ lint: golangci-lint run .PHONY: generate -generate: model metamodel +generate: model metamodel goimports-install rm -rf \ accountsmgmt \ addonsmgmt \ @@ -65,11 +83,11 @@ generate: model metamodel webrca \ osdfleetmgmt \ openapi - metamodel generate go \ + $(METAMODEL) generate go \ --model=model/model \ --base=github.com/openshift-online/ocm-sdk-go \ --output=. - metamodel generate openapi \ + $(METAMODEL) generate openapi \ --model=model/model \ --output=openapi @@ -87,11 +105,11 @@ model: .PHONY: metamodel metamodel: - go install github.com/openshift-online/ocm-api-metamodel/cmd/metamodel@$(metamodel_version) + @GOBIN=$(LOCAL_BIN_PATH) go install github.com/openshift-online/ocm-api-metamodel/cmd/metamodel@$(metamodel_version) .PHONY: clean clean: rm -rf \ - metamodel \ + bin \ model \ $(NULL)