github.com/NpoolPlatform/chain-middleware@v0.0.0-20240228100535-eb1bcf896eb9/Makefile (about)

     1  REPO_ROOT	:= $(shell git rev-parse --show-toplevel)
     2  
     3  .DEFAULT_GOAL:=help
     4  SHELL:=/usr/bin/env bash
     5  
     6  COLOR:=\\033[36m
     7  NOCOLOR:=\\033[0m
     8  GITREPO=$(shell git remote -v | grep fetch | awk '{print $$2}' | sed 's/\.git//g' | sed 's/https:\/\///g')
     9  SUBCMDS=$(wildcard cmd/*)
    10  SERVICES=$(SUBCMDS:cmd/%=%)
    11  SERVICEIMAGES=$(SERVICES:%=%-image)
    12  SERVICEIMAGERELEASES=$(SERVICES:%=%-release)
    13  SERVICEK8SDEPLOYS=$(SERVICES:%=%-k8s-deploy)
    14  
    15  ##@ init project
    16  init:
    17  	cp -f .githooks/* .git/hooks
    18  
    19  go.mod:
    20  	go mod init ${GITREPO}
    21  	go mod tidy -compat=1.17
    22  
    23  deps:
    24  	go get github.com/ugorji/go/codec@latest
    25  	go get -d ./...
    26  	go mod tidy -compat=1.17
    27  
    28  ##@ Verify
    29  
    30  .PHONY: add-verify-hook verify verify-build verify-golangci-lint verify-go-mod verify-shellcheck verify-spelling all
    31  
    32  add-verify-hook: ## Adds verify scripts to git pre-commit hooks.
    33  # Note: The pre-commit hooks can be bypassed by using the flag --no-verify when
    34  # performing a git commit.
    35  	git config --local core.hooksPath "${REPO_ROOT}/.githooks"
    36  
    37  # TODO(lint): Uncomment verify-shellcheck once we finish shellchecking the repo.
    38  verify: go.mod verify-build verify-golangci-lint verify-go-mod #verify-shellcheck ## Runs verification scripts to ensure correct execution
    39  	${REPO_ROOT}/hack/verify.sh
    40  
    41  verify-build: ## Builds the project for a chosen set of platforms
    42  	${REPO_ROOT}/hack/verify-build.sh ...
    43  
    44  verify-go-mod: ## Runs the go module linter
    45  	${REPO_ROOT}/hack/verify-go-mod.sh
    46  
    47  verify-golangci-lint: ## Runs all golang linters
    48  	${REPO_ROOT}/hack/verify-golangci-lint.sh
    49  
    50  verify-shellcheck: ## Runs shellcheck
    51  	${REPO_ROOT}/hack/verify-shellcheck.sh
    52  
    53  verify-spelling: ## Verifies spelling.
    54  	${REPO_ROOT}/hack/verify-spelling.sh
    55  
    56  gen-ent:
    57  	go install entgo.io/ent/cmd/ent@v0.11.2
    58  	go run -mod=mod entgo.io/ent/cmd/ent generate --feature entql,sql/lock,sql/execquery,sql/upsert,privacy,schema/snapshot,sql/modifier ./pkg/db/ent/schema
    59  
    60  all: verify-build
    61  
    62  ${SERVICES}:
    63  	${REPO_ROOT}/hack/verify-build.sh $@
    64  
    65  ${SERVICEIMAGES}:
    66  	${REPO_ROOT}/hack/generate-docker-image.sh $(@:%-image=%) $(DOCKER_REGISTRY)
    67  
    68  ${SERVICEIMAGERELEASES}:
    69  	${REPO_ROOT}/hack/release-docker-image.sh $(@:%-release=%) $(DOCKER_REGISTRY)
    70  
    71  ${SERVICEK8SDEPLOYS}:
    72  	${REPO_ROOT}/hack/deploy-to-k8s-cluster.sh $(@:%-k8s-deploy=%)
    73  
    74  generate-docker-images: ${SERVICES} ${SERVICEIMAGES}
    75  release-docker-images: ${generate-docker-images} ${SERVICEIMAGERELEASES}
    76  deploy-to-k8s-cluster: ${SERVICEK8SDEPLOYS}
    77  
    78  ##@ Tests
    79  
    80  .PHONY: test test-go-unit test-go-integration
    81  
    82  before-test: verify-build
    83  	${REPO_ROOT}/hack/before-test.sh
    84  
    85  test: verify-build test-go-unit ## Runs unit tests
    86  test-verbose:
    87  	VERBOSE=1 make test
    88  
    89  after-test:
    90  	${REPO_ROOT}/hack/after-test.sh
    91  
    92  test-go-unit: ## Runs Golang unit tests
    93  	${REPO_ROOT}/hack/test-go.sh
    94  
    95  
    96  ##@ Helpers
    97  
    98  .PHONY: help
    99  
   100  help:  ## Display this help
   101  	@awk \
   102  		-v "col=${COLOR}" -v "nocol=${NOCOLOR}" \
   103  		' \
   104  			BEGIN { \
   105  				FS = ":.*##" ; \
   106  				printf "\nUsage:\n  make %s<target>%s\n", col, nocol \
   107  			} \
   108  			/^[a-zA-Z_-]+:.*?##/ { \
   109  				printf "  %s%-15s%s %s\n", col, $$1, nocol, $$2 \
   110  			} \
   111  			/^##@/ { \
   112  				printf "\n%s%s%s\n", col, substr($$0, 5), nocol \
   113  			} \
   114  		' $(MAKEFILE_LIST)