Skip to content

Commit

Permalink
ci(github): use git-cliff to draft changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
trollixx committed Sep 8, 2024
1 parent a4fc8c1 commit eedf6d0
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
99 changes: 99 additions & 0 deletions .github/workflows/release/cliff.toml
Original file line number Diff line number Diff line change
@@ -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 = """\
<!-- TODO: Update milestone link, review commits. -->
{% 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 = "<!-- 0 -->Features" },
{ message = "^fix", group = "<!-- 1 -->Bug Fixes" },
{ message = "^perf", group = "<!-- 2 -->Performance" },
{ message = "^doc", group = "<!-- 3 -->Documentation" },
{ message = "^build", group = "<!-- 4 -->Build System" },
{ message = "^ci", group = "<!-- 5 -->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"

0 comments on commit eedf6d0

Please sign in to comment.