Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
147 lines (115 loc) · 5.32 KB
/
Copy pathMakefile
File metadata and controls
147 lines (115 loc) · 5.32 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# For more details regarding Makefiles see: https://makefiletutorial.com
SHELL := /bin/bash
.SHELLFLAGS := -eu -o pipefail -c
.DELETE_ON_ERROR:
MAKEFLAGS += --warn-undefined-variables
# Configuration
GO ?= go
PKG ?= .
TEST_FLAGS ?= -race
VERSION_FILE ?= VERSION
VERSION := $(shell cat $(VERSION_FILE) 2>/dev/null || echo "0.0.0")
MAJOR := $(word 1,$(subst ., ,$(VERSION)))
MINOR := $(word 2,$(subst ., ,$(VERSION)))
PATCH := $(word 3,$(subst ., ,$(VERSION)))
.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: _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: _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: _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)"
.PHONY: _git_commit_and_tag
_git_commit_and_tag:
@git add $(VERSION_FILE)
@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)"
## —— Quality & Security 🧙 ———————————————————————————————————————————————————————————————————————————————————
.PHONY: fmt
fmt: ## Format code with go fmt
@$(GO) fmt ./...
.PHONY: gofumpt
gofumpt: ## Format code with gofumpt (stricter gofmt)
@gofumpt -w .
.PHONY: lint
lint: ## Lint project with golangci-lint
@golangci-lint run
.PHONY: fix-imports
fix-imports: ## Fix all imports with goimports
@goimports -w *.go
.PHONY: test
test: ## Run unit tests with race detection
@$(GO) test $(TEST_FLAGS) ./...
.PHONY: test-verbose
test-verbose: ## Run all tests verbose
@$(GO) test -v $(TEST_FLAGS) ./...
.PHONY: test-short
test-short: ## Run tests in short mode
@$(GO) test -short ./...
.PHONY: benchmark bench
benchmark: ## Run benchmark tests
@$(GO) test -benchmem -bench=. ./...
bench: benchmark ## Alias for benchmark
.PHONY: vuln
vuln: ## Run security checks (gosec and govulncheck)
@gosec ./...
@govulncheck ./...
.PHONY: check
check: fmt gofumpt lint test vuln ## Run all verification checks (fmt, gofumpt, lint, test, vuln)
.PHONY: update
update: update-internal lint test coverage ## Update all dependencies and verify
.PHONY: update-internal
update-internal:
@$(GO) get -u all
@$(GO) mod tidy
## —— Code Coverage 🎵 —————————————————————————————————————————————————————————————————————————————————————————
.PHONY: coverage
coverage: generate-coverage show-total-coverage download-coverage-badge ## Run tests, generate coverage profile and update badge
.PHONY: generate-coverage
generate-coverage: ## Generate coverage profile (coverage.out)
@$(GO) test -cover -coverprofile=coverage.out $(PKG)
.PHONY: show-total-coverage
show-total-coverage: generate-coverage ## Show total code coverage percentage
@$(eval TOTAL_COV := $(shell $(GO) tool cover -func=coverage.out | grep "total:" | awk '{print $$3}'))
@echo "Total Coverage: $(TOTAL_COV)"
.PHONY: download-coverage-badge
download-coverage-badge: generate-coverage ## Download the coverage badge and save it as assets/coverage-badge.svg
@$(eval TOTAL_COV := $(shell $(GO) tool cover -func=coverage.out | grep "total:" | awk '{print $$3}'))
@mkdir -p assets
@curl -s -o assets/coverage-badge.svg "https://img.shields.io/badge/Coverage-$(subst %,%25,$(TOTAL_COV))-brightgreen?style=flat"
.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 coverage.out
.PHONY: clean
clean: ## Remove generated test and coverage artifacts
@rm -f coverage.out