Skip to content

Commit

Permalink
Add helper to bump next patch version by default
Browse files Browse the repository at this point in the history
  • Loading branch information
buberdds committed Mar 7, 2024
1 parent c727687 commit a2da425
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
30 changes: 17 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -182,18 +182,25 @@ psql:
shutdown-postgres:
@docker rm nexus-postgres --force

# Used when APP_VERSION is not set and until we have versioning tool in repo.
NEXT_PATCH_VERSION := $(shell git tag --list | grep -E 'v[0-9]+\.[0-9]+\.[0-9]+' | sort -V | tail -n1 | awk 'BEGIN{FS=OFS="."} {$$NF = $$NF + 1; print}')
# Conditionally assign APP_VERSION if it is not already set.
APP_VERSION ?= $(NEXT_PATCH_VERSION)

confirmVersion: fetch-git
@$(ECHO) "Latest published version is $(RED)v$(GIT_VERSION)$(OFF). You are about to publish $(CYAN)$(APP_VERSION)$(OFF)."
@$(ECHO) "If this is not what you want, re-run this command with VERSION=..."
@$(CONFIRM_ACTION)

# Fetch all the latest changes (including tags) from the canonical upstream git
# repository.
fetch-git:
@$(ECHO) "Fetching the latest changes (including tags) from $(GIT_ORIGIN_REMOTE) remote..."
@git fetch $(GIT_ORIGIN_REMOTE) --tags

# Tag the next release.
release-tag: fetch-git
@if [ -z "$(APP_VERSION)" ]; then \
echo "Please provide a version number using 'make changelog APP_VERSION=<your_version>'"; \
exit 1; \
fi
release-tag: confirmVersion
@$(CONFIRM_ACTION)
@$(ECHO) "Checking if we can tag version $(APP_VERSION) as the next release..."
@$(ENSURE_VALID_RELEASE_BRANCH_NAME)
@$(ENSURE_RELEASE_TAG_DOES_NOT_EXIST)
Expand All @@ -209,16 +216,13 @@ release-tag: fetch-git
release-build: codegen-go
@goreleaser release --rm-dist

changelog:
@if [ -z "$(APP_VERSION)" ]; then \
echo "Please provide a version number using 'make changelog VERSION=<your_version>'"; \
exit 1; \
fi
@$(ECHO) "$(CYAN)*** Generating Change Log for version $(APP_VERSION)...$(OFF)"
@$(BUILD_CHANGELOG)
@$(ECHO) "Next, review the staged changes, commit them and make a pull request."
changelog: confirmVersion
@$(ECHO) "$(CYAN)*** Generating Change Log for version $(APP_VERSION)...$(OFF)";
@$(BUILD_CHANGELOG);
@$(ECHO) "Next, review the staged changes, commit them and make a pull request.";
@$(WARN_BREAKING_CHANGES)


# List of targets that are not actual files.
.PHONY: \
all build \
Expand Down
13 changes: 11 additions & 2 deletions common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ endef
# Helper that builds the Change Log.
define BUILD_CHANGELOG =
if [[ $(ASSUME_YES) != 1 ]]; then \
towncrier build --version $(VERSION); \
towncrier build --version $(APP_VERSION); \
else \
towncrier build --version $(VERSION) --yes; \
towncrier build --version $(APP_VERSION) --yes; \
fi
endef

Expand Down Expand Up @@ -201,6 +201,15 @@ define ENSURE_VALID_RELEASE_BRANCH_NAME =
fi
endef

# Helper that calculates the next patch version number
define CALCULATE_NEXT_PATCH_VERSION
LATEST_VERSION=$$(git tag --list | grep -E 'v[0-9]+\.[0-9]+\.[0-9]+' | sort -V | tail -n1); \
NEXT_VERSION=$$(echo "$$LATEST_VERSION" | awk 'BEGIN{FS=OFS="."} {$$NF = $$NF + 1; print}'); \
$(ECHO) "Latest published version is $(RED)$$LATEST_VERSION$(OFF). You are about to publish $(CYAN)$$NEXT_VERSION$(OFF)."; \
$(ECHO) "If this is not what you want, re-run this command with VERSION=..."
endef


define newline


Expand Down

0 comments on commit a2da425

Please sign in to comment.