59 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Makefile
		
	
	
	
			
		
		
	
	
			59 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Makefile
		
	
	
	
# Inspired from https://dustinspecker.com/posts/go-combined-unit-integration-code-coverage/ and https://netdevops.me/2023/test-coverage-for-go-integration-tests/
 | 
						|
BIN_DIR = $(CURDIR)/artifacts
 | 
						|
BINARY = $(BIN_DIR)/gocustomurls
 | 
						|
COVERAGE_DIR = $(CURDIR)/coverage
 | 
						|
CURRENT_DIR = $(shell pwd)
 | 
						|
CUR_TAG = $(shell git tag | sort -g | tail -1 | cut -c 2-)
 | 
						|
VERSION_NUMBER ?= 0.0.0
 | 
						|
 | 
						|
ifneq ($(CI_COMMIT_TAG),)
 | 
						|
	VERSION_NUMBER := $(CI_COMMIT_TAG:v%=%)
 | 
						|
else
 | 
						|
	VERSION_NUMBER := ${CUR_TAG}
 | 
						|
endif
 | 
						|
 | 
						|
.PHONY: clean
 | 
						|
clean:
 | 
						|
	go clean
 | 
						|
 | 
						|
.PHONY: dep
 | 
						|
dep:
 | 
						|
	go mod tidy
 | 
						|
 | 
						|
.PHONY: fmt
 | 
						|
fmt:
 | 
						|
	go fmt ./...
 | 
						|
 | 
						|
.PHONY: lint
 | 
						|
lint:
 | 
						|
	golangci-lint run --timeout 3m --verbose
 | 
						|
 | 
						|
.PHONY: build
 | 
						|
build:
 | 
						|
	go build -o $(BINARY)
 | 
						|
 | 
						|
.PHONY: build-debug
 | 
						|
build-debug:
 | 
						|
	mkdir -p $(BIN_DIR)
 | 
						|
	go build -cover -o $(BINARY) .
 | 
						|
 | 
						|
.PHONY: test
 | 
						|
test: build-debug
 | 
						|
	rm -rf $(COVERAGE_DIR)
 | 
						|
	mkdir -p $(COVERAGE_DIR)
 | 
						|
	go test -cover ./... -args -test.gocoverdir="$(COVERAGE_DIR)"
 | 
						|
 | 
						|
.PHONY: coverage-full
 | 
						|
coverage-full: test
 | 
						|
	go tool covdata textfmt -i=$(COVERAGE_DIR) -o $(COVERAGE_DIR)/coverage.out
 | 
						|
	go tool cover -func=$(COVERAGE_DIR)/coverage.out
 | 
						|
 | 
						|
.PHONY: coverage-integration
 | 
						|
coverage-integration:
 | 
						|
	go test ./... -run Integration -covermode=count -coverprofile=$(COVERAGE_DIR)/integration.out
 | 
						|
	go tool cover -func=$(COVERAGE_DIR)/integration.out
 | 
						|
 | 
						|
.PHONY: coverage-html
 | 
						|
coverage-html: coverage-full
 | 
						|
	go tool cover -html=./coverage/coverage.out -o ./coverage/coverage.html
 | 
						|
	# open ./coverage/coverage.html
 |