From a43b04c95da928daf508b94df379399adea0379e Mon Sep 17 00:00:00 2001 From: Martin Necas Date: Fri, 25 Aug 2023 13:33:34 +0200 Subject: [PATCH] Update makefile: Add ginkgo-install and add binary gen for necessary targets Signed-off-by: Martin Necas --- .github/workflows/check-pull-request.yaml | 6 ----- .gitignore | 3 +++ Makefile | 30 +++++++++++++++++------ 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/.github/workflows/check-pull-request.yaml b/.github/workflows/check-pull-request.yaml index 2378ebc..e20c6df 100644 --- a/.github/workflows/check-pull-request.yaml +++ b/.github/workflows/check-pull-request.yaml @@ -36,11 +36,5 @@ jobs: with: go-version: 1.17 - - name: Setup Ginkgo - run: go install github.com/onsi/ginkgo/v2/ginkgo@v2.1.3 - - - name: Setup Goimports - run: go install golang.org/x/tools/cmd/goimports@v0.0.0-20200518194103-259583f2d8a9 - - name: Run the tests run: make tests diff --git a/.gitignore b/.gitignore index ba0eace..6483fa4 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,6 @@ /model/ /openapi_generator /tests/*/generated/ + +# Local bin directory +bin diff --git a/Makefile b/Makefile index 374cf9c..11287d8 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,14 @@ # Disable CGO so that we always generate static binaries: export CGO_ENABLED=0 +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 + # Details of the version of 'antlr' to use: antlr_version:=4.9.3 antlr_url:=https://www.antlr.org/download/antlr-$(antlr_version)-complete.jar @@ -43,6 +51,14 @@ antlr: wget --progress=dot:giga --output-document="$@" "$(antlr_url)" echo "$(antlr_sum) $@" | sha256sum --check +.PHONY: ginkgo_install +ginkgo_install: + @GOBIN=$(LOCAL_BIN_PATH) go install github.com/onsi/ginkgo/v2/ginkgo@v2.1.3 + +.PHONY: goimports_install +goimports_install: + @GOBIN=$(LOCAL_BIN_PATH) go install golang.org/x/tools/cmd/goimports@v0.0.0-20200518194103-259583f2d8a9 + .PHONY: fmt fmt: gofmt -s -l -w \ @@ -59,20 +75,20 @@ test tests: $(MAKE) docs_tests .PHONY: unit_tests -unit_tests: - ginkgo -r pkg +unit_tests: ginkgo_install + $(GINKGO) -r pkg .PHONY: golang_tests -go_tests: binary +go_tests: binary ginkgo_install goimports_install rm -rf tests/go/generated ./metamodel generate go \ --model=tests/model \ --base=github.com/openshift-online/ocm-api-metamodel/tests/go/generated \ --output=tests/go/generated - cd tests/go && ginkgo -r + cd tests/go && $(GINKGO) -r .PHONY: openapi_tests -openapi_tests: openapi_generator +openapi_tests: openapi_generator binary rm -rf tests/openapi/generated ./metamodel generate openapi --model=tests/model --output=tests/openapi/generated for spec in $$(find tests/openapi -name '*.json'); do \ @@ -84,7 +100,7 @@ openapi_generator: echo "$(openapi_generator_sum) $@" | sha256sum --check .PHONY: docs_tests -docs_tests: +docs_tests: binary rm -rf tests/docs/generated ./metamodel generate docs --model=tests/model --output=tests/docs/generated @@ -93,8 +109,8 @@ clean: rm -rf \ .gobin \ antlr \ - metamodel \ model \ + bin \ openapi_generator \ tests/*/generated \ $(NULL)