tomasbjerre/git-changelog-gradle-plugin

Trouble setting the project version

sschuberth opened this issue · 8 comments

I'd like to use this plugin to determine the current version of my Gradle project (which uses Conventional Commits) by setting project.version. In Kotlin DSL, usually

project.version = se.bjurr.gitchangelog.api.GitChangelogApi.gitChangelogApiBuilder()
    .withFromRepo(rootDir)
    .nextSemanticVersion

works fine, except for the case when the current commit is tagged with a SemVer. nextSemanticVersion would then bump the patch level version and return a different version than tagged. The pragmatic solution is to use highestSemanticVersion instead in this case, but it's inconvenient to choose between nextSemanticVersion and highestSemanticVersion depending on whether the current commit is tagged or not.

So I'm wondering whether there's some logic / helper method that I'm missing, or what's generally the best approach to achieve what I want with your plugin. Thanks!

Perhaps if you set:
patchVersionPattern = "[Ff]ix"
So that patch version only bumps on fixes?

So that patch version only bumps on fixes?

That would not generally work as I do want non-breaking and non-feature commits to bump the patch level.

How do you think about introducing a currentSemanticVersion that mostly behaves like nextSemanticVersion, but simply uses a SemVer tag if the current commit has one? Additionally, that function could append a suffix to the version if it's unreleased (read: not tagged yet), so fix commits following a 1.0.1 tag would result in a "1.0.2-SNAPSHOT" version until "1.0.2" is tagged.

So you have a commit that is tagged right? Is that a commit created by some release script?

You could invent something that does not bump the version, lik "ci":

"ci: this is a commit from ci"

And have a negative look ahead regexp that matches everything except "ci:". (?!ci:)

I think I like your idea with currentSemanticVersion!

I think I like your idea with currentSemanticVersion!

Actually, I believe that's then also the logic that should be used by the gitChangelogSemanticVersion task. Because currently, that task writes "1.0.3-SNAPSHOT" to gradle.properties is the current commit is tagged with "1.0.2".

Looks good, thanks! I haven't tested it yet, but let me close this and reopen eventually if I encounter an issue.

Releasing it in this plugin in 1.81.3.