github.com/openshift-online/ocm-sdk-go@v0.1.473/Makefile (about)

     1  #
     2  # Copyright (c) 2018 Red Hat, Inc.
     3  #
     4  # Licensed under the Apache License, Version 2.0 (the "License");
     5  # you may not use this file except in compliance with the License.
     6  # You may obtain a copy of the License at
     7  #
     8  #   http://www.apache.org/licenses/LICENSE-2.0
     9  #
    10  # Unless required by applicable law or agreed to in writing, software
    11  # distributed under the License is distributed on an "AS IS" BASIS,
    12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  # See the License for the specific language governing permissions and
    14  # limitations under the License.
    15  #
    16  #
    17  #
    18  MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
    19  PROJECT_PATH := $(patsubst %/,%,$(dir $(MKFILE_PATH)))
    20  LOCAL_BIN_PATH := $(PROJECT_PATH)/bin
    21  
    22  # Add the project-level bin directory into PATH. Needed in order
    23  # for the tasks to use project-level bin directory binaries first
    24  export PATH := $(LOCAL_BIN_PATH):$(PATH)
    25  
    26  # Disable CGO so that we always generate static binaries:
    27  export CGO_ENABLED=0
    28  
    29  goimports_version:=v0.4.0
    30  
    31  # Additional flags to pass to the `ginkgo` command. This is used in the GitHub
    32  # actions environment to skip tests that are sensitive to the speed of the
    33  # machine: the leadership flag and retry tests.
    34  ginkgo_flags:=
    35  
    36  .DEFAULT_GOAL := examples
    37  
    38  GINKGO := $(LOCAL_BIN_PATH)/ginkgo
    39  ginkgo-install:
    40  	@GOBIN=$(LOCAL_BIN_PATH) go install github.com/onsi/ginkgo/v2/ginkgo@v2.1.4 ;\
    41  
    42  verify: lint examples model metamodel-install goimports-install verify-hooks
    43  	go vet $(find . -maxdepth 1 -type d  ! -name 'vendor' ! -name '.')
    44  	hack/verify-gofmt.sh
    45  	hack/verify-client.sh $(METAMODEL) .
    46  	hack/verify-openapi.sh $(METAMODEL) ./openapi
    47  .PHONY: verify
    48  
    49  .PHONY: install-hooks
    50  install-hooks:
    51  	@echo "Installing git hooks..."
    52  	@if [ -f hooks/pre-push ]; then \
    53  		cp hooks/pre-push .git/hooks/pre-push && \
    54  		chmod +x .git/hooks/pre-push && \
    55  		echo "Installed and made .git/hooks/pre-push executable"; \
    56  	else \
    57  		echo "Error: hooks/pre-push not found in repository"; \
    58  		exit 1; \
    59  	fi
    60  
    61  .PHONY: verify-hooks
    62  verify-hooks:
    63  	@echo "Verifying git hooks..."
    64  	@if [ -f .git/hooks/pre-push ]; then \
    65  		if [ -x .git/hooks/pre-push ]; then \
    66  			echo ".git/hooks/pre-push is executable"; \
    67  		else \
    68  			echo ".git/hooks/pre-push is not executable"; \
    69  			echo "  Run 'make install-hooks' to fix this"; \
    70  			exit 1; \
    71  		fi \
    72  	else \
    73  		echo "Warning: .git/hooks/pre-push not found"; \
    74  		echo "  Run 'make install-hooks' to install it"; \
    75  	fi
    76  
    77  .PHONY: examples
    78  examples:
    79  	cd examples && \
    80  	for i in *.go; do \
    81  		go build $${i} || exit 1; \
    82  	done
    83  
    84  .PHONY: test tests
    85  test tests: ginkgo-install
    86  ifndef JUNITFILE
    87  	$(GINKGO) run -r $(ginkgo_flags)
    88  else
    89  	$(GINKGO) run -r $(ginkgo_flags) --junit-report=junit_golang_tests_junit.xml --output-dir=${ARTIFACT_DIR}
    90  endif
    91  
    92  
    93  .PHONY: fmt
    94  fmt:
    95  	gofmt -s -l -w .
    96  
    97  .PHONY: lint
    98  lint:
    99  	golangci-lint --version
   100  	golangci-lint run
   101  
   102  # set "normal" alias matching kube and ocp
   103  .PHONY: update
   104  update: generate
   105  
   106  .PHONY: generate
   107  generate: model metamodel-install goimports-install
   108  	hack/generate-client.sh $(METAMODEL) .
   109  	hack/generate-openapi.sh $(METAMODEL) ./openapi
   110  
   111  .PHONY: model
   112  model:
   113  	go mod tidy && go mod vendor
   114  
   115  .PHONY: metamodel
   116  METAMODEL=$(PROJECT_PATH)/metamodel_generator/metamodel
   117  metamodel-install:
   118  	 $(MAKE) -C metamodel_generator clean
   119  	 $(MAKE) -C metamodel_generator build
   120  
   121  .PHONY: goimports
   122  goimports-install:
   123  	@GOBIN=$(LOCAL_BIN_PATH) go install golang.org/x/tools/cmd/goimports@$(goimports_version)
   124  
   125  .PHONY: clean
   126  clean:
   127  	hack/clean-client.sh
   128  	hack/clean-openapi.sh
   129  	rm -rf \
   130  		$(PROJECT_PATH)/metamodel_generator/metamodel \
   131  		model \
   132  		$(NULL)