Skip to content
Draft
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
16 changes: 15 additions & 1 deletion git-cliff-release/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 '/<!-- git-cliff-unreleased-start -->/,/<!-- git-cliff-unreleased-end -->/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 '
/<!-- git-cliff-unreleased-start -->/ { in_unreleased = 1 }
in_unreleased { if (/<!-- git-cliff-unreleased-end -->/) { 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)
Expand All @@ -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 '<!-- git-cliff-unreleased-start -->' $out_file; then
sed -i '0,/^## /s//<!-- git-cliff-unreleased-start -->\n\n<!-- git-cliff-unreleased-end -->\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
Expand Down
10 changes: 4 additions & 6 deletions git-cliff-release/cliff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}<!-- git-cliff-unreleased-start -->
{% endif %}\
{% if not version %}<!-- git-cliff-unreleased-start -->\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
Expand All @@ -47,9 +46,8 @@ body = """
{% endif %}\
{%- endif %}\
{% endfor %}
{% endfor %}\n
{% if not version %}<!-- git-cliff-unreleased-end -->
{% endif %}\
{% endfor %}
{% if not version %}<!-- git-cliff-unreleased-end -->\n\n{% endif %}\
"""
# template for the changelog footer
footer = """
Expand Down
Loading