@@ -7,8 +7,10 @@ import org.gradle.api.tasks.testing.logging.TestLogEvent.PASSED
77import org.gradle.api.tasks.testing.logging.TestLogEvent.SKIPPED
88import org.gradle.api.tasks.testing.logging.TestLogging
99import org.gradle.api.tasks.testing.logging.TestStackTraceFilter
10+ import org.gradle.internal.impldep.org.joda.time.Instant
1011import pl.allegro.tech.build.axion.release.domain.VersionConfig
1112import ru.vyarus.gradle.plugin.python.PythonExtension
13+ import java.time.Instant.*
1214
1315plugins {
1416 base
@@ -50,30 +52,65 @@ scmVersion {
5052 null
5153 }
5254 val lastTagName = lastTagDesc?.substringBefore(" -" )
55+ logger.info(" Git describe result: $lastTagDesc " )
56+ logger.info(" Last tag name: $lastTagName " )
57+
58+ // Check if we have any tags at all
59+ val allTags = git.tagList().call()
60+ logger.info(" Total tags in repository: ${allTags.size} " )
61+ if (allTags.isNotEmpty()) {
62+ logger.info(" Available tags: ${allTags.map { it.name.substringAfterLast(" /" ) }} " )
63+ }
5364 val repo = git.repository
5465 val head = repo.resolve(" HEAD" )
5566 val lastTagCommit = lastTagName?.let { repo.resolve(" refs/tags/$it ^{commit}" ) }
5667
68+ logger.info(" HEAD commit: $head " )
69+ logger.info(" Last tag commit: $lastTagCommit " )
70+
5771 val commits =
5872 if (lastTagCommit != null && head != null ) {
73+ logger.info(" Getting commits between tag $lastTagName and HEAD" )
5974 git
6075 .log()
6176 .addRange(lastTagCommit, head)
6277 .call()
6378 .toList()
79+ } else if (allTags.isEmpty()) {
80+ // If no tags exist at all, this is likely the first release
81+ // Only look at commits since project started being versioned conventionally
82+ logger.info(" No tags found - treating as first release, analyzing recent commits only" )
83+ if (head != null ) {
84+ git
85+ .log()
86+ .add(head)
87+ .setMaxCount(10 ) // Only look at last 10 commits for first release
88+ .call()
89+ .toList()
90+ } else {
91+ logger.info(" No HEAD found, repository appears empty" )
92+ emptyList()
93+ }
6494 } else {
65- // If no tag exists yet, use all commits but guard against empty repo
95+ // Tags exist but we couldn't resolve the last one
96+ logger.info(" Tags exist but couldn't resolve last tag, getting all commits from HEAD" )
6697 if (head != null ) {
6798 git
6899 .log()
69100 .add(head)
70101 .call()
71102 .toList()
72103 } else {
104+ logger.info(" No HEAD found, repository appears empty" )
73105 emptyList()
74106 }
75107 }
76108
109+ logger.info(" Found ${commits.size} commits since last tag" )
110+ if (commits.isNotEmpty()) {
111+ logger.info(" Commit range: ${commits.last().name.substring(0 , 7 )} ..${commits.first().name.substring(0 , 7 )} " )
112+ }
113+
77114 var hasMajor = false
78115 var hasMinor = false
79116 var hasPatch = false
@@ -94,9 +131,18 @@ scmVersion {
94131 val bang = m?.groups?.get(" bang" ) != null
95132 val breaking = bang || breakingFooter.containsMatchIn(full)
96133
134+ logger.info(" Analyzing commit: [${ofEpochSecond(commit.commitTime.toLong())} ] $subject " )
135+ logger.info(" Type: $type , Breaking: $breaking " )
136+
97137 when {
98- breaking -> hasMajor = true
99- type == " feat" -> hasMinor = true
138+ breaking -> {
139+ hasMajor = true
140+ logger.info(" → Triggers MAJOR version bump (breaking change)" )
141+ }
142+ type == " feat" -> {
143+ hasMinor = true
144+ logger.info(" → Triggers MINOR version bump (new feature)" )
145+ }
100146 type in
101147 setOf (
102148 " fix" ,
@@ -111,22 +157,49 @@ scmVersion {
111157 " ci" ,
112158 " task" ,
113159 )
114- -> hasPatch = true
160+ -> {
161+ hasPatch = true
162+ logger.info(" → Triggers PATCH version bump ($type )" )
163+ }
164+ else -> {
165+ logger.info(" → No version impact" )
166+ }
115167 }
116168 }
117169
118170 val v = context.currentVersion
119171 if (commits.isEmpty()) {
120- // No commits since last tag → no bump (leave as-is )
172+ logger.info( " No commits since last tag → keeping version $v " )
121173 return @versionIncrementer v
122174 }
123175
124- when {
125- hasMajor -> if (v.majorVersion() == 0L ) v.nextMinorVersion() else v.nextMajorVersion()
126- hasMinor -> v.nextMinorVersion()
127- hasPatch -> v.nextPatchVersion()
128- else -> v.nextPatchVersion() // commits present, but no signal → patch
129- }
176+ logger.info(" Version bump analysis: major=$hasMajor , minor=$hasMinor , patch=$hasPatch " )
177+
178+ val newVersion =
179+ when {
180+ hasMajor -> {
181+ val next = if (v.majorVersion() == 0L ) v.nextMinorVersion() else v.nextMajorVersion()
182+ logger.info(" MAJOR version bump: $v → $next (0.x special handling: ${v.majorVersion() == 0L } )" )
183+ next
184+ }
185+ hasMinor -> {
186+ val next = v.nextMinorVersion()
187+ logger.info(" MINOR version bump: $v → $next " )
188+ next
189+ }
190+ hasPatch -> {
191+ val next = v.nextPatchVersion()
192+ logger.info(" PATCH version bump: $v → $next " )
193+ next
194+ }
195+ else -> {
196+ val next = v.nextPatchVersion()
197+ logger.info(" Default PATCH version bump (commits present but no conventional signal): $v → $next " )
198+ next
199+ }
200+ }
201+
202+ newVersion
130203 } finally {
131204 git.close()
132205 }
0 commit comments