jmongard / Git.SemVersioning.Gradle

Gradle plugin for automatically versioning a project using semantic versioning and conventional commits with change log support based on git commit messages.
https://plugins.gradle.org/plugin/com.github.jmongard.git-semver-plugin
Apache License 2.0
38 stars 4 forks source link

Issue in pattern matching #10

Closed Jessewb786 closed 2 years ago

Jessewb786 commented 2 years ago

I'm currently trying to get the following template to work to update the minor version

The configuration for semver is:

semver {
    defaultPreRelease = "snapshot"
    minorPattern = "^(\\s?)feat(?:\\(\\w+\\))?:"
    patchPattern = "^(\\s?)fix(?:\\(\\w+\\))?:"
}

The commit template I'm trying to match looks like:

TTLFLCT-1

feat: added git-semver-plugin for automatic semantic versioning

The testing:

When I pull your code and try this in the testCommits test in GitProviderTest, then the minor version updates correctly. So it passes the unit test.

 val gitProvider = GitProvider(SemverSettings().apply {
         groupVersionIncrements = true
         minorPattern = "^(\\s?)feat(?:\\(\\w+\\))?:"
 })
 ...
 commit(it, "TTLFLCT-1\n\nfeat: a feature", gitProvider)
Screen Shot 2021-11-10 at 18 31 07

If I try this in my actual project, then the minor version does not update.

Screen Shot 2021-11-10 at 18 32 53 Screen Shot 2021-11-10 at 18 32 03

This was tested on Mac OS.

jmongard commented 2 years ago

Hi,

Your pattern works for me when I'm trying:

Git.SemVersioning.Gradle.Actions-Example (master)                     
$ ./gradlew print                                                                                                

> Task :printVersion                                                                                             
--------------------                                                                                             
Version: 0.0.6-snapshot+002.sha.11d4ef0                                                                          

BUILD SUCCESSFUL in 1s                                                                                           
1 actionable task: 1 executed                                                                                    

Git.SemVersioning.Gradle.Actions-Example (master)                     
$ git commit -m $'TTLFLCT-1\n\nfeat: added git-semver-plugin for automatic semantic versioning' --allow-empty    
[master 3647356] TTLFLCT-1                                                                                       

Git.SemVersioning.Gradle.Actions-Example (master)                     
$ ./gradlew print                                                                                                

> Task :printVersion                                                                                             
--------------------                                                                                             
Version: 0.1.0-snapshot+003.sha.3647356                                                                          

BUILD SUCCESSFUL in 1s                                                                                           
1 actionable task: 1 executed                                                                                    

Can you make sure you configured the plugin before extracting the version number like this?

plugins {
    id 'com.github.jmongard.git-semver-plugin' version '0.4.2'
}

semver {
    defaultPreRelease = "snapshot"
    minorPattern = "^(\\s?)feat(?:\\(\\w+\\))?:"
    patchPattern = "^(\\s?)fix(?:\\(\\w+\\))?:"
}

version = semver.version
jmongard commented 2 years ago

Example repository: https://github.com/jmongard/Git.SemVersioning.Gradle.Actions-Example/tree/custom-pattern

Jessewb786 commented 2 years ago

@jmongard Sorry, you're absolutely right.

I had the configuration after the version assignment. It now seems to work as intended.