-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
161 lines (128 loc) · 5.71 KB
/
Makefile
File metadata and controls
161 lines (128 loc) · 5.71 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
SHELL := /usr/bin/env bash
# ====================================================================================
# Colors
# ------------------------------------------------------------------------------------
black := $(shell printf "\033[30m")
black-bold := $(shell printf "\033[30;1m")
red := $(shell printf "\033[31m")
red-bold := $(shell printf "\033[31;1m")
green := $(shell printf "\033[32m")
green-bold := $(shell printf "\033[32;1m")
yellow := $(shell printf "\033[33m")
yellow-bold := $(shell printf "\033[33;1m")
blue := $(shell printf "\033[34m")
blue-bold := $(shell printf "\033[34;1m")
magenta := $(shell printf "\033[35m")
magenta-bold := $(shell printf "\033[35;1m")
cyan := $(shell printf "\033[36m")
cyan-bold := $(shell printf "\033[36;1m")
white := $(shell printf "\033[37m")
white-bold := $(shell printf "\033[37;1m")
reset := $(shell printf "\033[0m")
# ====================================================================================
# Logger
# ------------------------------------------------------------------------------------
time-long = $(date +%Y-%m-%d' '%H:%M:%S)
time-short = $(date +%H:%M:%S)
time = $(time-short)
information = echo $(time) $(blue)[ DEBUG ]$(reset)
warning = echo $(time) $(yellow)[ WARNING ]$(reset)
exception = echo $(time) $(red)[ ERROR ]$(reset)
complete = echo $(time) $(green)[ COMPLETE ]$(reset)
fail = (echo $(time) $(red)[ FAILURE ]$(reset) && false)
# ====================================================================================
# Utility Command(s)
# ------------------------------------------------------------------------------------
url = $(shell git config --get remote.origin.url | sed -r 's/.*(\@|\/\/)(.*)(\:|\/)([^:\/]*)\/([^\/\.]*)\.git/https:\/\/\2\/\4\/\5/')
repository = $(shell basename -s .git $(shell git config --get remote.origin.url))
organization = $(shell git remote -v | grep "(fetch)" | sed 's/.*\/\([^ ]*\)\/.*/\1/')
package = $(shell printf "github.com/%s/%s" "$(organization)" "$(repository)")
version = $(shell [ -f VERSION ] && head VERSION || echo "0.0.0")
major = $(shell echo $(version) | sed "s/^\([0-9]*\).*/\1/")
minor = $(shell echo $(version) | sed "s/[0-9]*\.\([0-9]*\).*/\1/")
patch = $(shell echo $(version) | sed "s/[0-9]*\.[0-9]*\.\([0-9]*\).*/\1/")
zero = $(shell printf "%s" "0")
major-upgrade = $(shell expr $(major) + 1).$(zero).$(zero)
minor-upgrade = $(major).$(shell expr $(minor) + 1).$(zero)
patch-upgrade = $(major).$(minor).$(shell expr $(patch) + 1)
dirty = $(shell git diff --quiet)
dirty-contents = $(shell git diff --shortstat 2>/dev/null 2>/dev/null | tail -n1)
# ====================================================================================
# Package-Specific Target(s)
# ------------------------------------------------------------------------------------
all :: patch-release
install:
@brew update
@brew tap iac-factory/homebrew-taps
@brew install versioning-cli --force
@brew update && brew upgrade versioning-cli
tidy:
@go mod tidy && go mod vendor
test: tidy
@go test ./...
# --> patch
bump-patch: test
@if ! git diff --quiet --exit-code; then \
echo "$(red-bold)Dirty Working Tree$(reset) - Commit Changes and Try Again"; \
exit 1; \
else \
echo "$(patch-upgrade)" > VERSION; \
fi
commit-patch: bump-patch
@echo "$(blue-bold)Tag-Release (Patch)$(reset): \"$(yellow-bold)$(package)$(reset)\" - $(white-bold)$(version)$(reset)"
@git add VERSION
@git commit --message "Tag-Release (Patch): \"$(package)\" - $(version)"
@git push --set-upstream origin main
@git tag "v$(version)"
@git push origin "v$(version)"
@echo "$(green-bold)Published Tag$(reset): $(version)"
release-patch: commit-patch
@echo "$(blue-bold)Deployment (Patch)$(reset): \"$(yellow-bold)$(package)$(reset)\" - $(white-bold)$(version)$(reset)"
@unset GITLAB_TOKEN
@goreleaser release --clean
@echo "$(green-bold)Successful$(reset): $(version)"
patch-release: release-patch install
# --> minor
bump-minor: test
@if ! git diff --quiet --exit-code; then \
echo "$(red-bold)Dirty Working Tree$(reset) - Commit Changes and Try Again"; \
exit 1; \
else \
echo "$(minor-upgrade)" > VERSION; \
fi
commit-minor: bump-minor
@echo "$(blue-bold)Tag-Release (Minor)$(reset): \"$(yellow-bold)$(package)$(reset)\" - $(white-bold)$(version)$(reset)"
@git add VERSION
@git commit --message "Tag-Release (Minor): \"$(package)\" - $(version)"
@git push --set-upstream origin main
@git tag "v$(version)"
@git push origin "v$(version)"
@echo "$(green-bold)Published Tag$(reset): $(version)"
release-minor: commit-minor
@echo "$(blue-bold)Deployment (Minor)$(reset): \"$(yellow-bold)$(package)$(reset)\" - $(white-bold)$(version)$(reset)"
@unset GITLAB_TOKEN
@goreleaser release --clean
@echo "$(green-bold)Successful$(reset): $(version)"
minor-release: release-minor install
# --> major
bump-major: test
@if ! git diff --quiet --exit-code; then \
echo "$(red-bold)Dirty Working Tree$(reset) - Commit Changes and Try Again"; \
exit 1; \
else \
echo "$(major-upgrade)" > VERSION; \
fi
commit-major: bump-major
@echo "$(blue-bold)Tag-Release (Major)$(reset): \"$(yellow-bold)$(package)$(reset)\" - $(white-bold)$(version)$(reset)"
@git add VERSION
@git commit --message "Tag-Release (Major): \"$(package)\" - $(version)"
@git push --set-upstream origin main
@git tag "v$(version)"
@git push origin "v$(version)"
@echo "$(green-bold)Published Tag$(reset): $(version)"
release-major: commit-major
@echo "$(blue-bold)Deployment (Major)$(reset): \"$(yellow-bold)$(package)$(reset)\" - $(white-bold)$(version)$(reset)"
@unset GITLAB_TOKEN
@goreleaser release --clean
@echo "$(green-bold)Successful$(reset): $(version)"
major-release: release-major install