diff --git a/git-cliff-release/action.yaml b/git-cliff-release/action.yaml index 214dc0f..b90d8c6 100644 --- a/git-cliff-release/action.yaml +++ b/git-cliff-release/action.yaml @@ -161,7 +161,14 @@ runs: if [[ -n "${{ inputs.existing_changelog_path }}" ]]; then out_file=$GIT_CLIFF_WORKDIR/existing_changelog.md cp "$GIT_CLIFF_REPOSITORY/${{ inputs.existing_changelog_path }}" $out_file - sed '//,//d' -i $out_file + # Drop the unreleased section including the blank lines right after it, so the freshly + # rendered section fully controls the spacing around the markers. + awk ' + // { in_unreleased = 1 } + in_unreleased { if (//) { in_unreleased = 0; after_unreleased = 1 }; next } + after_unreleased && /^$/ { next } + { after_unreleased = 0; print } + ' $out_file > $out_file.tmp && mv $out_file.tmp $out_file dump_context_args+=(--unreleased) print_changelog_args+=(--prepend "$out_file" --unreleased) @@ -183,6 +190,13 @@ runs: python enhance_context.py --repo $GITHUB_REPO "${enhance_context_args[@]}" | git-cliff --from-context - "${print_changelog_args[@]}" + # A stable release consumes the whole unreleased section and renders without the markers. + # Reinsert an empty marker block ahead of the first release section, so the markers are + # always present and the next prerelease has a stable structure to splice into. + if ! grep -q '' $out_file; then + sed -i '0,/^## /s//\n\n\n\n&/' $out_file + fi + sed -i '$a\' $out_file # Make sure there is a newline at the end of the output file # Stage the changelog for the artifact upload. Consumers that receive the changelog through an diff --git a/git-cliff-release/cliff.toml b/git-cliff-release/cliff.toml index 2f34c6a..36a7b13 100644 --- a/git-cliff-release/cliff.toml +++ b/git-cliff-release/cliff.toml @@ -16,13 +16,12 @@ All notable changes to this project will be documented in this file.\n # template for the changelog body # https://keats.github.io/tera/docs/#introduction body = """ -{% if not version %} -{% endif %}\ +{% if not version %}\n\n{% endif %}\ {% if version and extra.release_link %}\ ## [{{ version | trim_start_matches(pat="v") }}]({{ extra.release_link }}) ({{ timestamp | date(format="%Y-%m-%d") }}) {% elif extra.unreleased_version %}\ ## {{ extra.unreleased_version | trim_start_matches(pat="v") }} - **not yet released** -{% elif version %} +{% elif version %}\ ## {{ version | trim_start_matches(pat="v") }} ({{ timestamp | date(format="%Y-%m-%d") }}) {% else %}\ ## Unreleased @@ -47,9 +46,8 @@ body = """ {% endif %}\ {%- endif %}\ {% endfor %} -{% endfor %}\n -{% if not version %} -{% endif %}\ +{% endfor %} +{% if not version %}\n\n{% endif %}\ """ # template for the changelog footer footer = """