Skip to content

Commit 74f305e

Browse files
authored
build: update psr templates (#242)
After updating python-semantic-release the custom changelog and release notes templates stopped working as expected. The changelog and release notes generated for 0.10.0 e.g. did not display feature commits. This commit introduces modified versions of the new default templates of python-semantic-release. Fixes #229
1 parent e902cb1 commit 74f305e

14 files changed

+679
-70
lines changed

.github/templates/.changes.j2

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{#
2+
3+
This template is adapted from:
4+
"python-semantic-release" (MIT License)
5+
https://github.com/python-semantic-release/python-semantic-release/blob/v9.17.0/src/semantic_release/data/templates/angular/md/.components/changelog_header.md.j2
6+
7+
#}
8+
# Changelog
9+
10+
All notable changes to this project will be documented in this file.
11+
12+
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). See
13+
[conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) for commit guidelines.
14+
{% if ctx.changelog_mode == "update"
15+
%}{# # IMPORTANT: add insertion flag for next version update
16+
#}{{
17+
insertion_flag ~ "\n"
18+
19+
}}{% endif
20+
%}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{#
2+
3+
This template is adapted from:
4+
"python-semantic-release" (MIT License)
5+
https://github.com/python-semantic-release/python-semantic-release/blob/v9.17.0/src/semantic_release/data/templates/angular/md/.components/changelog_init.md.j2
6+
7+
#}{#
8+
This changelog template initializes a full changelog for the project,
9+
it follows the following logic:
10+
1. Header
11+
2. Any Unreleased Details (uncommon)
12+
3. all previous releases except the very first release
13+
4. the first release
14+
15+
#}{#
16+
# Header
17+
#}{% include "changelog_header.md.j2"
18+
%}{#
19+
# Any Unreleased Details (uncommon)
20+
#}{% include "unreleased_changes.md.j2"
21+
%}{#
22+
# Since this is initialization, we are generating all the previous
23+
# release notes per version. The very first release notes is specialized
24+
#}{% if releases | length > 0
25+
%}{% for release in releases
26+
%}{% if loop.last and ctx.mask_initial_release
27+
%}{%- include "first_release.md.j2"
28+
-%}{% else
29+
%}{%- include "versioned_changes.md.j2"
30+
-%}{% endif
31+
%}{{ "\n"
32+
}}{% endfor
33+
%}{% endif
34+
%}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{#
2+
3+
This template is adapted from:
4+
"python-semantic-release" (MIT License)
5+
https://github.com/python-semantic-release/python-semantic-release/blob/v9.17.0/src/semantic_release/data/templates/angular/md/.components/changelog_update.md.j2
6+
7+
#}{#
8+
This Update changelog template uses the following logic:
9+
10+
1. Read previous changelog file (ex. project_root/CHANGELOG.md)
11+
2. Split on insertion flag (ex. <!-- version list -->)
12+
3. Print top half of previous changelog
13+
3. New Changes (unreleased commits & newly released)
14+
4. Print bottom half of previous changelog
15+
16+
Note: if a previous file was not found, it does not write anything at the bottom
17+
but render does NOT fail
18+
19+
#}{% set prev_changelog_contents = prev_changelog_file | read_file | safe
20+
%}{% set changelog_parts = prev_changelog_contents.split(insertion_flag, maxsplit=1)
21+
%}{#
22+
#}{% if changelog_parts | length < 2
23+
%}{# # insertion flag was not found, check if the file was empty or did not exist
24+
#}{% if prev_changelog_contents | length > 0
25+
%}{# # File has content but no insertion flag, therefore, file will not be updated
26+
#}{{ changelog_parts[0]
27+
}}{% else
28+
%}{# # File was empty or did not exist, therefore, it will be created from scratch
29+
#}{% include "changelog_init.md.j2"
30+
%}{% endif
31+
%}{% else
32+
%}{#
33+
# Previous Changelog Header
34+
# - Depending if there is header content, then it will separate the insertion flag
35+
# with a newline from header content, otherwise it will just print the insertion flag
36+
#}{% set prev_changelog_top = changelog_parts[0] | trim
37+
%}{% if prev_changelog_top | length > 0
38+
%}{{
39+
"%s\n\n%s\n" | format(prev_changelog_top, insertion_flag | trim)
40+
41+
}}{% else
42+
%}{{
43+
"%s\n" | format(insertion_flag | trim)
44+
45+
}}{% endif
46+
%}{% if releases | length > 0
47+
%}{# # Latest Release Details
48+
#}{% set release = releases[0]
49+
%}{#
50+
#}{% if releases | length == 1 and ctx.mask_initial_release
51+
%}{# # First Release detected
52+
#}{{ "\n"
53+
}}{%- include "first_release.md.j2"
54+
-%}{{ "\n"
55+
}}{#
56+
#}{% elif "# " ~ release.version.as_semver_tag() ~ " " not in changelog_parts[1]
57+
%}{# # The release version is not already in the changelog so we add it
58+
#}{{ "\n"
59+
}}{%- include "versioned_changes.md.j2"
60+
-%}{#
61+
#}{% endif
62+
%}{% endif
63+
%}{#
64+
# Previous Changelog Footer
65+
# - skips printing footer if empty, which happens when the insertion_flag
66+
# was at the end of the file (ignoring whitespace)
67+
#}{% set previous_changelog_bottom = changelog_parts[1] | trim
68+
%}{% if previous_changelog_bottom | length > 0
69+
%}{{ "\n%s\n" | format(previous_changelog_bottom)
70+
}}{% endif
71+
%}{% endif
72+
%}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
{#
2+
3+
This template is adapted from:
4+
"python-semantic-release" (MIT License)
5+
https://github.com/python-semantic-release/python-semantic-release/blob/v9.17.0/src/semantic_release/data/templates/angular/md/.components/changes.md.j2
6+
7+
#}{% from 'macros.md.j2' import apply_alphabetical_ordering_by_brk_descriptions
8+
%}{% from 'macros.md.j2' import apply_alphabetical_ordering_by_descriptions
9+
%}{% from 'macros.md.j2' import format_breaking_changes_description, format_commit_summary_line
10+
%}{% from 'custom.md.j2' import section_heading_order
11+
%}{#
12+
EXAMPLE:
13+
14+
### Features
15+
16+
- Add new feature ([#10](https://domain.com/namespace/repo/pull/10),
17+
[`abcdef0`](https://domain.com/namespace/repo/commit/HASH))
18+
19+
- **scope**: Add new feature ([`abcdef0`](https://domain.com/namespace/repo/commit/HASH))
20+
21+
### Bug Fixes
22+
23+
- Fix bug ([#11](https://domain.com/namespace/repo/pull/11),
24+
[`abcdef1`](https://domain.com/namespace/repo/commit/HASH))
25+
26+
### BREAKING CHANGES
27+
28+
- With the change _____, the change causes ___ effect. Ultimately, this section
29+
it is a more detailed description of the breaking change. With an optional
30+
scope prefix like the commit messages above.
31+
32+
- **scope**: this breaking change has a scope to identify the part of the code that
33+
this breaking change applies to for better context.
34+
35+
#}{% set max_line_width = max_line_width | default(120)
36+
%}{% set hanging_indent = hanging_indent | default(2)
37+
%}{#
38+
#}{% for type_ in section_heading_order if type_ in commit_objects
39+
%}{# PREPROCESS COMMITS (order by description & format description line)
40+
#}{% set ns = namespace(commits=commit_objects[type_])
41+
%}{{ apply_alphabetical_ordering_by_descriptions(ns) | default("", true)
42+
}}{#
43+
#}{% set commit_descriptions = []
44+
%}{#
45+
#}{% for commit in ns.commits
46+
%}{# # Add reference links to the commit summary line
47+
#}{% set description = "- %s" | format(format_commit_summary_line(commit))
48+
%}{% set description = description | autofit_text_width(max_line_width, hanging_indent)
49+
%}{{ commit_descriptions.append(description) | default("", true)
50+
}}{% endfor
51+
%}{#
52+
# # PRINT SECTION (header & commits)
53+
#}{{ "\n"
54+
}}{{ "### %s\n" | format(type_ | title)
55+
}}{{ "\n"
56+
}}{{ "%s\n" | format(commit_descriptions | unique | join("\n"))
57+
}}{% endfor
58+
-%}
59+
{#
60+
# # Determine if any commits have a breaking change
61+
# # commit_objects is a dictionary of strings to a list of commits { "Features", [ParsedCommit(), ...] }
62+
#}{% set breaking_commits = []
63+
%}{% for commits in commit_objects.values()
64+
%}{# # Filter out breaking change commits that have no breaking descriptions
65+
#}{{ breaking_commits.extend(
66+
commits | rejectattr("error", "defined") | selectattr("breaking_descriptions.0")
67+
) | default("", true)
68+
}}{% endfor
69+
%}{#
70+
#}{% if breaking_commits | length > 0
71+
%}{# PREPROCESS COMMITS
72+
#}{% set brk_ns = namespace(commits=breaking_commits)
73+
%}{{ apply_alphabetical_ordering_by_brk_descriptions(brk_ns) | default("", true)
74+
}}{#
75+
#}{% set brking_descriptions = []
76+
%}{#
77+
#}{% for commit in brk_ns.commits
78+
%}{% set full_description = "- %s" | format(
79+
format_breaking_changes_description(commit).split("\n\n") | join("\n\n- ")
80+
)
81+
%}{{ brking_descriptions.append(
82+
full_description | autofit_text_width(max_line_width, hanging_indent)
83+
) | default("", true)
84+
}}{% endfor
85+
%}{#
86+
# # PRINT BREAKING CHANGE DESCRIPTIONS (header & descriptions)
87+
#}{{ "\n"
88+
}}{{ "### BREAKING CHANGES\n"
89+
}}{{
90+
"\n%s\n" | format(brking_descriptions | unique | join("\n\n"))
91+
}}{#
92+
#}{% endif
93+
-%}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{# Ref: https://github.com/python-semantic-release/python-semantic-release/issues/1122#issuecomment-2542518505
2+
3+
The types in the section header order corresponds to the ones defined in
4+
PSR's angular commit parser:
5+
https://github.com/python-semantic-release/python-semantic-release/blob/7b3f71697ccfbaef884e1e754b6364e974b134cf/src/semantic_release/commit_parser/angular.py#L46
6+
7+
#}
8+
{% set section_heading_order = [
9+
"features",
10+
"bug fixes",
11+
"performance improvements",
12+
"refactoring",
13+
"testing",
14+
"documentation",
15+
] %}

0 commit comments

Comments
 (0)