diff --git a/release.mk b/release.mk index 8db4d77..b35fc95 100644 --- a/release.mk +++ b/release.mk @@ -77,3 +77,35 @@ release-default: release-precheck release-notes clean:: rm -rf '$(CURDIR)/dist' rm -rf '$(RELEASE_DIR)' + +CHANGELOG_FILENAME=CHANGELOG.md + +.PHONY: prepare-release +prepare-release: + @if [ -z "$(NEW_VERSION)" ]; then \ + echo "Error: NEW_VERSION is not set. Usage: make $@ NEW_VERSION=vX.Y.Z"; \ + exit 1; \ + fi + @rm $(CHANGELOG_FILENAME) + @git add $(CHANGELOG_FILENAME) + @git commit -m "Prepare release" + @git tag $(NEW_VERSION) + $(MAKE) $(CHANGELOG_FILENAME) + @git tag -d $(NEW_VERSION) + @git add $(CHANGELOG_FILENAME) + @git commit --amend -m "Prepare release" + @git tag $(NEW_VERSION) + +TAGS := $(shell git tag | sort --version-sort --reverse) +INITIAL_COMMIT := $(shell git rev-list --max-parents=0 HEAD)) + +$(TAGS): + ./go.mk/scripts/generate-release-notes-for-tag.sh $@ >> $(CHANGELOG_FILENAME) + +.PHONY: new-changelog +new-changelog: + @printf "# Changelog\n\n" > $(CHANGELOG_FILENAME) + +# creates a new changelog and generates the content for each git tag +.PHONY: $(CHANGELOG_FILENAME) +$(CHANGELOG_FILENAME): new-changelog $(TAGS) diff --git a/scripts/generate-release-notes-for-tag.sh b/scripts/generate-release-notes-for-tag.sh new file mode 100755 index 0000000..85b2d69 --- /dev/null +++ b/scripts/generate-release-notes-for-tag.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env sh + +CURRENT_TAG=$1 + +INITIAL_COMMIT=$(git rev-list --max-parents=0 HEAD) + +PREVIOUS_TAG=$(git tag | sort --version-sort --reverse | awk "/^${CURRENT_TAG}$/ {getline; print}") + +if [ "${PREVIOUS_TAG}" = "${CURRENT_TAG}" ]; then + PREVIOUS_TAG=${INITIAL_COMMIT} +fi + +printf "\n## %s\n" ${CURRENT_TAG} + +git log ${PREVIOUS_TAG}..${CURRENT_TAG} --oneline --no-decorate | sed 's/^/- /'