Skip to content
Snippets Groups Projects
Makefile 3.82 KiB
Newer Older
  • Learn to ignore specific revisions
  • ifeq ($(wildcard dependencies/go-orusapi),)
    $(error Run hg cfensureconf to clone the dependencies)
    endif
    
    
    Axel Prel's avatar
    Axel Prel committed
    VERSIONTAG = dev
    VCSCOMMIT = $(shell hg id --id)
    
    Christophe de Vienne's avatar
    Christophe de Vienne committed
    
    GOSWAGGER_VERSION = v0.24.0
    GOSWAGGER_BIN = tools/bin/swagger-$(GOSWAGGER_VERSION)
    
    
    Axel Prel's avatar
    Axel Prel committed
    GOLANGCI_LINT_VERSION = v1.64.8
    
    Christophe de Vienne's avatar
    Christophe de Vienne committed
    GOLANGCI_LINT_BIN = tools/bin/golangci-lint-$(GOLANGCI_LINT_VERSION)
    
    
    Axel Prel's avatar
    Axel Prel committed
    BASEVERSION = $(shell grep version: swagger.yaml| cut -f2 -d: |xargs)
    VERSION = $(BASEVERSION)
    ifneq ($(VERSIONTAG), "")
      VERSION = $(BASEVERSION)-$(VERSIONTAG)
      ifneq ($(VCSCOMMIT), "")
        VERSION = $(BASEVERSION)-$(VERSIONTAG).$(VCSCOMMIT)
      endif
    endif
    
    LDFLAGS =  -X orus.io/orus-io/rednerd/cmd/rednerd/cmd.Version=$(VERSION) -X orus.io/orus-io/rednerd/restapi.VersionTag=$(VERSIONTAG) -X orus.io/orus-io/rednerd/restapi.VCSCommit=$(VCSCOMMIT)
    GOFLAGS =
    GOBUILD = CGO_ENABLED=1 go build  -ldflags '$(LDFLAGS)'
    
    
    
    VCS_REF ?= $(shell hg --debug identify -i)
    BUILD_DATE ?= $(shell date --rfc-3339=seconds)
    VCS_URL ?= $(shell hg config paths.default)
    ifeq ($(origin VERSION), undefined)
    	TOPIC ::= $(shell hg topics --current)
    	BRANCH ::= $(shell hg identify --branch)
    	ifeq ($(origin VERSION),)
    		VERSION = branch-$(BRANCH)
    	else
    		VERSION = topic-$(BRANCH)-$(TOPIC)
    	endif
    endif
    
    Axel Prel's avatar
    Axel Prel committed
    print-%  : ; @echo $* = $($*)
    
    
    Christophe de Vienne's avatar
    Christophe de Vienne committed
    help:  ## Display this help
    	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
    		| awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
    
    
    $(GOSWAGGER_BIN):
    	mkdir -p tools/bin
    	download_url=$$(curl -s https://api.github.com/repos/go-swagger/go-swagger/releases/tags/$(GOSWAGGER_VERSION) \
    		| jq -r '.assets[] | select(.name | contains("'"$$(uname | tr '[:upper:]' '[:lower:]')"'_amd64")) | .browser_download_url') \
    		&& curl -o $@ -L'#' "$$download_url" \
    		&& chmod +x $@
    
    $(GOLANGCI_LINT_BIN):
    	mkdir -p tools/bin
    	if (which curl) then \
    		curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh; \
    	else \
    		wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh; \
    	fi \
    		| sh -s -- -b $$(go env GOPATH)/bin $(GOLANGCI_LINT_VERSION) \
    	&& cp $$(go env GOPATH)/bin/golangci-lint $(GOLANGCI_LINT_BIN)
    
    .PHONY: generate-swagger
    
    generate-swagger:  $(GOSWAGGER_BIN) ## Using swagger.yaml, generates API internal models
    
    Christophe de Vienne's avatar
    Christophe de Vienne committed
    	rm -rf restapi/operations
    	$(GOSWAGGER_BIN) generate server \
    		--name Rednerd \
    		--main-package rednerd \
    		--principal models.Principal \
    
    Christophe de Vienne's avatar
    Christophe de Vienne committed
    		-f swagger.yaml
    
    	rm restapi/server.go
    
    	$(GOSWAGGER_BIN) generate server \
    		--name Rednerd \
    		--main-package rednerd \
    		--principal models.Principal \
    		-f swagger.yaml \
    		-C server.yaml --template-dir ./tools/swagger-templates \
    		--exclude-main --exclude-spec --skip-models
    
    generate-models: generate-swagger ## Generate the package models (API internal data models)
    
    	go generate ./models
    
    
    generate: generate-swagger generate-models ## generates swagger, models
    
    Christophe de Vienne's avatar
    Christophe de Vienne committed
    .PHONY: lint
    lint: $(GOLANGCI_LINT_BIN) ## Lint the files
    
    	$(GOLANGCI_LINT_BIN) run $(GOLANGCI_LINT_ARGS)
    
    .PHONY: lint-fix
    lint-fix: $(GOLANGCI_LINT_BIN) ## Lint & fix the files
    	$(GOLANGCI_LINT_BIN) run --fix $(GOLANGCI_LINT_ARGS)
    
    .PHONY: govulncheck-fetch
    
    Axel Prel's avatar
    Axel Prel committed
    govulncheck-fetch: ## Fetches govulncheck
    
    	go install golang.org/x/vuln/cmd/govulncheck@latest
    
    .PHONY: vulncheck
    
    Axel Prel's avatar
    Axel Prel committed
    vulncheck: govulncheck-fetch ## Run vulncheck
    
    Axel Prel's avatar
    Axel Prel committed
    .PHONY: vvulncheck
    vvulncheck: govulncheck-fetch ## Run vulncheck in verbose
    	govulncheck -show verbose ./...
    
    
    Christophe de Vienne's avatar
    Christophe de Vienne committed
    .PHONY: test
    
    Christophe de Vienne's avatar
    Christophe de Vienne committed
    test: ## Run the tests
    	go test ./...
    
    Christophe de Vienne's avatar
    Christophe de Vienne committed
    test-short: ## Run the short version of the tests
    	go test -short ./...
    
    build/rednerd: $(shell find dependencies cmd)
    
    Christophe de Vienne's avatar
    Christophe de Vienne committed
    	mkdir -p build
    	$(GOBUILD) -o build/rednerd ./cmd/rednerd
    
    Axel Prel's avatar
    Axel Prel committed
    clean-build: ## Removes the rednerd binary
    
    	rm -f build/rednerd
    
    .PHONY: build
    build: clean-build build/rednerd ## Build the rednerd binary, forcing a clean