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

build: account for Python Semantic Release updates #483

Merged
merged 3 commits into from
Oct 17, 2024
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ and understanding.
[conventional commits]: https://www.conventionalcommits.org
[Python Semantic Release]: https://python-semantic-release.readthedocs.io/en/latest/index.html

<!--next-version-placeholder-->

## [v0.51.0](https://github.com/phylum-dev/phylum-ci/compare/v0.50.0...v0.51.0) (2024-10-09)

### Feature
Expand Down
6 changes: 3 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ logging_use_named_masks = true
[tool.semantic_release.publish]
dist_glob_patterns = ["dist/*", "build/phylum-ci.exe", "build/phylum-ci.zip"]

[tool.semantic_release.changelog]
mode = "update"
insertion_flag = "<!--next-version-placeholder-->"

[tool.semantic_release.changelog.environment]
trim_blocks = true
lstrip_blocks = true
Expand Down
571 changes: 0 additions & 571 deletions templates/.CHANGELOG_historic.md

This file was deleted.

3 changes: 2 additions & 1 deletion templates/.changes.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% set included_commit_types = ("breaking", "feature", "fix", "performance", "documentation") %}
{% set included_commit_types = ("breaking", "features", "fixes", "performance improvements", "documentation") %}

{% for commit_type in included_commit_types if commit_type in release.elements %}
### {{ commit_type | capitalize }}

Expand Down
2 changes: 1 addition & 1 deletion templates/.release_notes.md.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
This is a Jinja template for generating release notes with Python Semantic Release.
Ref: https://python-semantic-release.readthedocs.io/en/latest/changelog_templates.html
#}
{% set releases = context.history.released.items() | list %}
{% set releases = ctx.history.released.items() | list %}
{% set prev_version = releases[1][0].as_tag() %}
{% include ".changes.j2" %}
**Full Changelog**: {{ prev_version | compare_url(version.as_tag()) }}
52 changes: 13 additions & 39 deletions templates/CHANGELOG.md.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,17 @@
This is a Jinja template for generating the CHANGELOG with Python Semantic Release.
Ref: https://python-semantic-release.readthedocs.io/en/latest/changelog_templates.html
#}
# Changelog

All notable changes to this project will be documented in this file.

The format is partially based on [Keep a Changelog], and this project adheres to
[Semantic Versioning]. The entries in this changelog are primarily automatically
generated through the use of [conventional commits] and the [Python Semantic Release]
tool. However, some entries may be manually edited, where it helps for clarity
and understanding.

[Keep a Changelog]: https://keepachangelog.com/en/1.0.0/
[Semantic Versioning]: https://semver.org/spec/v2.0.0.html
[conventional commits]: https://www.conventionalcommits.org
[Python Semantic Release]: https://python-semantic-release.readthedocs.io/en/latest/index.html

{#
The filter for releases that aren't already in the historic CHANGELOG (which
gets included at the end of this template) is done by release tag timestamp
instead of version since the version comparison is only possible as strings,
which does not properly account for individual components of the version.
New timestamps can be computed in Python as:

min_release_timestamp = datetime.datetime(year=2024, month=1, day=6).timestamp()
#}
{% set min_release_timestamp = 1704520800.0 %}
{% for version, release in context.history.released.items() if
release.tagged_date.timestamp() > min_release_timestamp
and ("unknown" not in release.elements or release.elements | length > 1)
%}
{% if loop.nextitem %}
{% set prev_version = "v{}".format(loop.nextitem[0]) %}
{% set ver_compare_url = prev_version | compare_url("v{}".format(version)) %}
## [{{ version.as_tag() }}]({{ ver_compare_url }}) ({{ release.tagged_date.strftime("%Y-%m-%d") }})
{% else %}
## {{ version.as_tag() }} ({{ release.tagged_date.strftime("%Y-%m-%d") }})
{% endif %}

{% set releases = ctx.history.released.items() | list %}
{% set release = releases[0][1] %}
{% set curr_version = releases[0][0].as_tag() %}
{% set prev_version = releases[1][0].as_tag() %}
{% set ver_compare_url = prev_version | compare_url(curr_version) %}
{% set insertion_flag = ctx.changelog_insertion_flag %}
{% set prev_changelog_contents = ctx.prev_changelog_file | read_file | safe %}
{% set changelog_parts = prev_changelog_contents.split(insertion_flag, maxsplit=1) %}
{% set prev_changelog_top = changelog_parts[0] | trim %}
{% set prev_changelog_bottom = changelog_parts[1] | trim %}
{{ "%s\n\n%s\n" | format(prev_changelog_top, insertion_flag | trim) }}
## [{{ curr_version }}]({{ ver_compare_url }}) ({{ release.tagged_date.strftime("%Y-%m-%d") }})
{% include ".changes.j2" %}
{% endfor %}
{% include ".CHANGELOG_historic.md" %}
{{ "%s" | format(prev_changelog_bottom) }}