Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release: generate CHANGELOG from git history #45

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions release.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)
15 changes: 15 additions & 0 deletions scripts/generate-release-notes-for-tag.sh
Original file line number Diff line number Diff line change
@@ -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/^/- /'