@@ -22,6 +22,99 @@ ifneq ($(wildcard build/custom.mk),)
22
22
include build/custom.mk
23
23
endif
24
24
25
+ # ====================================================================================
26
+ # Used for semver bumping
27
+ PROTECTED_BRANCH := master
28
+ APP_NAME := $(shell basename -s .git `git config --get remote.origin.url`)
29
+ CURRENT_VERSION := $(shell git describe --abbrev=0 --tags)
30
+ VERSION_PARTS := $(subst ., ,$(subst v,,$(subst -rc, ,$(CURRENT_VERSION ) ) ) )
31
+ MAJOR := $(word 1,$(VERSION_PARTS ) )
32
+ MINOR := $(word 2,$(VERSION_PARTS ) )
33
+ PATCH := $(word 3,$(VERSION_PARTS ) )
34
+ RC := $(shell echo $(CURRENT_VERSION ) | grep -oE 'rc[0-9]+' | sed 's/rc//')
35
+ # Check if current branch is protected
36
+ define check_protected_branch
37
+ @current_branch=$$(git rev-parse --abbrev-ref HEAD ) ; \
38
+ if ! echo "$(PROTECTED_BRANCH ) " | grep -wq "$$current_branch"; then \
39
+ echo "Error: Tagging is only allowed from $(PROTECTED_BRANCH ) branch. You are on $$current_branch branch."; \
40
+ exit 1; \
41
+ fi
42
+ endef
43
+ # Check if there are pending pulls
44
+ define check_pending_pulls
45
+ @git fetch; \
46
+ current_branch=$$(git rev-parse --abbrev-ref HEAD ) ; \
47
+ if [ "$$(git rev-parse HEAD ) " != "$$(git rev-parse origin/$$current_branch ) " ]; then \
48
+ echo "Error: Your branch is not up to date with upstream. Please pull the latest changes before performing a release"; \
49
+ exit 1; \
50
+ fi
51
+ endef
52
+ # ====================================================================================
53
+
54
+ .PHONY : patch minor major patch-rc minor-rc major-rc
55
+
56
+ patch : # # to bump patch version (semver)
57
+ $(call check_protected_branch)
58
+ $(call check_pending_pulls)
59
+ @$(eval PATCH := $(shell echo $$(($(PATCH ) +1 ) ) ) )
60
+ @echo Bumping $(APP_NAME ) to Patch version $(MAJOR ) .$(MINOR ) .$(PATCH )
61
+ git tag -s -a v$(MAJOR ) .$(MINOR ) .$(PATCH ) -m " Bumping $( APP_NAME) to Patch version $( MAJOR) .$( MINOR) .$( PATCH) "
62
+ git push origin v$(MAJOR ) .$(MINOR ) .$(PATCH )
63
+ @echo Bumped $(APP_NAME ) to Patch version $(MAJOR ) .$(MINOR ) .$(PATCH )
64
+
65
+ minor : # # to bump minor version (semver)
66
+ $(call check_protected_branch)
67
+ $(call check_pending_pulls)
68
+ @$(eval MINOR := $(shell echo $$(($(MINOR ) +1 ) ) ) )
69
+ @$(eval PATCH := 0)
70
+ @echo Bumping $(APP_NAME ) to Minor version $(MAJOR ) .$(MINOR ) .$(PATCH )
71
+ git tag -s -a v$(MAJOR ) .$(MINOR ) .$(PATCH ) -m " Bumping $( APP_NAME) to Minor version $( MAJOR) .$( MINOR) .$( PATCH) "
72
+ git push origin v$(MAJOR ) .$(MINOR ) .$(PATCH )
73
+ @echo Bumped $(APP_NAME ) to Minor version $(MAJOR ) .$(MINOR ) .$(PATCH )
74
+
75
+ major : # # to bump major version (semver)
76
+ $(call check_protected_branch)
77
+ $(call check_pending_pulls)
78
+ $(eval MAJOR := $(shell echo $$(($(MAJOR ) +1 ) ) ) )
79
+ $(eval MINOR := 0)
80
+ $(eval PATCH := 0)
81
+ @echo Bumping $(APP_NAME ) to Major version $(MAJOR ) .$(MINOR ) .$(PATCH )
82
+ git tag -s -a v$(MAJOR ) .$(MINOR ) .$(PATCH ) -m " Bumping $( APP_NAME) to Major version $( MAJOR) .$( MINOR) .$( PATCH) "
83
+ git push origin v$(MAJOR ) .$(MINOR ) .$(PATCH )
84
+ @echo Bumped $(APP_NAME ) to Major version $(MAJOR ) .$(MINOR ) .$(PATCH )
85
+
86
+ patch-rc : # # to bump patch release candidate version (semver)
87
+ $(call check_protected_branch)
88
+ $(call check_pending_pulls)
89
+ @$(eval RC := $(shell echo $$(($(RC ) +1 ) ) ) )
90
+ @echo Bumping $(APP_NAME ) to Patch RC version $(MAJOR ) .$(MINOR ) .$(PATCH ) -rc$(RC )
91
+ git tag -s -a v$(MAJOR ) .$(MINOR ) .$(PATCH ) -rc$(RC ) -m " Bumping $( APP_NAME) to Patch RC version $( MAJOR) .$( MINOR) .$( PATCH) -rc$( RC) "
92
+ git push origin v$(MAJOR ) .$(MINOR ) .$(PATCH ) -rc$(RC )
93
+ @echo Bumped $(APP_NAME ) to Patch RC version $(MAJOR ) .$(MINOR ) .$(PATCH ) -rc$(RC )
94
+
95
+ minor-rc : # # to bump minor release candidate version (semver)
96
+ $(call check_protected_branch)
97
+ $(call check_pending_pulls)
98
+ @$(eval MINOR := $(shell echo $$(($(MINOR ) +1 ) ) ) )
99
+ @$(eval PATCH := 0)
100
+ @$(eval RC := 1)
101
+ @echo Bumping $(APP_NAME ) to Minor RC version $(MAJOR ) .$(MINOR ) .$(PATCH ) -rc$(RC )
102
+ git tag -s -a v$(MAJOR ) .$(MINOR ) .$(PATCH ) -rc$(RC ) -m " Bumping $( APP_NAME) to Minor RC version $( MAJOR) .$( MINOR) .$( PATCH) -rc$( RC) "
103
+ git push origin v$(MAJOR ) .$(MINOR ) .$(PATCH ) -rc$(RC )
104
+ @echo Bumped $(APP_NAME ) to Minor RC version $(MAJOR ) .$(MINOR ) .$(PATCH ) -rc$(RC )
105
+
106
+ major-rc : # # to bump major release candidate version (semver)
107
+ $(call check_protected_branch)
108
+ $(call check_pending_pulls)
109
+ @$(eval MAJOR := $(shell echo $$(($(MAJOR ) +1 ) ) ) )
110
+ @$(eval MINOR := 0)
111
+ @$(eval PATCH := 0)
112
+ @$(eval RC := 1)
113
+ @echo Bumping $(APP_NAME ) to Major RC version $(MAJOR ) .$(MINOR ) .$(PATCH ) -rc$(RC )
114
+ git tag -s -a v$(MAJOR ) .$(MINOR ) .$(PATCH ) -rc$(RC ) -m " Bumping $( APP_NAME) to Major RC version $( MAJOR) .$( MINOR) .$( PATCH) -rc$( RC) "
115
+ git push origin v$(MAJOR ) .$(MINOR ) .$(PATCH ) -rc$(RC )
116
+ @echo Bumped $(APP_NAME ) to Major RC version $(MAJOR ) .$(MINOR ) .$(PATCH ) -rc$(RC )
117
+
25
118
# # Checks the code style, tests, builds and bundles the plugin.
26
119
all : check-style test dist
27
120
0 commit comments