github.com/instana/go-sensor@v1.62.2-0.20240520081010-4919868049e1/Makefile.release (about)

     1  GO_MODULE_NAME ?= github.com/instana/go-sensor
     2  
     3  VERSION_TAG_PREFIX ?= v
     4  VERSION_GO_FILE ?= $(shell grep -l '^const Version = ".\+"' *.go | head -1)
     5  
     6  GIT_REMOTE ?= origin
     7  GIT_MAIN_BRANCH ?= $(shell git remote show $(GIT_REMOTE) | sed -n '/HEAD branch/s/.*: //p')
     8  GIT_TREE_STATE = $(shell (git status --porcelain | grep -q .) && echo dirty || echo clean)
     9  
    10  GITHUB_CLI = $(shell which gh 2>/dev/null)
    11  
    12  # Search for the latest vX.Y.Z tag ignoring all others, and use the X.Y.Z part as a version
    13  GIT_VERSION = $(shell git tag | grep "^$(VERSION_TAG_PREFIX)[0-9]\+\(\.[0-9]\+\)\{2\}" | sort -V | tail -n1 | sed "s~^$(VERSION_TAG_PREFIX)~~" )
    14  ifeq ($(GIT_VERSION),)
    15  	GIT_VERSION = 0.0.0
    16  endif
    17  
    18  # Parse semantic version X.Y.Z found in git tags
    19  GIT_MAJOR_VERSION = $(word 1,$(subst ., ,$(GIT_VERSION)))
    20  GIT_MINOR_VERSION = $(word 2,$(subst ., ,$(GIT_VERSION)))
    21  GIT_PATCH_VERSION = $(word 3,$(subst ., ,$(GIT_VERSION)))
    22  
    23  # Parse version from version.go file
    24  VERSION = $(shell grep -hm1 '^const Version = ".\+"' ${VERSION_GO_FILE} | head -1 | sed -E 's/const Version = "([0-9\.]+)"/\1/')
    25  
    26  # Create new release tag and publish a release from it
    27  release :
    28  	git tag $(VERSION_TAG_PREFIX)$(VERSION)
    29  	git push --tags
    30  ifneq ($(GITHUB_CLI),)
    31  	$(GITHUB_CLI) release create $(VERSION_TAG_PREFIX)$(VERSION) \
    32  		--draft \
    33  		--title $(VERSION_TAG_PREFIX)$(VERSION)
    34  else
    35  	@echo "GitHub CLI is not installed. Please proceed with creating the release on https://github.com"
    36  endif
    37  
    38  # Calculate the next major version from the latest one found in git tags, update version.go, commit and push changes to remote
    39  major : ensure-git-clean update-local-copy
    40  	$(eval VERSION = $(shell echo $$(($(GIT_MAJOR_VERSION)+1))).0.0)
    41  	@printf "You are about to increase the major version to $(VERSION), are you sure? [y/N]: " && read ans && [ $${ans:-N} = y ]
    42  	sed -i '' 's/^const Version = ".*"/const Version = "$(VERSION)"/' ${VERSION_GO_FILE}
    43  	git commit -m "Bump version to v$(VERSION)" ${VERSION_GO_FILE}
    44  	git push $(GIT_REMOTE) HEAD
    45  
    46  # Calculate the next minor version from the latest one found in git tags, update version.go, commit and push changes to remote
    47  minor : ensure-git-clean update-local-copy
    48  	$(eval VERSION = $(GIT_MAJOR_VERSION).$(shell echo $$(($(GIT_MINOR_VERSION)+1))).0)
    49  	sed -i '' 's/^const Version = ".*"/const Version = "$(VERSION)"/' ${VERSION_GO_FILE}
    50  	git commit -m "Bump version to v$(VERSION)" ${VERSION_GO_FILE}
    51  	git push $(GIT_REMOTE) HEAD
    52  
    53  # Calculate the next patch version from the latest one found in git tags, update version.go, commit and push changes to remote
    54  patch : ensure-git-clean update-local-copy
    55  	$(eval VERSION = $(GIT_MAJOR_VERSION).$(GIT_MINOR_VERSION).$(shell echo $$(($(GIT_PATCH_VERSION)+1))))
    56  	sed -i '' 's/^const Version = ".*"/const Version = "$(VERSION)"/' ${VERSION_GO_FILE}
    57  	git commit -m "Bump version to v$(VERSION)" ${VERSION_GO_FILE}
    58  	git push $(GIT_REMOTE) HEAD
    59  
    60  # Make sure there are no uncommitted changes in the working tree
    61  ensure-git-clean :
    62  ifeq ($(GIT_TREE_STATE),dirty)
    63  	$(error "There are uncommitted changes in current working tree. Please stash or commit them before release.")
    64  endif
    65  
    66  # Switch to the main branch, then pull and rebase to the latest changes including tags
    67  update-local-copy :
    68  	git fetch --tags $(GIT_REMOTE)
    69  	git checkout $(GIT_MAIN_BRANCH)
    70  	git rebase $(GIT_REMOTE)/$(GIT_MAIN_BRANCH)
    71  
    72  .PHONY : major minor patch release ensure-git-clean update-local-copy