Last active
December 4, 2022 02:51
-
-
Save luckylittle/df7a88caa91bd461dab7d1d7bfecefea to your computer and use it in GitHub Desktop.
Makefile versioning example based on https://semver.org/
This file contains 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
#--------------# | |
# VERSIONING # | |
#--------------# | |
# Current tags: | |
CURRENT_FULLTAG = $(shell git describe --tags --abbrev=0 | awk -F. '{ printf $$0 }') | |
CURRENT_YAML = $(shell grep '^version' YAML.yml | awk -F' ' '{ print $$2 }') | |
CURRENT_MAJORTAG = $(shell git describe --tags --abbrev=0 | awk -F. '{ printf $$1 }') | |
CURRENT_MINORTAG = $(shell git describe --tags --abbrev=0 | awk -F. '{ printf $$2 }') | |
CURRENT_PATCHTAG = $(shell git describe --tags --abbrev=0 | awk -F. '{ printf $$3 }') | |
# New tags: | |
NEW_MAJORTAG = $(shell git describe --tags --abbrev=0 | awk -F. '{ printf $$1+1 }') | |
NEW_MINORTAG = $(shell git describe --tags --abbrev=0 | awk -F. '{ printf $$2+1 }') | |
NEW_PATCHTAG = $(shell git describe --tags --abbrev=0 | awk -F. '{ printf $$3+1 }') | |
.PHONY: showver | |
showver: | |
@echo 'Current version is:' | |
@echo Git: ${CURRENT_FULLTAG}, YAML.yml: ${CURRENT_YAML} | |
# | |
# X.0.1 | |
# ^ | |
.PHONY: major | |
major: | |
@$(eval NEW_FULLTAG := ${NEW_MAJORTAG}.${CURRENT_MINORTAG}.${CURRENT_PATCHTAG}) | |
# | |
# 1.X.0 | |
# ^ | |
.PHONY: minor | |
minor: | |
@$(eval NEW_FULLTAG := ${CURRENT_MAJORTAG}.${NEW_MINORTAG}.${CURRENT_PATCHTAG}) | |
# | |
# 1.0.X | |
# ^ | |
.PHONY: patch | |
patch: | |
@$(eval NEW_FULLTAG := ${CURRENT_MAJORTAG}.${CURRENT_MINORTAG}.${NEW_PATCHTAG}) | |
# cat YAML.yml | |
# version: 0.0.1 | |
# | |
.PHONY: release | |
release: | |
@sed -i 's/^version: [0-9][0-9.]*/version: $(NEW_FULLTAG)/' YAML.yml | |
@git add YAML.yml | |
@git commit -m "Release v$(NEW_FULLTAG)" | |
@git push | |
@echo 'Released new version to Git:' | |
@git tag -a $(NEW_FULLTAG) -m "Release v$(NEW_FULLTAG)" | |
@git push --tags | |
git show $(NEW_FULLTAG) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment