- Initial release
GO_MODULE_NAME ?= github.com/instana/go-sensor
VERSION_TAG_PREFIX ?= v
VERSION_GO_FILE ?= $(shell grep -l '^const Version = ".\+"' *.go | head -1)
GIT_REMOTE ?= origin
GIT_MAIN_BRANCH ?= $(shell git remote show $(GIT_REMOTE) | sed -n '/HEAD branch/s/.*: //p')
GIT_TREE_STATE = $(shell (git status --porcelain | grep -q .) && echo dirty || echo clean)
GITHUB_CLI = $(shell which gh 2>/dev/null)
Search for the latest vX.Y.Z tag ignoring all others, and use the X.Y.Z part as a version
GIT_VERSION = $(shell git tag | grep "^$(VERSION_TAG_PREFIX)[0-9]\+\(\.[0-9]\+\)\{2\}" | sort -V | tail -n1 | sed "s~^$(VERSION_TAG_PREFIX)~~" )
ifeq ($(GIT_VERSION),)
GIT_VERSION = 0.0.0
endif
Parse semantic version X.Y.Z found in git tags
GIT_MAJOR_VERSION = $(word 1,$(subst ., ,$(GIT_VERSION)))
GIT_MINOR_VERSION = $(word 2,$(subst ., ,$(GIT_VERSION)))
GIT_PATCH_VERSION = $(word 3,$(subst ., ,$(GIT_VERSION)))
Parse version from version.go file
VERSION = $(shell grep -hm1 '^const Version = ".\+"' ${VERSION_GO_FILE} | head -1 | sed -E 's/const Version = "([0-9\.]+)"/\1/')
Create new release tag and publish a release from it
release :
git tag $(VERSION_TAG_PREFIX)$(VERSION)
git push --tags
ifneq ($(GITHUB_CLI),)
$(GITHUB_CLI) release create $(VERSION_TAG_PREFIX)$(VERSION) \
--draft \
--title $(VERSION_TAG_PREFIX)$(VERSION)
else
echo "GitHub CLI is not installed. Please proceed with creating the release on https://github.com"
endif
Calculate the next major version from the latest one found in git tags, update version.go, commit and push changes to remote
major : ensure-git-clean update-local-copy
$(eval VERSION = $(shell echo $$(($(GIT_MAJOR_VERSION)+1))).0.0)
printf "You are about to increase the major version to $(VERSION), are you sure? [y/N]: " && read ans && [ $${ans:-N} = y ]
sed -i '' 's/^const Version = ".*"/const Version = "$(VERSION)"/' ${VERSION_GO_FILE}
git commit -m "Bump version to v$(VERSION)" ${VERSION_GO_FILE}
git push $(GIT_REMOTE) HEAD
Calculate the next minor version from the latest one found in git tags, update version.go, commit and push changes to remote
minor : ensure-git-clean update-local-copy
$(eval VERSION = $(GIT_MAJOR_VERSION).$(shell echo $$(($(GIT_MINOR_VERSION)+1))).0)
sed -i '' 's/^const Version = ".*"/const Version = "$(VERSION)"/' ${VERSION_GO_FILE}
git commit -m "Bump version to v$(VERSION)" ${VERSION_GO_FILE}
git push $(GIT_REMOTE) HEAD
Calculate the next patch version from the latest one found in git tags, update version.go, commit and push changes to remote
patch : ensure-git-clean update-local-copy
$(eval VERSION = $(GIT_MAJOR_VERSION).$(GIT_MINOR_VERSION).$(shell echo $$(($(GIT_PATCH_VERSION)+1))))
sed -i '' 's/^const Version = ".*"/const Version = "$(VERSION)"/' ${VERSION_GO_FILE}
git commit -m "Bump version to v$(VERSION)" ${VERSION_GO_FILE}
git push $(GIT_REMOTE) HEAD
Make sure there are no uncommitted changes in the working tree
ensure-git-clean :
ifeq ($(GIT_TREE_STATE),dirty)
$(error "There are uncommitted changes in current working tree. Please stash or commit them before release.")
endif
Switch to the main branch, then pull and rebase to the latest changes including tags
update-local-copy :
git fetch --tags $(GIT_REMOTE)
git checkout $(GIT_MAIN_BRANCH)
git rebase $(GIT_REMOTE)/$(GIT_MAIN_BRANCH)
.PHONY : major minor patch release ensure-git-clean update-local-copy