-
Notifications
You must be signed in to change notification settings - Fork 122
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
Add a Markdown how-to #436
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ Narrative | |
:maxdepth: 1 | ||
|
||
tutorial | ||
keep-a-changelog | ||
|
||
|
||
Reference | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
How to Keep a Changelog in Markdown | ||
=================================== | ||
|
||
`Keep a Changelog <https://keepachangelog.com/>`_ is a standardized way to format a news file in `Markdown <https://en.wikipedia.org/wiki/Markdown>`_. | ||
|
||
This guide shows you how to configure ``towncrier`` for keeping a Markdown-based news file of a project without using any Python-specific features. | ||
Everything used here can be use with any other language or platform. | ||
|
||
This guide makes the following assumptions: | ||
|
||
- The project lives at https://github.com/twisted/my-project/. | ||
- The news file name is ``CHANGELOG.md``. | ||
- You store the news fragments in the ``changelog.d`` directory at the root of the project. | ||
|
||
Put the following into your ``pyproject.toml`` or ``towncrier.toml``: | ||
|
||
.. code-block:: toml | ||
|
||
[tool.towncrier] | ||
directory = "changelog.d" | ||
filename = "CHANGELOG.md" | ||
start_string = "<!-- towncrier release notes start -->\n" | ||
underlines = ["", "", ""] | ||
template = "changelog.d/changelog_template.jinja" | ||
title_format = "## [{version}](https://github.com/twisted/my-project/tree/{version}) - {project_date}" | ||
issue_format = "[#{issue}](https://github.com/twisted/my-project/issues/{issue})" | ||
|
||
[tool.towncrier.fragment.security] | ||
name = "Security" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previously the config was something like this
I guess the main issue is due to pytoml not using an ordered dict. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ooof yeah you're right. It used to be an array but is a dict now and tomli gives it alphabetically: {'tool': {'towncrier': {'directory': 'changelog.d',
'filename': 'CHANGELOG.md',
'fragment': {'added': {'name': 'Added'},
'changed': {'name': 'Changed'},
'deprecated': {'name': 'Deprecated'},
'fixed': {'name': 'Fixed'},
'removed': {'name': 'Removed'},
'security': {'name': 'Security'}},
'issue_format': '[#{issue}](https://github.com/twisted/my-project/issues/{issue})',
'start_string': '<!-- towncrier release notes start '
'-->\n',
'template': 'changelog.d/changelog_template.jinja',
'title_format': '## '
'[{version}](https://github.com/twisted/my-project/tree/{version}) '
'- {project_date}',
'underlines': ['', '', '']}}} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For reference. I think the old format is still supported. This looks like a bug for the new format. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure what toml lib we a re using, but it looks like ordered dict are not a thing :) and also not wanted in the general TOML spec There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In modern Pythons, dicts are always ordered. This is a deliberate action by tomli based on the spec that you linked. I've opened #437 to track this. |
||
|
||
[tool.towncrier.fragment.removed] | ||
name = "Removed" | ||
|
||
[tool.towncrier.fragment.deprecated] | ||
name = "Deprecated" | ||
|
||
[tool.towncrier.fragment.added] | ||
name = "Added" | ||
|
||
[tool.towncrier.fragment.changed] | ||
name = "Changed" | ||
|
||
[tool.towncrier.fragment.fixed] | ||
name = "Fixed" | ||
|
||
|
||
Next create the news fragment directory and the news file template: | ||
|
||
.. code-block:: console | ||
|
||
$ mkdir changelog.d | ||
|
||
And put the following into ``changelog.d/changelog_template.jinja``: | ||
|
||
.. code-block:: jinja | ||
|
||
{% if sections[""] %} | ||
{% for category, val in definitions.items() if category in sections[""] %} | ||
|
||
### {{ definitions[category]['name'] }} | ||
|
||
{% for text, values in sections[""][category].items() %} | ||
- {{ text }} {{ values|join(', ') }} | ||
{% endfor %} | ||
|
||
{% endfor %} | ||
{% else %} | ||
No significant changes. | ||
|
||
|
||
{% endif %} | ||
|
||
|
||
Next, create the news file with an explanatory header:: | ||
|
||
$ cat >CHANGELOG.md <<EOF | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
This project uses [*towncrier*](https://towncrier.readthedocs.io/) and the changes for the upcoming release can be found in <https://github.com/twisted/my-project/tree/main/changelog.d/>. | ||
|
||
<!-- towncrier release notes start --> | ||
|
||
|
||
EOF | ||
|
||
.. note:: | ||
|
||
The two empty lines at the end are on purpose. | ||
|
||
That's it! | ||
You can start adding news fragments: | ||
|
||
.. code-block:: console | ||
|
||
$ towncrier create -c "Added a cool feature!" 1.added.md | ||
$ towncrier create -c "Changed a behavior!" 2.changed.md | ||
$ towncrier create -c "Deprecated a module!" 3.deprecated.md | ||
$ towncrier create -c "Removed a square feature!" 4.removed.md | ||
$ towncrier create -c "Fixed a bug!" 5.fixed.md | ||
$ towncrier create -c "Fixed a security issue!" 6.security.md | ||
$ towncrier create -c "Fixed a security issue!" 7.security.md | ||
$ towncrier create -c "A fix without an issue number!" +something-unique.fixed.md | ||
|
||
|
||
After running ``towncrier build --yes --version 1.0.0`` (you can ignore the Git error messages) your ``CHANGELOG.md`` looks like this: | ||
|
||
.. code-block:: markdown | ||
|
||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
This project uses [*towncrier*](https://towncrier.readthedocs.io/) and the changes for the upcoming release can be found in <https://github.com/twisted/my-project/tree/main/changelog.d/>. | ||
|
||
<!-- towncrier release notes start --> | ||
|
||
## [1.0.0](https://github.com/twisted/my-project/tree/1.0.0) - 2022-09-28 | ||
|
||
|
||
### Added | ||
|
||
- Added a cool feature! [#1](https://github.com/twisted/my-project/issues/1) | ||
|
||
|
||
### Changed | ||
|
||
- Changed a behavior! [#2](https://github.com/twisted/my-project/issues/2) | ||
|
||
|
||
### Deprecated | ||
|
||
- Deprecated a module! [#3](https://github.com/twisted/my-project/issues/3) | ||
|
||
|
||
### Fixed | ||
|
||
- Fixed a bug! [#5](https://github.com/twisted/my-project/issues/5) | ||
- A fix without an issue number! | ||
|
||
|
||
### Removed | ||
|
||
- Removed a square feature! [#4](https://github.com/twisted/my-project/issues/4) | ||
|
||
|
||
### Security | ||
|
||
- Fixed a security issue! [#6](https://github.com/twisted/my-project/issues/6), [#7](https://github.com/twisted/my-project/issues/7) | ||
|
||
|
||
Pretty close, so this concludes this guide! | ||
|
||
.. note:: | ||
|
||
- Because ``towncrier`` doesn't have a concept of a "previous version" (yet), the version links will point to the release tags and not to the ``compare`` link like in *Keep a Changelog*. | ||
- *Keep a Changelog* doesn't have the concept of a uncategorized change, so the template doesn't expect any. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Added a Markdown-based how-to guide. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now is ok.
I expect that Markdown is a common use case, so we might want to have a predefined markdown template, that is maintained by the main dev team.