{% import ".macros.j2" as macros %}

{#-
Changelog template for python-semantic-release (PSR).

This template intentionally regenerates the full changelog from git history on
each run.

Rationale:
- "Splice" logic (string-splitting existing CHANGELOG.md) is brittle and tends
  to duplicate blocks or silently skip releases.
- Deterministic regeneration is easier to reason about and easier to verify.
-#}

# 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.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

<!-- PSR-INSERT-FLAG -->

{%- set releases = context.history.released.values() | list | sort(attribute='version', reverse=true) %}

{% if context.history.unreleased and macros.has_renderable_commits(context.history.unreleased) %}
## [Unreleased]

{{ macros.render_changelog_entry(context.history.unreleased) | trim }}

{% endif -%}

{%- for release in releases %}
## [{{ release.version }}] - {{ release.tagged_date.strftime('%Y-%m-%d') }}

{% set body_trimmed = macros.render_changelog_entry(release.elements) | trim -%}
{% if body_trimmed %}
{{ body_trimmed }}
{% else %}
_No user-facing changes._
{% endif -%}
{% if not loop.last %}

{% endif -%}
{%- endfor %}

<!-- PSR-LINKS-START -->
{{ macros.render_comparison_links(context.history) }}
