From eedf6d026a91872139af9e827b68ded415cacbb2 Mon Sep 17 00:00:00 2001 From: Oleg Shparber Date: Sat, 7 Sep 2024 22:50:27 -0400 Subject: [PATCH] ci(github): use git-cliff to draft changelog --- .github/workflows/release.yaml | 10 +++ .github/workflows/release/cliff.toml | 99 ++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 .github/workflows/release/cliff.toml diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 479708f..db04f61 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -175,11 +175,21 @@ jobs: - name: Package Source run: cmake --build build --preset ${{ matrix.config.buildPreset }} --target package_source + - name: Generate Changelog + uses: orhun/git-cliff-action@v4 + id: git-cliff + with: + args: --latest + config: .github/workflows/release/cliff.toml + env: + GITHUB_REPO: ${{ github.repository }} + - name: Update GitHub Release uses: softprops/action-gh-release@v2 with: draft: true fail_on_unmatched_files: true + body: ${{ steps.git-cliff.outputs.content }} # Only upload the following artifacts: # - Source packages. files: | diff --git a/.github/workflows/release/cliff.toml b/.github/workflows/release/cliff.toml new file mode 100644 index 0000000..a4adeea --- /dev/null +++ b/.github/workflows/release/cliff.toml @@ -0,0 +1,99 @@ +# git-cliff ~ configuration file +# https://git-cliff.org/docs/configuration + +# Set via GITHUB_REPO and GITHUB_TOKEN environment variables. +#[remote.github] +#owner = "zealdocs" +#repo = "zeal" +#token = "" + +[changelog] +# Template docs: https://keats.github.io/tera/docs/. +body = """\ + +{% if version and previous.version %} + [Full Changelog]({{ self::diff_url() }}) | [Resolved Issues]({{ self::remote_url() }}/milestone/TBD?closed=1) +{% endif %}\ + +{% for group, commits in commits | group_by(attribute="group") %} + ### {{ group | striptags | trim }} + {% for commit in commits %} + {% if commit.github.pr_title -%} + {%- set commit_message = commit.github.pr_title -%} + {%- else -%} + {%- set commit_message = commit.message -%} + {%- endif -%} + - {% if commit.scope %}**{{ commit.scope }}:** {% endif %}\ + {{ commit.message | split(pat="\n") | first | trim }} \ + ({{ self::commit_link(id=commit.id) }})\ + {% endfor %} +{% endfor %} +--- + +{%- 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 \ + {{ self::pr_link(pr_number=contributor.pr_number) }}\ + {%- endif %} +{%- endfor -%} +{%- endif -%} + +{%- macro remote_url() -%} + https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }} +{%- endmacro -%} + +{%- macro diff_url() -%} + {{ self::remote_url() }}/compare/{{ previous.version }}...{{ version }} +{%- endmacro -%} + +{%- macro pr_link(pr_number) -%} + [#{{ pr_number }}]({{ self::remote_url() }}/pull/{{ pr_number }}) +{%- endmacro -%} + +{%- macro commit_link(id) -%} + [`{{ id | truncate(length=7, end="") }}`]({{ self::remote_url() }}/commit/{{ id }}) +{%- endmacro -%} +""" +# Remove the leading and trailing whitespace from the template. +trim = true +# Template for the changelog footer. +footer = """ +""" +# Postprocessors. +postprocessors = [] + +[git] +# Parse the commits based on https://www.conventionalcommits.org. +conventional_commits = true +# Filter out the commits that are not conventional. +filter_unconventional = true +# Process each line of a commit as an individual commit. +split_commits = false +# Regex for preprocessing the commit messages. +commit_preprocessors = [ + # Remove issue numbers from commits. + { pattern = '\((\w+\s)?#([0-9]+)\)', replace = "" }, +] +# Regex for parsing and grouping commits. +commit_parsers = [ + { message = "^feat", group = "Features" }, + { message = "^fix", group = "Bug Fixes" }, + { message = "^perf", group = "Performance" }, + { message = "^doc", group = "Documentation" }, + { message = "^build", group = "Build System" }, + { message = "^ci", group = "CI/CD" }, + # Skipped groups: + { message = "^chore", skip = true }, + { message = "^refactor", skip = true }, +] +# Filter out the commits that are not matched by commit parsers. +filter_commits = false +# Sort the tags topologically. +topo_order = false +# Sort the commits inside sections by oldest/newest order. +sort_commits = "oldest"