diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3bfe64c8..c8f29cb1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -107,20 +107,14 @@ jobs: - name: "create working branch for previous major release (${{ env.LATEST_VERSION }})" if: ( env.RELEASE_KIND == 'major' ) run: | - # save a branch so that we can easily create PR for that version when we want to fix something git checkout "v${{ env.LATEST_VERSION }}" export BRANCH_NAME=$(echo "${{ env.LATEST_VERSION }}" | sed 's/^\([0-9]*\).*/v\1/') git checkout -b "$BRANCH_NAME" git push origin "$BRANCH_NAME" - # create branch of version - name: prepare project version ${{ env.RELEASE_REF }} ${{ env.LATEST_VERSION }} -> ${{ env.NEW_VERSION }} run: | - # jump back for the case that we switched to a tag git checkout "${{ env.RELEASE_REF }}" - # install pontos python3 -m pip install pontos - #poetry install - #poetry shell pontos-version update ${{ env.NEW_VERSION }} if git diff --exit-code --quiet; then echo "There are no modified files, skipping." @@ -131,32 +125,35 @@ jobs: git push origin ${{ env.RELEASE_REF }} fi - - run: mkdir assets/ + - run: mkdir -p assets/ + + # Install git-cliff using Greenbone's UV action + - name: Install git-cliff + uses: greenbone/actions/uv@v3 + with: + install: git-cliff + + # Generate changelog with git-cliff and cliff.toml configuration + - name: Generate changelog with git-cliff + run: | + # Generate changelog from previous version to HEAD + git-cliff -v --strip header -o /tmp/changelog.md --config cliff.toml --tag "${{ env.NEW_VERSION }}" "v${{ env.LATEST_VERSION }}..HEAD" + # Fallback if changelog is empty + if [ ! -s "/tmp/changelog.md" ]; then + echo "No release notes. See commit history for details." > /tmp/changelog.md + fi + - name: release ${{ env.LATEST_VERSION }} -> ${{ env.NEW_VERSION }} run: | export PROJECT=$(echo "${{ github.repository }}" | sed 's/.*\///' ) - pontos-changelog \ - --current-version ${{ env.LATEST_VERSION }} \ - --next-version ${{ env.NEW_VERSION }} \ - --config changelog.toml \ - --repository ${{ github.repository }} \ - --versioning-scheme semver \ - -o /tmp/changelog.md || true - # we would rather have empty release notes than no release - if [ ! -f "/tmp/changelog.md" ]; then - touch /tmp/changelog.md - fi - echo "${{ secrets.GREENBONE_BOT_TOKEN }}" | gh auth login --with-token - # lets see how smart it is export nrn="v${{ env.NEW_VERSION }}" export filename="$PROJECT-$nrn" + echo "${{ secrets.GREENBONE_BOT_TOKEN }}" | gh auth login --with-token gh release create "$nrn" -F /tmp/changelog.md - mkdir -p assets - ls -las assets/ curl -Lo assets/$filename.zip https://github.com/${{ github.repository }}/archive/refs/tags/$nrn.zip curl -Lo assets/$filename.tar.gz https://github.com/${{ github.repository }}/archive/refs/tags/$nrn.tar.gz echo -e "${{ secrets.GPG_KEY }}" > private.pgp echo ${{ secrets.GPG_PASSPHRASE }} | bash .github/sign-assets.sh private.pgp rm assets/$filename.zip rm assets/$filename.tar.gz - gh release upload $nrn assets/* + gh release upload $nrn assets/* \ No newline at end of file diff --git a/changelog.toml b/changelog.toml deleted file mode 100644 index 9858b824..00000000 --- a/changelog.toml +++ /dev/null @@ -1,8 +0,0 @@ -commit_types = [ - { message = "^add", group = "Added"}, - { message = "^remove", group = "Removed"}, - { message = "^change", group = "Changed"}, - { message = "^fix", group = "Bug Fixes"}, -] - -changelog_dir = "changelog" diff --git a/cliff.toml b/cliff.toml new file mode 100644 index 00000000..70ba54eb --- /dev/null +++ b/cliff.toml @@ -0,0 +1,87 @@ +[changelog] +# template for the changelog header +header = """ +# Changelog\n +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\n +""" +# template for the changelog body +# https://keats.github.io/tera/docs/#introduction +body = """ +{%- macro remote_url() -%} + https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }} +{%- endmacro -%} + +{% if version -%} + ## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }} +{% else -%} + ## [Unreleased] +{% endif -%} + +{% for group, commits in commits | group_by(attribute="group") %} + ### {{ group | upper_first }} + {% for commit in commits %} + - {{ commit.message | split(pat="\n") | first | upper_first | trim }}\ + {% if commit.remote.username %} by [@{{ commit.remote.username }}](https://github.com/{{ commit.remote.username }}){%- endif -%} + {% if commit.remote.pr_number %} in \ + [#{{ commit.remote.pr_number }}]({{ self::remote_url() }}/pull/{{ commit.remote.pr_number }}) \ + {% elif commit.id %} in \ + [{{ commit.id | truncate(length=7, end="") }}]({{ self::remote_url() }}/commit/{{ commit.id }})\ + {%- endif -%} + {% endfor %} +{% endfor -%} +""" +# template for the changelog footer +footer = """ +{%- macro remote_url() -%} + https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }} +{%- endmacro -%} + +{% for release in releases %} + {% if release.version -%} + {% if release.previous.version -%} + [{{ release.version | trim_start_matches(pat="v") }}]: \ + {{ self::remote_url() }}/compare/{{ release.previous.version }}..{{ release.version }} + {% endif -%} + {% else -%} + [unreleased]: {{ self::remote_url() }}/compare/{{ release.previous.version }}..HEAD + {% endif -%} +{%- endfor -%} +""" +# remove the leading and trailing whitespace from the templates +trim = true + +[git] +# parse the commits based on https://www.conventionalcommits.org +conventional_commits = true +# filter out the commits that are not following the conventional commits format +filter_unconventional = false +# 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 = "^[a|A]dd", group = ":sparkles: Added" }, + { message = "^[c|C]hange", group = ":construction_worker: Changed" }, + { message = "^[f|F]ix", group = ":bug: Bug Fixes" }, + { message = "^[r|R]emove", group = ":fire: Removed" }, + { message = "^[d|D]rop", group = ":fire: Removed" }, + { message = "^[d|D]oc", group = ":books: Documentation" }, + { message = "^[t|T]est", group = ":white_check_mark: Testing" }, + { message = "^[c|C]hore", group = ":wrench: Miscellaneous" }, + { message = "^[c|C]i", group = "️:wrench: Miscellaneous" }, + { message = "^[m|M]isc", group = ":wrench: Miscellaneous" }, + { message = "^[d|D]eps", group = ":ship: Dependencies" }, +] +# filter out the commits that are not matched by commit parsers +filter_commits = true +# sort the tags topologically +topo_order = false +# sort the commits inside sections by oldest/newest order +sort_commits = "oldest" \ No newline at end of file