Changed changelog generation and version handling

This commit is contained in:
Corey Oordt 2022-09-21 11:37:26 -05:00
parent 68abe74741
commit 7b3f5400a2
7 changed files with 1383 additions and 1258 deletions

119
.changelog-config.yaml Normal file
View file

@ -0,0 +1,119 @@
# For more configuration information, please see https://coordt.github.io/generate-changelog/
# User variables for reference in other parts of the configuration.
variables:
repo_url: https://github.com/jazzband/django-categories
changelog_filename: CHANGELOG.md
# Pipeline to find the most recent tag for incremental changelog generation.
# Leave empty to always start at first commit.
starting_tag_pipeline:
- action: ReadFile
kwargs:
filename: '{{ changelog_filename }}'
- action: FirstRegExMatch
kwargs:
pattern: (?im)^## (?P<rev>\d+\.\d+(?:\.\d+)?)\s+\(\d+-\d{2}-\d{2}\)$
named_subgroup: rev
# Used as the version title of the changes since the last valid tag.
unreleased_label: Unreleased
# Process the commit's first line for use in the changelog.
summary_pipeline:
- action: strip_spaces
- action: Strip
comment: Get rid of any periods so we don't get double periods
kwargs:
chars: .
- action: SetDefault
args:
- no commit message
- action: capitalize
- action: append_dot
# Process the commit's body for use in the changelog.
body_pipeline:
- action: ParseTrailers
comment: Parse the trailers into metadata.
kwargs:
commit_metadata: save_commit_metadata
# Process and store the full or partial changelog.
output_pipeline:
- action: IncrementalFileInsert
kwargs:
filename: '{{ changelog_filename }}'
last_heading_pattern: (?im)^## \d+\.\d+(?:\.\d+)?\s+\([0-9]+-[0-9]{2}-[0-9]{2}\)$
# Full or relative paths to look for output generation templates.
template_dirs:
- .github/changelog_templates/
# Group the commits within a version by these commit attributes.
group_by:
- metadata.category
# Only tags matching this regular expression are used for the changelog.
tag_pattern: ^[0-9]+\.[0-9]+(?:\.[0-9]+)?$
# Tells ``git-log`` whether to include merge commits in the log.
include_merges: false
# Ignore commits whose summary line matches any of these regular expression patterns.
ignore_patterns:
- '[@!]minor'
- '[@!]cosmetic'
- '[@!]refactor'
- '[@!]wip'
- ^$
- ^Merge branch
- ^Merge pull
# Set the commit's category metadata to the first classifier that returns ``True``.
commit_classifiers:
- action: SummaryRegexMatch
category: New
kwargs:
pattern: (?i)^(?:new|add)[^\n]*$
- action: SummaryRegexMatch
category: Updates
kwargs:
pattern: (?i)^(?:update|change|rename|remove|delete|improve|refactor|chg|modif)[^\n]*$
- action: SummaryRegexMatch
category: Fixes
kwargs:
pattern: (?i)^(?:fix)[^\n]*$
- action:
category: Other
# Tokens in git commit trailers that indicate authorship.
valid_author_tokens:
- author
- based-on-a-patch-by
- based-on-patch-by
- co-authored-by
- co-committed-by
- contributions-by
- from
- helped-by
- improved-by
- original-patch-by
# Rules applied to commits to determine the type of release to suggest.
release_hint_rules:
- match_result: patch
no_match_result: no-release
grouping: Other
- match_result: patch
no_match_result: no-release
grouping: Fixes
- match_result: minor
no_match_result: no-release
grouping: Updates
- match_result: minor
no_match_result:
grouping: New
- match_result: major
no_match_result:
grouping: Breaking Changes

View file

@ -1,311 +0,0 @@
# -*- coding: utf-8; mode: python -*-
#
# Format
#
# ACTION: [AUDIENCE:] COMMIT_MSG [!TAG ...]
#
# Description
#
# ACTION is one of 'chg', 'fix', 'new'
#
# Is WHAT the change is about.
#
# 'chg' is for refactor, small improvement, cosmetic changes...
# 'fix' is for bug fixes
# 'new' is for new features, big improvement
#
# AUDIENCE is optional and one of 'dev', 'usr', 'pkg', 'test', 'doc'
#
# Is WHO is concerned by the change.
#
# 'dev' is for developpers (API changes, refactors...)
# 'usr' is for final users (UI changes)
# 'pkg' is for packagers (packaging changes)
# 'test' is for testers (test only related changes)
# 'doc' is for doc guys (doc only changes)
#
# COMMIT_MSG is ... well ... the commit message itself.
#
# TAGs are additionnal adjective as 'refactor' 'minor' 'cosmetic'
#
# They are preceded with a '!' or a '@' (prefer the former, as the
# latter is wrongly interpreted in github.) Commonly used tags are:
#
# 'refactor' is obviously for refactoring code only
# 'minor' is for a very meaningless change (a typo, adding a comment)
# 'cosmetic' is for cosmetic driven change (re-indentation, 80-col...)
# 'wip' is for partial functionality but complete subfunctionality.
#
# Example:
#
# new: usr: support of bazaar implemented
# chg: re-indentend some lines !cosmetic
# new: dev: updated code to be compatible with last version of killer lib.
# fix: pkg: updated year of licence coverage.
# new: test: added a bunch of test around user usability of feature X.
# fix: typo in spelling my name in comment. !minor
#
# Please note that multi-line commit message are supported, and only the
# first line will be considered as the "summary" of the commit message. So
# tags, and other rules only applies to the summary. The body of the commit
# message will be displayed in the changelog without reformatting.
#
# ``ignore_regexps`` is a line of regexps
#
# Any commit having its full commit message matching any regexp listed here
# will be ignored and won't be reported in the changelog.
#
ignore_regexps = [
r'@minor', r'!minor',
r'@cosmetic', r'!cosmetic',
r'@refactor', r'!refactor',
r'@wip', r'!wip',
r'^([cC]hg|[fF]ix|[nN]ew)\s*:\s*[p|P]kg:',
r'^([cC]hg|[fF]ix|[nN]ew)\s*:\s*[d|D]ev:',
r'^(.{3,3}\s*:)?\s*[fF]irst commit.?\s*$',
r'^Initial Commit.$',
r'^Version updated.+$',
r'^$', # ignore commits with empty messages
r'^Merge branch .+',
r'^Merge pull .+',
]
# ``section_regexps`` is a list of 2-tuples associating a string label and a
# list of regexp
#
# Commit messages will be classified in sections thanks to this. Section
# titles are the label, and a commit is classified under this section if any
# of the regexps associated is matching.
#
# Please note that ``section_regexps`` will only classify commits and won't
# make any changes to the contents. So you'll probably want to go check
# ``subject_process`` (or ``body_process``) to do some changes to the subject,
# whenever you are tweaking this variable.
#
section_regexps = [
('New', [
r'^\[?[nN][eE][wW]\]?\s*:?\s*((dev|use?r|pkg|test|doc)\s*:\s*)?([^\n]*)$',
r'^\[?[aA][dD][dD]\]?\s*:?\s*((dev|use?r|pkg|test|doc)\s*:\s*)?([^\n]*)$',
]),
('Updates', [
r'^\[?[uU][pP][dD][aA][tT][eE]\s*:?\s*((dev|use?r|pkg|test|doc)\s*:\s*)?([^\n]*)$',
r'^\[?[cC][hH][aA][nN][gG][eE][dD]?\s*:?\s*((dev|use?r|pkg|test|doc)\s*:\s*)?([^\n]*)$',
]),
('Fix', [
r'^\[?[fF][iI][xX]\]?\s*:?\s*((dev|use?r|pkg|test|doc)\s*:\s*)?([^\n]*)$',
]),
('Other', None # Match all lines
),
]
# ``body_process`` is a callable
#
# This callable will be given the original body and result will
# be used in the changelog.
#
# Available constructs are:
#
# - any python callable that take one txt argument and return txt argument.
#
# - ReSub(pattern, replacement): will apply regexp substitution.
#
# - Indent(chars=" "): will indent the text with the prefix
# Please remember that template engines gets also to modify the text and
# will usually indent themselves the text if needed.
#
# - Wrap(regexp=r"\n\n"): re-wrap text in separate paragraph to fill 80-Columns
#
# - noop: do nothing
#
# - ucfirst: ensure the first letter is uppercase.
# (usually used in the ``subject_process`` pipeline)
#
# - final_dot: ensure text finishes with a dot
# (usually used in the ``subject_process`` pipeline)
#
# - strip: remove any spaces before or after the content of the string
#
# - SetIfEmpty(msg="No commit message."): will set the text to
# whatever given ``msg`` if the current text is empty.
#
# Additionally, you can `pipe` the provided filters, for instance:
# body_process = Wrap(regexp=r'\n(?=\w+\s*:)') | Indent(chars=" ")
# body_process = Wrap(regexp=r'\n(?=\w+\s*:)')
# body_process = noop
body_process = ReSub(r'((^|\n)[A-Z]\w+(-\w+)*: .*(\n\s+.*)*)+$', r'') | strip
# ``subject_process`` is a callable
#
# This callable will be given the original subject and result will
# be used in the changelog.
#
# Available constructs are those listed in ``body_process`` doc.
subject_process = (strip |
ReSub(r'^(\[\w+\])\s*:?\s*((dev|use?r|pkg|test|doc)\s*:\s*)?([^\n@]*)(@[a-z]+\s+)*$', r'\4') |
SetIfEmpty("No commit message.") | ucfirst | final_dot)
# ``tag_filter_regexp`` is a regexp
#
# Tags that will be used for the changelog must match this regexp.
#
tag_filter_regexp = r'^[0-9]+\.[0-9]+(\.[0-9]+)?$'
# ``unreleased_version_label`` is a string or a callable that outputs a string
#
# This label will be used as the changelog Title of the last set of changes
# between last valid tag and HEAD if any.
def unreleased_date():
import datetime
return 'Unreleased ({})'.format(datetime.datetime.now().strftime('%Y-%m-%d'))
unreleased_version_label = unreleased_date
# ``output_engine`` is a callable
#
# This will change the output format of the generated changelog file
#
# Available choices are:
#
# - rest_py
#
# Legacy pure python engine, outputs ReSTructured text.
# This is the default.
#
# - mustache(<template_name>)
#
# Template name could be any of the available templates in
# ``templates/mustache/*.tpl``.
# Requires python package ``pystache``.
# Examples:
# - mustache("markdown")
# - mustache("restructuredtext")
#
# - makotemplate(<template_name>)
#
# Template name could be any of the available templates in
# ``templates/mako/*.tpl``.
# Requires python package ``mako``.
# Examples:
# - makotemplate("restructuredtext")
#
# output_engine = rest_py
# output_engine = mustache("restructuredtext")
output_engine = mustache("markdown")
# output_engine = makotemplate("restructuredtext")
# ``include_merge`` is a boolean
#
# This option tells git-log whether to include merge commits in the log.
# The default is to include them.
include_merge = True
# ``log_encoding`` is a string identifier
#
# This option tells gitchangelog what encoding is outputed by ``git log``.
# The default is to be clever about it: it checks ``git config`` for
# ``i18n.logOutputEncoding``, and if not found will default to git's own
# default: ``utf-8``.
log_encoding = 'utf-8'
OUTPUT_FILE = "CHANGELOG.md"
INSERT_POINT_REGEX = r'''(?isxu)
^
(
\s*\#\s+Changelog\s*(\n|\r\n|\r) ## ``Changelog`` line
)
( ## Match all between changelog and release rev
(
(?!
(?<=(\n|\r)) ## look back for newline
\#\#\s+%(rev)s ## revision
\s+
\([0-9]+-[0-9]{2}-[0-9]{2}\)(\n|\r\n|\r) ## date
)
.
)*
)
(?P<tail>\#\#\s+(?P<rev>%(rev)s))
''' % {'rev': r"[0-9]+\.[0-9]+(\.[0-9]+)?"}
# ``publish`` is a callable
#
# Sets what ``gitchangelog`` should do with the output generated by
# the output engine. ``publish`` is a callable taking one argument
# that is an interator on lines from the output engine.
#
# Some helper callable are provided:
#
# Available choices are:
#
# - stdout
#
# Outputs directly to standard output
# (This is the default)
#
# - FileInsertAtFirstRegexMatch(file, pattern, idx=lamda m: m.start())
#
# Creates a callable that will parse given file for the given
# regex pattern and will insert the output in the file.
# ``idx`` is a callable that receive the matching object and
# must return a integer index point where to insert the
# the output in the file. Default is to return the position of
# the start of the matched string.
#
# - FileRegexSubst(file, pattern, replace, flags)
#
# Apply a replace inplace in the given file. Your regex pattern must
# take care of everything and might be more complex. Check the README
# for a complete copy-pastable example.
#
publish = FileRegexSubst(OUTPUT_FILE, INSERT_POINT_REGEX, r"\1\o\n\g<tail>")
# ``revs`` is a list of callable or a list of string
#
# callable will be called to resolve as strings and allow dynamical
# computation of these. The result will be used as revisions for
# gitchangelog (as if directly stated on the command line). This allows
# to filter exaclty which commits will be read by gitchangelog.
#
# To get a full documentation on the format of these strings, please
# refer to the ``git rev-list`` arguments. There are many examples.
#
# Using callables is especially useful, for instance, if you
# are using gitchangelog to generate incrementally your changelog.
#
# Some helpers are provided, you can use them::
#
# - FileFirstRegexMatch(file, pattern): will return a callable that will
# return the first string match for the given pattern in the given file.
# If you use named sub-patterns in your regex pattern, it'll output only
# the string matching the regex pattern named "rev".
#
# - Caret(rev): will return the rev prefixed by a "^", which is a
# way to remove the given revision and all its ancestor.
#
# Please note that if you provide a rev-list on the command line, it'll
# replace this value (which will then be ignored).
#
# If empty, then ``gitchangelog`` will act as it had to generate a full
# changelog.
#
# The default is to use all commits to make the changelog.
# revs = ["^1.0.3", ]
revs = [
Caret(FileFirstRegexMatch(OUTPUT_FILE, INSERT_POINT_REGEX)),
"HEAD"
]

View file

@ -0,0 +1,8 @@
- {{ commit.summary }} [{{ commit.short_sha }}]({{ repo_url }}/commit/{{ commit.sha }})
{{ commit.body|indent(2, first=True) }}
{% for key, val in commit.metadata["trailers"].items() %}
{% if key not in VALID_AUTHOR_TOKENS %}
**{{ key }}:** {{ val|join(", ") }}
{% endif %}
{% endfor %}

View file

@ -0,0 +1,4 @@
## {{ version.label }} ({{ version.date_time.strftime("%Y-%m-%d") }})
{% if version.previous_tag %}
[Compare the full difference.]({{ repo_url }}/compare/{{ version.previous_tag }}...{{ version.tag }})
{% endif %}

File diff suppressed because it is too large Load diff

View file

@ -7,6 +7,7 @@ SOURCE_DIR := categories
BRANCH_NAME := $(shell echo $$(git rev-parse --abbrev-ref HEAD)) BRANCH_NAME := $(shell echo $$(git rev-parse --abbrev-ref HEAD))
SHORT_BRANCH_NAME := $(shell echo $(BRANCH_NAME) | cut -c 1-20) SHORT_BRANCH_NAME := $(shell echo $(BRANCH_NAME) | cut -c 1-20)
PRIMARY_BRANCH_NAME := master PRIMARY_BRANCH_NAME := master
BUMPVERSION_OPTS :=
EDIT_CHANGELOG_IF_EDITOR_SET := @bash -c "$(shell if [[ -n $$EDITOR ]] ; then echo "$$EDITOR CHANGELOG.md" ; else echo "" ; fi)" EDIT_CHANGELOG_IF_EDITOR_SET := @bash -c "$(shell if [[ -n $$EDITOR ]] ; then echo "$$EDITOR CHANGELOG.md" ; else echo "" ; fi)"
@ -46,45 +47,6 @@ publish: ## Publish a release to PyPi (requires permissions)
python setup.py sdist bdist_wheel python setup.py sdist bdist_wheel
twine upload dist/* twine upload dist/*
release-helper:
## DO NOT CALL DIRECTLY. It is used by release-{patch,major,minor,dev}
@echo "Branch In Use: $(BRANCH_NAME) $(SHORT_BRANCH_NAME)"
ifeq ($(BRANCH_NAME), $(PRIMARY_BRANCH_NAME))
ifeq ($(RELEASE_KIND), dev)
@echo "Error! Can't bump $(RELEASE_KIND) while on the $(PRIMARY_BRANCH_NAME) branch."
exit
else ifneq ($(RELEASE_KIND), dev)
@echo "Error! Must be on the $(PRIMARY_BRANCH_NAME) branch to bump $(RELEASE_KIND)."
exit
endif
git fetch -p --all
gitchangelog
$(EDIT_CHANGELOG_IF_EDITOR_SET)
export BRANCH_NAME=$(SHORT_BRANCH_NAME);bumpversion $(RELEASE_KIND) --allow-dirty --tag
git push origin $(BRANCH_NAME)
git push --tags
set-release-major-env-var:
$(eval RELEASE_KIND := major)
set-release-minor-env-var:
$(eval RELEASE_KIND := minor)
set-release-patch-env-var:
$(eval RELEASE_KIND := patch)
set-release-dev-env-var:
$(eval RELEASE_KIND := dev)
release-dev: set-release-dev-env-var release-helper ## Release a new development version: 1.1.1 -> 1.1.1+branchname-0
release-patch: set-release-patch-env-var release-helper ## Release a new patch version: 1.1.1 -> 1.1.2
release-minor: set-release-minor-env-var release-helper ## Release a new minor version: 1.1.1 -> 1.2.0
release-major: set-release-major-env-var release-helper ## release a new major version: 1.1.1 -> 2.0.0
docs: ## generate Sphinx HTML documentation, including API docs docs: ## generate Sphinx HTML documentation, including API docs
mkdir -p docs mkdir -p docs
rm -f doc_src/api/$(SOURCE_DIR)*.rst rm -f doc_src/api/$(SOURCE_DIR)*.rst
@ -94,3 +56,45 @@ docs: ## generate Sphinx HTML documentation, including API docs
pubdocs: docs ## Publish the documentation to GitHub pubdocs: docs ## Publish the documentation to GitHub
ghp-import -op docs ghp-import -op docs
release-dev: RELEASE_KIND := dev
release-dev: do-release ## Release a new development version: 1.1.1 -> 1.1.1+branchname-1
release-patch: RELEASE_KIND := patch
release-patch: do-release ## Release a new patch version: 1.1.1 -> 1.1.2
release-minor: RELEASE_KIND := minor
release-minor: do-release ## Release a new minor version: 1.1.1 -> 1.2.0
release-major: RELEASE_KIND := major
release-major: do-release ## Release a new major version: 1.1.1 -> 2.0.0
release-version: get-version do-release ## Release a specific version: release-version 1.2.3
#
# Helper targets. Not meant to use directly
#
do-release:
@if [[ "$(BRANCH_NAME)" == "$(PRIMARY_BRANCH_NAME)" ]]; then \
if [[ "$(RELEASE_KIND)" == "dev" ]]; then \
echo "Error! Can't bump $(RELEASE_KIND) while on the $(PRIMARY_BRANCH_NAME) branch."; \
exit; \
fi; \
elif [[ "$(RELEASE_KIND)" != "dev" ]]; then \
echo "Error! Must be on the $(PRIMARY_BRANCH_NAME) branch to bump $(RELEASE_KIND)."; \
exit; \
fi; \
git fetch -p --all; \
generate-changelog; \
git add CODEOWNERS; \
export BRANCH_NAME=$(SHORT_BRANCH_NAME);bumpversion $(BUMPVERSION_OPTS) $(RELEASE_KIND) --allow-dirty --dry-run; \
git push origin $(BRANCH_NAME); \
git push --tags;
get-version: # Sets the value after release-version to the VERSION
$(eval VERSION := $(filter-out release-version,$(MAKECMDGOALS)))
$(eval BUMPVERSION_OPTS := --new-version=$(VERSION))
%: # NO-OP for unrecognized rules
@:

View file

@ -1,8 +1,6 @@
--find-links https://github.com/PennyDreadfulMTG/pystache/releases/
-r test.txt -r test.txt
bump2version>=1.0.1 bump2version>=1.0.1
git-fame>=1.12.2 git-fame>=1.12.2
gitchangelog>=3.0.4 generate-changelog
pre-commit pre-commit
pystache>=0.6.0