This repository has been archived by the owner on Jun 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
129 lines (112 loc) · 4.58 KB
/
Makefile
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
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec
.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Build
.PHONY: build
build: format ## Compiles the source code.
go build ./...
.PHONY: format
format: goimports-reviser gofumpt wsl ## Cleans up the code for easier reading and collaboration.
$(GOIMPORTS_REVISER) -use-cache -rm-unused -format ./...
$(GOFUMPT) -w -extra .
$(WSL) -fix ./...
##@ Release
.PHONY: current-version
current-version: svu ## Show the current version of the project.
@current_version=$$($(SVU) current); \
echo $$current_version
.PHONY: next-version
next-version: svu ## Calculate the next version, following semantic versioning.
@current_version=$$($(SVU) current); \
next_version=$$($(SVU) next); \
if [ "$$current_version" = "$$next_version" ]; then \
echo "Error: Current version is equal to next version."; \
exit 1; \
fi; \
echo $$next_version
.PHONY: auto-release
auto-release: build svu ## Automate release tasks based on git log.
@current_version=$$($(SVU) current); \
next_version=$$($(SVU) next); \
if [ "$$current_version" = "$$next_version" ]; then \
echo "Error: Current version is equal to next version."; \
exit 1; \
fi; \
current_branch=$$(git rev-parse --abbrev-ref HEAD); \
remote_branch=$$(git for-each-ref --format='%(upstream:short)' refs/heads/"$$current_branch"); \
if [ "$$remote_branch" != "origin/main" ]; then \
echo "Error: You are not in the main branch."; \
exit 1; \
fi; \
next_version=$$($(SVU) next); \
git tag -a $$next_version -m "release $$next_version"; \
git push origin $$next_version; \
echo "$$next_version has been released successfully"
.PHONY: major-release
major-release: build svu ## Force a major release with significant changes.
@current_branch=$$(git rev-parse --abbrev-ref HEAD); \
remote_branch=$$(git for-each-ref --format='%(upstream:short)' refs/heads/"$$current_branch"); \
if [ "$$remote_branch" != "origin/main" ]; then \
echo "Error: You are not in the main branch."; \
exit 1; \
fi; \
next_version=$$($(SVU) major); \
git tag -a $$next_version -m "release $$next_version"; \
git push origin $$next_version; \
echo "$$next_version has been released successfully"
.PHONY: minor-release
minor-release: build svu ## Force a minor release with new features.
@current_branch=$$(git rev-parse --abbrev-ref HEAD); \
remote_branch=$$(git for-each-ref --format='%(upstream:short)' refs/heads/"$$current_branch"); \
if [ "$$remote_branch" != "origin/main" ]; then \
echo "Error: You are not in the main branch."; \
exit 1; \
fi; \
next_version=$$($(SVU) minor); \
git tag -a $$next_version -m "release $$next_version"; \
git push origin $$next_version; \
echo "$$next_version has been released successfully"
.PHONY: patch-release
patch-release: build svu ## Force a patch release with bug fixes.
@current_branch=$$(git rev-parse --abbrev-ref HEAD); \
remote_branch=$$(git for-each-ref --format='%(upstream:short)' refs/heads/"$$current_branch"); \
if [ "$$remote_branch" != "origin/main" ]; then \
echo "Error: You are not in the main branch."; \
exit 1; \
fi; \
next_version=$$($(SVU) patch); \
git tag -a $$next_version -m "release $$next_version"; \
git push origin $$next_version; \
echo "$$next_version has been released successfully"
##@ Tool Binaries
SVU = $(shell pwd)/bin/svu
.PHONY: svu
svu: ## Checks for svu installation and downloads it if not found.
$(call go-get-tool,$(SVU),github.com/caarlos0/svu@v1.11.0)
GOIMPORTS_REVISER = $(shell pwd)/bin/goimports-reviser
.PHONY: goimports-reviser
goimports-reviser: ## Checks for goimports-reviser installation and downloads it if not found.
$(call go-get-tool,$(GOIMPORTS_REVISER),github.com/incu6us/goimports-reviser/v3@v3.4.5)
GOFUMPT = $(shell pwd)/bin/gofumpt
.PHONY: gofumpt
gofumpt: ## Checks for gofumpt installation and downloads it if not found.
$(call go-get-tool,$(GOFUMPT),mvdan.cc/gofumpt@v0.5.0)
WSL = $(shell pwd)/bin/wsl
.PHONY: wsl
wsl: ## Checks for wsl installation and downloads it if not found.
$(call go-get-tool,$(WSL),github.com/bombsimon/wsl/v4/cmd...@v4.1.0)
# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef