From 4109308641b0aecc05b357295d849cfdc02f5157 Mon Sep 17 00:00:00 2001 From: DerTiedemann Date: Tue, 5 Nov 2024 09:18:06 +0100 Subject: [PATCH] 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](https://github.com/bakdata/streams-bootstrap/pull/214) * [Gradle Release Plugin] - pre tag commit: '2.23.0'. by @bakdata-bot **Full Changelog**: https://github.com/bakdata/streams-bootstrap/compare/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](https://github.com/bakdata/streams-bootstrap/pull/214) **Full Changelog**: https://github.com/bakdata/streams-bootstrap/compare/2.22.1...2.23.0
For more config options have a look at the docs, this thing is pretty powerful. Let me know what you think. --- .github/workflows/bump-version-release.yaml | 8 +- .github/workflows/java-gradle-release.yaml | 2 +- actions/changelog-generate/action.yaml | 153 +++++------------- .../changelog-generate/changelog-config.json | 8 - actions/changelog-generate/default-cliff.toml | 62 +++++++ actions/java-gradle-release/action.yaml | 11 +- docs/actions/changelog-generate/README.md | 23 ++- 7 files changed, 117 insertions(+), 150 deletions(-) delete mode 100644 actions/changelog-generate/changelog-config.json create mode 100644 actions/changelog-generate/default-cliff.toml diff --git a/.github/workflows/bump-version-release.yaml b/.github/workflows/bump-version-release.yaml index a891d118e..28992e0f8 100644 --- a/.github/workflows/bump-version-release.yaml +++ b/.github/workflows/bump-version-release.yaml @@ -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/commit-and-push@v1.6.0 diff --git a/.github/workflows/java-gradle-release.yaml b/.github/workflows/java-gradle-release.yaml index 29354d691..dd3de4e2b 100644 --- a/.github/workflows/java-gradle-release.yaml +++ b/.github/workflows/java-gradle-release.yaml @@ -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 }} diff --git a/actions/changelog-generate/action.yaml b/actions/changelog-generate/action.yaml index 9074bf48f..6cef6ae4b 100644 --- a/actions/changelog-generate/action.yaml +++ b/actions/changelog-generate/action.yaml @@ -5,7 +5,7 @@ inputs: github-token: description: "The GitHub token for committing the changes." required: true - new-tag: + tag: description: Version after bump required: true # optional inputs @@ -13,130 +13,51 @@ inputs: 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/checkout@1.46.4 + 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<> $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<> $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 diff --git a/actions/changelog-generate/changelog-config.json b/actions/changelog-generate/changelog-config.json deleted file mode 100644 index ee7958d45..000000000 --- a/actions/changelog-generate/changelog-config.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "categories": [{ "title": "### Merged pull requests:" }], - "ignore_labels": ["ignore"], - "sort": { "order": "ASC", "on_property": "mergedAt" }, - "template": "# [#{{TO_TAG}}](https://github.com/#{{OWNER}}/#{{REPO}}/releases/tag/#{{TO_TAG}}) - Release Date: #{{TO_TAG_DATE}}\n\n#{{CHANGELOG}}", - "pr_template": "- #{{TITLE}} [##{{NUMBER}}](#{{URL}}) ([@#{{AUTHOR}}](https://github.com/#{{AUTHOR}}))\n", - "empty_template": "- no changes!" -} diff --git a/actions/changelog-generate/default-cliff.toml b/actions/changelog-generate/default-cliff.toml new file mode 100644 index 000000000..8e87df0ae --- /dev/null +++ b/actions/changelog-generate/default-cliff.toml @@ -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 = """ + +""" +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" diff --git a/actions/java-gradle-release/action.yaml b/actions/java-gradle-release/action.yaml index 83debc419..d86ee1c82 100644 --- a/actions/java-gradle-release/action.yaml +++ b/actions/java-gradle-release/action.yaml @@ -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/changelog-generate@1.48.0 + 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: | diff --git a/docs/actions/changelog-generate/README.md b/docs/actions/changelog-generate/README.md index f9123570a..5fcc20897 100644 --- a/docs/actions/changelog-generate/README.md +++ b/docs/actions/changelog-generate/README.md @@ -86,16 +86,11 @@ steps: -| 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 | @@ -103,10 +98,10 @@ steps: -| 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. |