From d580156fa2cfc1b16d5b512a8a4d0d319529c09f Mon Sep 17 00:00:00 2001 From: Stefan Hausotte Date: Thu, 4 Jun 2026 15:03:22 +0200 Subject: [PATCH] ci: add automatic changelog creation --- CHANGELOG.md | 5 ----- cliff.toml | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 1 + justfile | 48 +++++++++++++++++++++++++++++++++++++++++----- 4 files changed, 98 insertions(+), 10 deletions(-) create mode 100644 cliff.toml diff --git a/CHANGELOG.md b/CHANGELOG.md index 5964aa7..88b62c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,8 +5,6 @@ All notable changes to Forji will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased] - ## [1.5] - 2026-06-04 ### Added @@ -41,6 +39,3 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - No longer opens a duplicate PR when the reviewer request fails (#53). - Background notification poll no longer crashes on an invalid instance URL (#54). - Messages that were not marked as read are now handled correctly. - -[Unreleased]: https://codeberg.org/secana/Forji/compare/v1.5...HEAD -[1.5]: https://codeberg.org/secana/Forji/releases/tag/v1.5 diff --git a/cliff.toml b/cliff.toml new file mode 100644 index 0000000..7128774 --- /dev/null +++ b/cliff.toml @@ -0,0 +1,54 @@ +# git-cliff configuration — generates CHANGELOG.md from conventional commits. +# Output follows the Keep a Changelog format (https://keepachangelog.com/en/1.1.0/). +# See https://git-cliff.org/docs/configuration + +[changelog] +header = """ +# Changelog + +All notable changes to Forji will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\n +""" +body = """ +{% 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 }}\ + {% endfor %} +{% endfor %}\n +""" +footer = "" +# Remove leading and trailing whitespaces from the changelog's body. +trim = true + +[git] +# Parse commits according to the conventional commits specification. +conventional_commits = true +# Drop commits that are not conventional (e.g. merge commits). +filter_unconventional = true +# Drop commits that no parser assigns to a group. +filter_commits = true +# Only consider tags that look like releases (v1.5, v1.6, ...). +tag_pattern = "v[0-9]*" +sort_commits = "oldest" +# Groups render alphabetically; "Added" < "Changed" < "Fixed" already matches +# the Keep a Changelog ordering for the types we emit. +commit_parsers = [ + { message = "^feat", group = "Added" }, + { message = "^fix", group = "Fixed" }, + { message = "^refactor", group = "Changed" }, + { message = "^perf", group = "Changed" }, + { message = "^docs", group = "Changed" }, + { message = "^chore", skip = true }, + { message = "^test", skip = true }, + { message = "^style", skip = true }, + { message = "^ci", skip = true }, + { message = "^build", skip = true }, +] diff --git a/flake.nix b/flake.nix index 20edbe7..a97824c 100644 --- a/flake.nix +++ b/flake.nix @@ -18,6 +18,7 @@ pkgs.xcbeautify pkgs.swiftlint pkgs.swiftformat + pkgs.git-cliff ]; }; }); diff --git a/justfile b/justfile index c3de0f5..b45d23c 100644 --- a/justfile +++ b/justfile @@ -37,11 +37,49 @@ pbxproj := "Forji/Forji.xcodeproj/project.pbxproj" version: @grep -m1 'MARKETING_VERSION' {{pbxproj}} | sed 's/.*= *//;s/;.*//' -# Set app version (updates both MARKETING_VERSION and CURRENT_PROJECT_VERSION) -set-version new_version: - sed -i '' 's/MARKETING_VERSION = [^;]*/MARKETING_VERSION = {{new_version}}/' {{pbxproj}} - sed -i '' 's/CURRENT_PROJECT_VERSION = [^;]*/CURRENT_PROJECT_VERSION = {{new_version}}/' {{pbxproj}} - @echo "Version set to {{new_version}}" +changelog := "CHANGELOG.md" + +# Preview the changelog entries for unreleased commits (since the latest tag) +changelog: + @git cliff --config cliff.toml --unreleased --strip header + +# Release a new version: bump version, generate the changelog, tag, commit, and push +release new_version: + #!/usr/bin/env bash + set -eo pipefail + NEW="{{new_version}}" + TAG="v$NEW" + + # Refuse to release from a dirty tree so the release commit stays clean. + if [ -n "$(git status --porcelain)" ]; then + echo "Working tree is not clean. Commit or stash your changes before releasing." + exit 1 + fi + + # Refuse to clobber an existing tag. + if git rev-parse "$TAG" >/dev/null 2>&1; then + echo "Tag $TAG already exists." + exit 1 + fi + + PREV=$(grep -m1 'MARKETING_VERSION' {{pbxproj}} | sed 's/.*= *//;s/;.*//') + echo "Releasing $PREV -> $NEW" + + # 1. Bump the version in the Xcode project. + sed -i '' "s/MARKETING_VERSION = [^;]*/MARKETING_VERSION = $NEW/" {{pbxproj}} + sed -i '' "s/CURRENT_PROJECT_VERSION = [^;]*/CURRENT_PROJECT_VERSION = $NEW/" {{pbxproj}} + + # 2. Generate the changelog section for the new version from the conventional + # commits since the last tag, prepending it under the header. + git cliff --config cliff.toml --unreleased --tag "$TAG" --prepend {{changelog}} + + # 3. Commit, tag, and push. + git add {{pbxproj}} {{changelog}} + git commit -m "chore: release $NEW" + git tag -a "$TAG" -m "Release $NEW" + git push origin HEAD + git push origin "$TAG" + echo "Released $NEW and pushed $TAG." # Clean build artifacts clean: