-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
112 lines (88 loc) · 4.37 KB
/
Copy pathMakefile
File metadata and controls
112 lines (88 loc) · 4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# For more details regarding Makefiles see: https://makefiletutorial.com
# Variables
VERSION_FILE = VERSION
VERSION := $(shell cat $(VERSION_FILE))
MAJOR := $(word 1,$(subst ., ,$(VERSION)))
MINOR := $(word 2,$(subst ., ,$(VERSION)))
PATCH := $(word 3,$(subst ., ,$(VERSION)))
TOTAL_COVERAGE := $(shell go test -cover | grep -Eo "coverage:\s*\d+\.\d+%" | grep -Eo "\d+\.\d+%")
COVERAGE_BADGE_URL := $(shell echo 'https://img.shields.io/badge/Coverage-_PERCENTAGE_-brightgreen\?style=flat' | sed -e "s/_PERCENTAGE_/$(TOTAL_COVERAGE)25/g")
# Misc
.DEFAULT_GOAL = help
## —— 🎵 🐳 The Secure Webhook Token Makefile 🐳 🎵 ————————————————————————————————————————————————————————————
.PHONY = help
help: ## Outputs this help screen
@grep -E '(^[a-zA-Z0-9_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}{printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m##/[33m/'
## —— Semantic Versioning 🐳 ———————————————————————————————————————————————————————————————————————————————————
.PHONY: major
major: _major _git_commit_and_tag ## Increase the major version
_major:
@echo "Bumping major version..."
$(eval NEW_MAJOR := $(shell echo $$(($(MAJOR)+1))))
$(eval NEW_VERSION := $(NEW_MAJOR).0.0)
@echo $(NEW_VERSION) > $(VERSION_FILE)
@echo "Updated version to: $(NEW_VERSION)"
.PHONY: minor
minor: _minor _git_commit_and_tag ## Increase the minor version
_minor:
@echo "Bumping minor version..."
$(eval NEW_MINOR := $(shell echo $$(($(MINOR)+1))))
$(eval NEW_VERSION := $(MAJOR).$(NEW_MINOR).0)
@echo $(NEW_VERSION) > $(VERSION_FILE)
@echo "Updated version to: $(NEW_VERSION)"
.PHONY: patch
patch: _patch _git_commit_and_tag ## Increase the patch version
_patch:
@echo "Bumping patch version..."
$(eval NEW_PATCH := $(shell echo $$(($(PATCH)+1))))
$(eval NEW_VERSION := $(MAJOR).$(MINOR).$(NEW_PATCH))
@echo $(NEW_VERSION) > $(VERSION_FILE)
@echo "Updated version to: $(NEW_VERSION)"
_git_commit_and_tag:
@git add VERSION
@git commit --amend -C HEAD
@git tag v$(NEW_VERSION)
@echo In order to update tags run: git push origin v$(NEW_VERSION)
.PHONY: show-version
show-version: ## Show current version
@echo Current version: $(VERSION)
## —— Go command 🧙 ————————————————————————————————————————————————————————————————————————————————————————————
.PHONY: lint
lint: ## Lint project
@golangci-lint run
.PHONY: fix-imports
fix-imports: ## Fix all imports with goimports
@goimports -w *.go
.PHONY: test
test: ## Run tests
@go test ./...
.PHONY: test-verbose
test-verbose: ## Run all tests verbose
@go test -v ./...
.PHONY: benchmark
benchmark: ## Run benchmark tests
@go test -cpu 1,2,4,8,12 -benchmem -bench . benchmark_test.go
.PHONY: update
update: update-internal lint test coverage ## Update all dependencies
.PHONY: update-internal
update-internal:
@go get -u all
@go mod tidy
## —— Code Coverage 🎵 —————————————————————————————————————————————————————————————————————————————————————————
.PHONY: coverage
coverage: show-total-coverage download-coverage-badge ## Show total code coverage and create a coverage badge within the assets folder
.PHONY: generate-coverage
generate-coverage: ## Generate coverage profile (coverage.out)
@go test -cover -coverprofile coverage.out .
.PHONY: download-coverage-badge
download-coverage-badge: ## Download the coverage badge and save it as (assets/coverage-badge.svg)
@curl -s -o assets/coverage-badge.svg $(COVERAGE_BADGE_URL)
.PHONY: show-total-coverage
show-total-coverage: ## Show total code coverage
@echo Total-Coverage: $(TOTAL_COVERAGE)
.PHONY: show-coverage-html
show-coverage-html: generate-coverage ## Visualize code coverage in browser
@go tool cover -html coverage.out
.PHONY: gocovsh
gocovsh: generate-coverage ## Show current code coverage with gocovsh
@gocovsh