Skip to content

Commit

Permalink
Feat: New changelog generator (#205)
Browse files Browse the repository at this point in the history
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:
```toml
# 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](https://github.com/bakdata/streams-bootstrap/tree/2.23.0) -
2024-06-12
### What's changed

* [Gradle Release Plugin] - new version commit: '2.22.2-SNAPSHOT'. by
@bakdata-bot

* Changelog for version 2.22.1 by @bakdata-bot

* Add dynamic application.server config to streams app chart by
@philipp94831 in
[#214](bakdata/streams-bootstrap#214)

* [Gradle Release Plugin] - pre tag commit:  '2.23.0'. by @bakdata-bot


**Full Changelog**:
bakdata/streams-bootstrap@2.22.1...2.23.0

into this:
## [2.23.0](https://github.com/bakdata/streams-bootstrap/tree/2.23.0) -
2024-06-12
### What's changed

* Add dynamic application.server config to streams app chart by
@philipp94831 in
[#214](bakdata/streams-bootstrap#214)


**Full Changelog**:
bakdata/streams-bootstrap@2.22.1...2.23.0


<hr>

For more config options have a look at the docs, this thing is pretty
powerful. Let me know what you think.
  • Loading branch information
DerTiedemann authored Nov 5, 2024
1 parent 2a589a8 commit 4109308
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 150 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/bump-version-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,12 @@ jobs:

- name: Create changelog
id: build-changelog
uses: bakdata/ci-templates/actions/changelog-generate@1.35.0
uses: bakdata/ci-templates/actions/changelog-generate@1.48.0
if: ${{ inputs.changelog }}
with:
github-token: ${{ secrets.github-token }}
config: ${{ inputs.changelog-config }}
new-tag: ${{ steps.bump-version.outputs.release-version }}
fetch-reviewers: "true"
fetch-release-information: "true"
tag: ${{ steps.bump-version.outputs.release-version }}
changelog-file: CHANGELOG.md

- name: Commit and push changes including .bumpversion.cfg file
uses: bakdata/ci-templates/actions/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/java-gradle-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
steps:
- name: Release on Github
id: release
uses: bakdata/ci-templates/actions/java-gradle-release@1.43.0
uses: bakdata/ci-templates/actions/java-gradle-release@1.48.0
with:
release-type: ${{ inputs.release-type }}
github-email: ${{ secrets.github-email }}
Expand Down
153 changes: 37 additions & 116 deletions actions/changelog-generate/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,138 +5,59 @@ inputs:
github-token:
description: "The GitHub token for committing the changes."
required: true
new-tag:
tag:
description: Version after bump
required: true
# optional inputs
changelog-file:
description: Path to the changelog file in the GitHub repository
required: false
default: "CHANGELOG.md"
commit-mode:
description: "Special configuration for projects which work without PRs."
required: false
default: "false"
config:
description: Path to the changelog config JSON file
required: false
default: ""
fetch-release-information:
description: "Will enable fetching additional release information from tags."
required: false
default: "false"
fetch-reviewers:
description: "Will enable fetching the users/reviewers who approved the PR"
required: false
default: "false"
old-tag:
description: Previous version. Let empty for releases
required: false
default: ""

outputs:
merged-changelog:
description: "Changelog containing listing of all single changelogs"
value: ${{ steps.output-generator.outputs.merged-changelog }}
description: "All changelogs combinded."
value: ${{ steps.git-cliff.outputs.content }}
single-changelog:
description: "Changelog containing changes of the latest tag"
value: ${{ steps.output-generator.outputs.single-changelog }}
description: "Only the latest changelog."
value: ${{ steps.git-cliff-latest.outputs.content }}

runs:
using: "composite"

steps:
- name: "Set tags"
id: set-tags
- name: Check out repository
uses: bakdata/ci-templates/actions/[email protected]
with:
fetch-depth: 0
- name: Get config path
id: get-config-path
run: |
tag_list=$(git tag) || tag_list=""
# to-tag
if [[ "$tag_list" == *"${{ inputs.new-tag }}"* ]]; then
echo "totag=${{ inputs.new-tag }}">> $GITHUB_OUTPUT
else
echo "totag=$(git rev-parse HEAD)">> $GITHUB_OUTPUT
fi
#from-tag
setfrom=""
if [[ -n "${{ inputs.old-tag }}" ]] && [[ "$tag_list" == *"${{ inputs.old-tag }}"* ]]; then
# tag provided & provided tag exists
setfrom=${{ inputs.old-tag }}
DEFAULT_PATH=$GITHUB_ACTION_PATH/default-cliff.toml
if [-f cliff.toml ]; then
cp cliff.toml tmp_cliff.toml
else
# no tag provided or a non-existing tag was provided
if [ -n "$tag_list" ]; then
# if any tag exists then set from-tag to the latest tag
setfrom=$(git describe --tags `git rev-list --tags --max-count=1`)
else
# if no tag exists then use the frist commit as fromtag
setfrom=$(git rev-list --max-parents=0 HEAD)
fi
cp $DEFAULT_PATH tmp_cliff.toml
fi
echo "fromtag=$setfrom">> $GITHUB_OUTPUT
if [[ -z "${{ inputs.config }}" ]]; then
path="$GITHUB_ACTION_PATH/changelog-config.json"
else
path=${{ inputs.config }}
fi
if [ ! -f "$path" ]; then
echo "changelog config file $path doesn't exist"
exit 1
fi
echo "path=$path" >> "$GITHUB_OUTPUT"
shell: bash

- name: "Create changelog"
id: build_changelog
uses: mikepenz/release-changelog-builder-action@v4
- name: Generate latest only changelog
uses: orhun/git-cliff-action@v3
id: git-cliff-latest
with:
token: "${{ inputs.github-token }}"
configuration: "${{ steps.set-tags.outputs.path }}"
fromTag: "${{ steps.set-tags.outputs.fromtag }}"
toTag: "${{ steps.set-tags.outputs.totag }}"
outputFile: ${{ runner.temp }}/changes.md
fetchReviewers: "${{ inputs.fetch-reviewers }}"
fetchReleaseInformation: "${{ inputs.fetch-release-information }}"
commitMode: "${{ inputs.commit-mode }}"

- name: Replace default branch with new Tag
if: ${{ steps.set-tags.outputs.totag != inputs.new-tag }}
run: |
# Replace default branch with new tag
sed -i 's/\[${{ steps.set-tags.outputs.totag }}\]/\[${{ inputs.new-tag }}\]/g' ${{ runner.temp }}/changes.md
sed -i 's|releases/tag/${{ steps.set-tags.outputs.totag }}|releases/tag/${{ inputs.new-tag }}|g' ${{ runner.temp }}/changes.md
# Set Release date
tag_date=$(date '+%Y-%m-%d')
sed -i "s/Release Date: /Release Date: \[${tag_date}\]/g" ${{ runner.temp }}/changes.md
shell: bash

- name: Update GitHub Changelog
id: output-generator
run: |
# Reformat ${{ runner.temp }}/changes.md and add it to the existing changelog
{
echo 'single-changelog<<EOF'
cat ${{ runner.temp }}/changes.md
echo EOF
} >> $GITHUB_OUTPUT
# Create changelog.md in case of a first Release
if [ -n "${{ inputs.changelog-file }}" ]; then
sed -i 's/# /## /g' ${{ runner.temp }}/changes.md
echo -e "\n" >> ${{ runner.temp }}/changes.md
if [ ! -f "${{ inputs.changelog-file }}" ]; then
echo $'# Changelog\n' >> ${{ inputs.changelog-file }}
fi
# Update global changelog and pass it to the ouput
sed -i "2i $(sed ':a;N;$!ba;s/\n/\\n/g' ${{ runner.temp }}/changes.md)" ${{ inputs.changelog-file }}
{
echo 'merged-changelog<<EOF'
cat ${{ inputs.changelog-file }}
echo EOF
} >> $GITHUB_OUTPUT
fi
config: tmp_cliff.toml
args: "--unreleased --tag ${{ inputs.tag }} --verbose"
env:
GITHUB_REPO: ${{ github.repository }}
GITHUB_TOKEN: ${{ inputs.github-token }}
- name: Generate a changelog
uses: orhun/git-cliff-action@v3
id: git-cliff
with:
config: tmp_cliff.toml
args: "--tag ${{ inputs.tag }} --verbose"
env:
OUTPUT: ${{ inputs.changelog-file }}
GITHUB_REPO: ${{ github.repository }}
GITHUB_TOKEN: ${{ inputs.github-token }}
- name: remove tmp config file
run: rm tmp_cliff.toml && rm -rf git-cliff/
shell: bash
8 changes: 0 additions & 8 deletions actions/changelog-generate/changelog-config.json

This file was deleted.

62 changes: 62 additions & 0 deletions actions/changelog-generate/default-cliff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
[changelog]
header = """
# Changelog\n
All notable changes to this project will be documented in this file.\n
"""
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 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 %}\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 %}
"""
footer = """
<!-- generated by git-cliff -->
"""
trim = true
postprocessors = []

[git]
conventional_commits = true
filter_unconventional = false
split_commits = false
commit_preprocessors = []
commit_parsers = []
protect_breaking_commits = false
filter_commits = false
topo_order = false
sort_commits = "oldest"
11 changes: 5 additions & 6 deletions actions/java-gradle-release/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,11 @@ runs:
shell: bash

- name: Create changelog
run: ./gradlew -Pchangelog.githubRepository=${{ github.event.repository.name }} -Pchangelog.futureVersionTag=${{ steps.evaluate-version.outputs.release-version }} --stacktrace --info generateChangelog ${{ inputs.gradle-refresh-dependencies == 'true' && '--refresh-dependencies' || '' }}
shell: bash
working-directory: ${{ inputs.working-directory }}
env:
GITHUB_USER: ${{ github.repository_owner }}
GITHUB_TOKEN: ${{ inputs.github-token }}
uses: bakdata/ci-templates/actions/[email protected]
with:
github-token: ${{ inputs.github-token }}
tag: ${{ steps.evaluate-version.outputs.release-version }}
changelog-file: CHANGELOG.md

- name: Commit and push changes including the bump config file
run: |
Expand Down
23 changes: 9 additions & 14 deletions docs/actions/changelog-generate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,27 +86,22 @@ steps:
<!-- AUTO-DOC-INPUT:START - Do not remove or modify this section -->
| INPUT | TYPE | REQUIRED | DEFAULT | DESCRIPTION |
| ------------------------- | ------ | -------- | ---------------- | -------------------------------------------------------------- |
| changelog-file | string | false | `"CHANGELOG.md"` | Path to the changelog file in the GitHub repository |
| commit-mode | string | false | `"false"` | Special configuration for projects which work without PRs. |
| config | string | false | | Path to the changelog config JSON file |
| fetch-release-information | string | false | `"false"` | Will enable fetching additional release information from tags. |
| fetch-reviewers | string | false | `"false"` | Will enable fetching the users/reviewers who approved the PR |
| github-token | string | true | | The GitHub token for committing the changes. |
| new-tag | string | true | | Version after bump |
| old-tag | string | false | | Previous version. Let empty for releases |
| INPUT | TYPE | REQUIRED | DEFAULT | DESCRIPTION |
| -------------- | ------ | -------- | ---------------- | --------------------------------------------------- |
| changelog-file | string | false | `"CHANGELOG.md"` | Path to the changelog file in the GitHub repository |
| github-token | string | true | | The GitHub token for committing the changes. |
| tag | string | true | | Version after bump |
<!-- AUTO-DOC-INPUT:END -->
### Outputs
<!-- AUTO-DOC-OUTPUT:START - Do not remove or modify this section -->
| OUTPUT | TYPE | DESCRIPTION |
| ---------------- | ------ | ----------------------------------------------------- |
| merged-changelog | string | Changelog containing listing of all single changelogs |
| single-changelog | string | Changelog containing changes of the latest tag |
| OUTPUT | TYPE | DESCRIPTION |
| ---------------- | ------ | -------------------------- |
| merged-changelog | string | All changelogs combinded. |
| single-changelog | string | Only the latest changelog. |
<!-- AUTO-DOC-OUTPUT:END -->
Expand Down

0 comments on commit 4109308

Please sign in to comment.