bakdata / ci-templates

Collection of reusable workflows and composite actions for Github
MIT License
4 stars 1 forks source link

Feat: New changelog generator #205

Open DerTiedemann opened 3 months ago

DerTiedemann commented 3 months ago

New changelog generator: https://git-cliff.org/ This action updated replaces the previous generator with the aforementioned tool.

All existing functionality has been preserved and some new things have been added, most notably the first contribution mention. The action will check of there is a cliff.toml present in the current repo and if not use the default that is present inside of this repo. Custom configs are sometimes required to filter out commits that dont contain meaningful changes like version bumps. An example of how this could look for streams-bootstrap:

# ommited
commit_parsers = [
  { message = "^\\[Gradle Release Plugin\\]", skip = true },
  { message = "^Changelog for version .*", skip = true },
]

Which turns changelogs that look like this:

2.23.0 - 2024-06-12

What's changed

Full Changelog: https://github.com/bakdata/streams-bootstrap/compare/2.22.1...2.23.0

into this:

2.23.0 - 2024-06-12

What's changed

Full Changelog: https://github.com/bakdata/streams-bootstrap/compare/2.22.1...2.23.0


For more config options have a look at the docs, this thing is pretty powerful. Let me know what you think.

DerTiedemann commented 2 months ago

I was asked if this can also group by labels, a little tricky but its possible with this config:

# git-cliff ~ default configuration file
# https://git-cliff.org/docs/configuration
#
# Lines starting with "#" are comments.
# Configuration options are organized into tables and keys.
# See documentation for more information on available options.

[changelog]
# template for the changelog footer
header = """
# Changelog\n
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 = """
{%- macro remote_url() -%}\
  https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}
{%- endmacro -%}
{%- if version -%}
    ## [{{ version | trim_start_matches(pat="v") }}]({{ self::remote_url() }}/tree/{{ version | trim_start_matches(pat="v")}}) - {{ timestamp | date(format="%Y-%m-%d") }}
{%- else -%}
    ## [unreleased]
{%- endif %}
### What's changed
{% for _groups, commits in commits | group_by(attribute="github.pr_labels") %}

  {%- set groups = _groups | trim_start_matches(pat="[") | trim_end_matches(pat="]") | trim | split(pat=",") -%}
  {%- set_global labels = [] -%}
  {%- for group in groups -%}
    {% set_global label = group | trim_start_matches(pat='"') | trim_end_matches(pat='"') %}
    {% if label == "" %}{% set label = "Uncategorized" %}{% endif %}
    {% set_global labels = labels | concat(with=label) %}
  {%- endfor -%}

  {%- if labels | length > 0 %}
    #### {{ labels | join(sep=" & ") }}
      {% for commit in commits %}
        {% if commit.github.pr_title -%}\
          {%- set commit_message = commit.github.pr_title -%}
        {%- else -%}
          {%- set commit_message = commit.message -%}
        {%- endif -%}
        * {{ commit_message | split(pat="\n") | first | trim }}\
          {% if commit.github.username %} by @{{ commit.github.username }}{%- endif -%}
          {% if commit.github.pr_number %} in \
            [#{{ commit.github.pr_number }}]({{ self::remote_url() }}/pull/{{ commit.github.pr_number }}) \
          {%- endif %}    
    {%- endfor -%}
  {%- endif -%}
{% endfor %}\n
{%- if github -%}
{% if github.contributors | filter(attribute="is_first_time", value=true) | length != 0 %}
  {% raw %}\n{% endraw -%}
  ### New Contributors
{%- endif %}\
{% for contributor in github.contributors | filter(attribute="is_first_time", value=true) %}
  * @{{ contributor.username }} made their first contribution
    {%- if contributor.pr_number %} in \
      [#{{ contributor.pr_number }}]({{ self::remote_url() }}/pull/{{ contributor.pr_number }}) \
    {%- endif %}
{%- endfor -%}
{%- endif -%}

{% if version %}
    {% if previous.version %}
      **Full Changelog**: {{ self::remote_url() }}/compare/{{ previous.version }}...{{ version }}
    {% endif %}
{% endif %}
"""
# template for the changelog footer
footer = """
<!-- generated by git-cliff -->
"""
# remove the leading and trailing s
trim = true
# postprocessors
postprocessors = [
  # { pattern = '<REPO>', replace = "https://github.com/orhun/git-cliff" }, # replace repository URL
]

[git]
# parse the commits based on https://www.conventionalcommits.org
conventional_commits = true
# filter out the commits that are not conventional
filter_unconventional = false
# process each line of a commit as an individual commit
split_commits = false
# regex for preprocessing the commit messages
commit_preprocessors = [
  # Replace issue numbers
  #{ pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](<REPO>/issues/${2}))"},
  # Check spelling of the commit with https://github.com/crate-ci/typos
  # If the spelling is incorrect, it will be automatically fixed.
  #{ pattern = '.*', replace_command = 'typos --write-changes -' },
]
commit_parsers = [{ message = "^Bump version", skip = true }]
# regex for parsing and grouping commits
# protect breaking changes from being skipped due to matching a skipping commit_parser
protect_breaking_commits = false
# filter out the commits that are not matched by commit parsers
filter_commits = false
# regex for matching git tags
# tag_pattern = "v[0-9].*"
# regex for skipping tags
# skip_tags = ""
# regex for ignoring tags
# ignore_tags = ""
# sort the tags topologically
topo_order = false
# sort the commits inside sections by oldest/newest order
sort_commits = "oldest"
# limit the number of commits included in the changelog.
# limit_commits = 42

which produces changelogs like this for kpops:

Changelog

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

6.1.0 - 2024-07-09

What's changed

type/enhancement & component/handlers

type/enhancement & component/pipeline-components

type/refactor

Full Changelog: https://github.com/bakdata/kpops/compare/6.0.2...6.1.0

6.0.2 - 2024-07-04

What's changed

area/documentation

Uncategorized

Full Changelog: https://github.com/bakdata/kpops/compare/6.0.1...6.0.2

6.0.1 - 2024-06-12

What's changed

type/bug & component/pipeline-components

Full Changelog: https://github.com/bakdata/kpops/compare/6.0.0...6.0.1

6.0.0 - 2024-06-06

What's changed

type/enhancement & type/refactor & component/cli & breaking-change

Full Changelog: https://github.com/bakdata/kpops/compare/5.1.1...6.0.0

5.1.1 - 2024-05-22

What's changed

type/bug

Full Changelog: https://github.com/bakdata/kpops/compare/5.1.0...5.1.1

5.1.0 - 2024-05-22

What's changed

component/pipeline-components

Full Changelog: https://github.com/bakdata/kpops/compare/5.0.1...5.1.0