From 3ed8dfb742f65904981493f8edfe642a99e63f84 Mon Sep 17 00:00:00 2001 From: Silvano Cerza <3314350+silvanocerza@users.noreply.github.com> Date: Tue, 19 Nov 2024 10:23:08 +0100 Subject: [PATCH] ci: Fix changelog generation (#1199) * Fix changelog creation to also show PRs that don't have conventional commits * Fix file glob for changelog creation * Handle commits with multiple lines * Add PR number * Hide commits that just update the changelog * Fix sorting --- .github/workflows/CI_pypi_release.yml | 2 +- cliff.toml | 74 ++++++++++++++++++++------- 2 files changed, 57 insertions(+), 19 deletions(-) diff --git a/.github/workflows/CI_pypi_release.yml b/.github/workflows/CI_pypi_release.yml index e29d3ea36..1162ca3b3 100644 --- a/.github/workflows/CI_pypi_release.yml +++ b/.github/workflows/CI_pypi_release.yml @@ -54,7 +54,7 @@ jobs: with: config: cliff.toml args: > - --include-path "${{ steps.pathfinder.outputs.project_path }}/*" + --include-path "${{ steps.pathfinder.outputs.project_path }}/**/*" --tag-pattern "${{ steps.pathfinder.outputs.project_path }}-v*" - name: Commit changelog diff --git a/cliff.toml b/cliff.toml index 29228543e..45e4c647b 100644 --- a/cliff.toml +++ b/cliff.toml @@ -19,11 +19,43 @@ body = """ ## [unreleased] {% endif %}\ {% for group, commits in commits | group_by(attribute="group") %} + {# + Skip the whole section if it contains only a single commit + and it's the commit that updated the changelog. + If we don't do this we get an empty section since we don't show + commits that update the changelog + #}\ + {% if commits | length == 1 and commits[0].message == 'Update the changelog' %}\ + {% continue %}\ + {% endif %}\ ### {{ group | striptags | trim | upper_first }} - {% for commit in commits %} + {% for commit in commits %}\ + {# + Skip commits that update the changelog, they're not useful to the user + #}\ + {% if commit.message == 'Update the changelog' %}\ + {% continue %}\ + {% endif %} - {% if commit.scope %}*({{ commit.scope }})* {% endif %}\ {% if commit.breaking %}[**breaking**] {% endif %}\ - {{ commit.message | upper_first }}\ + {# + We first try to render the conventional commit message if present. + If it's not a conventional commit we get the PR title if present. + If the commit is neither conventional, nor has a PR title set + we fallback to whatever the commit message is. + + We do this cause when merging PRs with multiple commits that don't + have a title following conventional commit guidelines we might get + a commit message that is multiple lines. That makes the changelog + look a bit funky so we handle it like so. + #}\ + {% if commit.conventional %}\ + {{ commit.message | upper_first }}\ + {% elif commit.remote.pr_title %}\ + {{ commit.remote.pr_title | upper_first }} (#{{ commit.remote.pr_number }})\ + {% else %}\ + {{ commit.message | upper_first }}\ + {% endif %}\ {% endfor %} {% endfor %}\n """ @@ -35,7 +67,7 @@ footer = """ trim = true # postprocessors postprocessors = [ - # { pattern = '', replace = "https://github.com/orhun/git-cliff" }, # replace repository URL + # { pattern = '', replace = "https://github.com/orhun/git-cliff" }, # replace repository URL ] [git] @@ -47,24 +79,26 @@ filter_unconventional = false split_commits = false # regex for preprocessing the commit messages commit_preprocessors = [ - # Replace issue numbers - #{ pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](/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 -' }, + # Replace issue numbers + #{ pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](/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 -' }, ] # regex for parsing and grouping commits commit_parsers = [ - { message = "^feat", group = "๐Ÿš€ Features" }, - { message = "^fix", group = "๐Ÿ› Bug Fixes" }, - { message = "^doc", group = "๐Ÿ“š Documentation" }, - { message = "^perf", group = "โšก Performance" }, - { message = "^refactor", group = "๐Ÿšœ Refactor" }, - { message = "^style", group = "๐ŸŽจ Styling" }, - { message = "^test", group = "๐Ÿงช Testing" }, - { message = "^chore|^ci", group = "โš™๏ธ Miscellaneous Tasks" }, - { body = ".*security", group = "๐Ÿ›ก๏ธ Security" }, - { message = "^revert", group = "โ—€๏ธ Revert" }, + { message = "^feat", group = "๐Ÿš€ Features" }, + { message = "^fix", group = "๐Ÿ› Bug Fixes" }, + { message = "^refactor", group = "๐Ÿšœ Refactor" }, + { message = "^doc", group = "๐Ÿ“š Documentation" }, + { message = "^perf", group = "โšก Performance" }, + { message = "^style", group = "๐ŸŽจ Styling" }, + { message = "^test", group = "๐Ÿงช Testing" }, + { body = ".*security", group = "๐Ÿ›ก๏ธ Security" }, + { message = "^revert", group = "โ—€๏ธ Revert" }, + { message = "^ci", group = "โš™๏ธ CI" }, + { message = "^chore", group = "๐Ÿงน Chores" }, + { message = ".*", group = "๐ŸŒ€ Miscellaneous" }, ] # protect breaking changes from being skipped due to matching a skipping commit_parser protect_breaking_commits = false @@ -82,3 +116,7 @@ topo_order = false sort_commits = "oldest" # limit the number of commits included in the changelog. # limit_commits = 42 + +[remote.github] +owner = "deepset-ai" +repo = "haystack-core-integrations"