-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: New changelog generator (#205)
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
1 parent
2a589a8
commit 4109308
Showing
7 changed files
with
117 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: | | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters