Updating my package version using only a Makefile So I have written a Makefile that has a release function that can be run like: make release bump=patch and I want it to be fully executable in the Makefile. The only issue with my current implementation is that there is a lot of redundancy and long lines of commands, which I think can be simplified a lot, although I haven't found any better solutions yet (mainly because of the incrementation). It then tags and pushes.

The required functionality is being able to pass in patch,minor,major and have it overwrite the current file with the new version commit that and push the new tag.

It just has that 'gross' feeling, which I strive to avoid.

My current makefile looks like:

release:
    $(eval v := $(shell git describe --tags --abbrev=0 | sed -E -e 's/^v//' -e 's/(.*)-.*/\1/'))
ifeq ($(bump),patch)
    @echo "$v" | grep -Eo '[0-9]+$$' | tail -n 1 | awk '{print $$1 + 1}' | xargs -I '{}' sed -i '' -E 's/([0-9]+"$$)/{}"/' ._version_.py
else ifeq ($(bump),minor)
    @echo "$v" | grep -Eo '(\.[0-9]+\.)' | awk '{print $$1 + 1}' | xargs -I{} sed -i '' -E 's/(\.[0-9]+\.)/.{}./' ._version_.py
else ifeq ($(bump),major)
 @echo "$v" | grep -Eo '([0-9]+)' | head -n 1 | awk '{print $$1 + 1}' | xargs -I{} sed -i '' -E 's/([0-9]+)/{}/' ._version_.py
endif
    $(eval a := $(shell grep -Eo '([0-9]+\.[0-9]+\.[0-9]+)' ._version_.py))
    @git tag "$a"
    @git commit -am "Bumped to version $a"
    @git push --tags
I think there's an easier way to get this done:


Extract the semver part from the tag (as you already did)
Use conditionals to determine the field to increment
Use a single Awk to increment the selected field


For example:

release:
    $(eval v := $(shell git describe --tags --abbrev=0 | sed -Ee 's/^v|-.*//'))
ifeq ($(bump), major)
    $(eval f := 1)
else ifeq ($(bump), minor)
    $(eval f := 2)
else
    $(eval f := 3)
endif
    @echo $(v) | awk -F. -v OFS=. -v f=$(f) '{ $$f++ } 1'


I would add some validation in case the version doesn't have major, minor, patch components.