Skip to content

Commit

Permalink
ci: account for python-semantic-release changes (#421)
Browse files Browse the repository at this point in the history
The most recent weekly dependency bump caused the
`python-semantic-release` package to be upgraded from v9.4.2 --> v9.6.0,
which introduced breaking changes. With the irony noted, this PR seeks
to account for the changes with the following actions:

* Replace instances of `--prerelease` with `--as-prerelease`
  * This was the breaking change
* Make use of the new `compare_url` filter
  * Remove the custom macro that did the same thing
* Remove `.macros.j2` file since it only contains a constant used once
  • Loading branch information
maxrake authored Apr 29, 2024
1 parent dd4c1a3 commit 83d3698
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 29 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ jobs:
next_ver=$(poetry run semantic-release -vv version --print)
if [ "${{ env.PHYLUM_ORIGINAL_VER }}" = "${next_ver}" ]; then
if [ "${{ inputs.prerelease }}" = "true" ]; then
next_ver=$(poetry run semantic-release -vv --strict version --print --prerelease --patch)
next_ver=$(poetry run semantic-release -vv --strict version --print --as-prerelease --patch)
else
next_ver=$(poetry run semantic-release -vv --strict version --print --patch)
fi
else
if [ "${{ inputs.prerelease }}" = "true" ]; then
next_ver=$(poetry run semantic-release -vv --strict version --print --prerelease)
next_ver=$(poetry run semantic-release -vv --strict version --print --as-prerelease)
fi
fi
poetry version "${next_ver}"
Expand Down Expand Up @@ -152,13 +152,13 @@ jobs:
run: |
if [ "${{ env.PHYLUM_ORIGINAL_VER }}" = "${{ env.PHYLUM_NEXT_VER }}" ]; then
if [ "${{ inputs.prerelease }}" = "true" ]; then
poetry run semantic-release -vv --strict version --prerelease --patch
poetry run semantic-release -vv --strict version --as-prerelease --patch
else
poetry run semantic-release -vv --strict version --patch
fi
else
if [ "${{ inputs.prerelease }}" = "true" ]; then
poetry run semantic-release -vv --strict version --prerelease
poetry run semantic-release -vv --strict version --as-prerelease
else
poetry run semantic-release -vv version
fi
Expand Down
16 changes: 0 additions & 16 deletions templates/.macros.j2

This file was deleted.

6 changes: 2 additions & 4 deletions templates/.release_notes.md.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +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
#}
{% from ".macros.j2" import version_compare_url %}
{% set releases = context.history.released.items() | list %}
{% set prev_version = releases[1][0] %}
{% set full_changelog_url = version_compare_url(prev_version, version) %}
{% set prev_version = "v{}".format(releases[1][0]) %}
{% include ".changes.j2" %}
**Full Changelog**: {{ full_changelog_url }}
**Full Changelog**: {{ prev_version | compare_url("v{}".format(version)) }}
19 changes: 14 additions & 5 deletions templates/CHANGELOG.md.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
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
#}
{% import ".macros.j2" as macros %}
# Changelog

All notable changes to this project will be documented in this file.
Expand All @@ -18,14 +17,24 @@ and understanding.
[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() > macros.min_release_timestamp
release.tagged_date.timestamp() > min_release_timestamp
and ("unknown" not in release.elements or release.elements | length > 1)
%}
{% if loop.nextitem %}
{% set prev_version = loop.nextitem[0] %}
{% set compare_url = macros.version_compare_url(prev_version, version) %}
## [{{ version.as_tag() }}]({{ compare_url }}) ({{ release.tagged_date.strftime("%Y-%m-%d") }})
{% 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 %}
Expand Down

0 comments on commit 83d3698

Please sign in to comment.