I've a makefile with variable DOCKER_TAG = 0.0.1
and I want that on each target called it will be bumped (only patch version ) is it possible
e.g.
DOCKER_TAG = 0.0.1
push:
docker push docker.io/testasm:$(DOCKER_TAG)
now If I run make push it will use version 0.0.1 but If I do it for the second time it will be bumped to 0.0.2 and so on (on each run of make push) , is it possible ?
update I've tried the following
DOCKER_TAG = 0.0.1
DOCKER_REGISTRY = testreg/vsp
VERSION_FILE := version.txt
-include $(VERSION_FILE)
VERMAJMIN := $(subst ., ,$(DOCKER_TAG))
DOCKER_TAG := $(shell [ -f "$(VERSION_FILE)" ] && cat "$(VERSION_FILE)" || echo '0.0.1')
VERMAJMIN := $(subst ., ,$(DOCKER_TAG))
VERSION := $(word 1,$(VERMAJMIN))
MAJOR := $(word 2,$(VERMAJMIN))
MINOR := $(word 3,$(VERMAJMIN))
NEW_MINOR := $(shell expr "$(MINOR)" + 1)
NEW_DOCKER_TAG := $(VERSION).$(MAJOR).$(NEW_MINOR)
NEW_DOCKER_TAG := $(VERSION).$(MAJOR).$(NEW_MINOR)
build:
echo "$(NEW_DOCKER_TAG)" > "$(VERSION_FILE)"
And the version.txt file get value of .. two dots ... any idea how to solve it?
if I take the last option in the answer as-is
I see that the version.txt file contain DOCKER_TAG := ..
update 2
I've created empty version.txt file and use the folloing as-is
VERSION_FILE := version.txt
DOCKER_TAG := 0.0.1.
-include $(VERSION_FILE)
VERMAJMIN := $(subst ., ,$(DOCKER_TAG))
NEW_DOCKER_TAG := $(VERSION).$(MAJOR).$(NEW_MINOR)
build:
docker build -t docker.io/vcd/test:$(DOCKER_TAG) .
echo "DOCKER_TAG := $(NEW_DOCKER_TAG)" > "$(VERSION_FILE)"
and I got in the version.txt file the following DOCKER_TAG := ..