Created
June 1, 2025 16:44
-
-
Save alejandrobernardis/f86e3ee488f0a5ddc1e58954cfe64360 to your computer and use it in GitHub Desktop.
Semantic Versioning in Make
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##! Commons | |
##@ Version | |
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
##: Dynamic Target (%) | |
##, [+N]=Increase version [ex: minor.+1] | |
##, [-N]=Decrease version [ex: minor.-1] | |
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
_f_version = $(PWD)/source/VERSION | |
_f_release = $(PWD)/source/RELEASE | |
_v_version = $(shell cat $(_f_version)) | |
_v_version_major = $(shell echo $(_v_version) | cut -d. -f1) | |
_v_version_minor = $(shell echo $(_v_version) | cut -d. -f2) | |
_v_release = $(shell cat $(_f_release)) | |
major.%: ## Adjust MAYOR value | |
$(call __w_counter\ | |
,$$(( $(_v_version_major) $* )).$(_v_version_minor)\ | |
,$(_f_version)) | |
minor.%: ## Adjust MINOR value | |
$(call __w_counter\ | |
,$(_v_version_major).$$(( $(_v_version_minor) $* ))\ | |
,$(_f_version)) | |
patch.%: ## Adjust PATCH value | |
$(call __w_counter,$$(( $(_v_release) $* )),$(_f_release)) | |
##----------------------------------------------------------------------------- | |
reset: ## Reset release counter [ex: v1.0 r0] | |
$(call __w_counter,1.0,$(_f_version)) | |
$(call __w_counter,0,$(_f_release)) | |
version: ## Show current version | |
echo $(_v_version).$(_v_release) | |
define __w_counter | |
echo -n $(1) >$(2) | |
endef | |
# --- help ---------------------------------------------------------------- | |
_rst=\033[m | |
_prx=\033[38;5; | |
h: help | |
help: | |
@command -p grep -Ehi '^(##.*)|(^[a-z0-9][a-z0-9\.%_-]+:.*?##\s.*)$$'\ | |
$(PWD)/Makefile\ | |
$(_include)\ | |
| awk 1>&2 '\ | |
BEGIN { FS = ":.*?## " }\ | |
/^##!/ {printf "\n\n$(_rst) $(_prx)208;7m %s \n", toupper(substr($$0,5))}\ | |
/^##@/ {printf "\n$(_rst)$(_prx)208m%s\n", substr($$0,4)}\ | |
/^##~/ {printf "$(_rst)$(_prx)159m%s\n", substr($$0,4)}\ | |
/^##-/ {printf "$(_rst)$(_prx)250m%s\n", substr($$0,4)}\ | |
/^##:/ {printf "$(_rst)$(_prx)159m%s:\n", substr($$0,4)}\ | |
/^##,/ {split(substr($$0, 4),x,"=");printf "$(_rst)$(_prx)195;3m ~%s: %s\n", x[1], x[2];}\ | |
/^##;/ {split(substr($$0, 4),x,"=");printf "$(_rst)$(_prx)246;3m -%-17s $(_prx)246m%s\n", x[1], x[2];}\ | |
/^##>/ {printf "$(_rst)%-21s$(_prx)246m%s\n", "", substr($$0,4);}\ | |
/^[a-zA-Z].*/ {printf "$(_rst)$(_prx)230m %-16s $(_prx)255m-- %s\n", $$1, $$2}\ | |
'; printf 1>&2 '\n$(_rst)' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment