Skip to content

Commit

Permalink
#622 fix: evaluate also instance VersionVersionProperties.Incremente…
Browse files Browse the repository at this point in the history
…r to run in right condition if dsl is kotlin (#626)

Test & Documentation
  • Loading branch information
duschata committed May 24, 2023
1 parent 412c7c4 commit b5f4262
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 3 deletions.
6 changes: 6 additions & 0 deletions docs/examples/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ scmVersion {
monorepos {
}

branchVersionIncrementer.putAll(
mapOf<String, Any>(
"master" to VersionProperties.Incrementer { c: VersionIncrementerContext -> c.currentVersion.incrementMajorVersion() }
)
)

versionCreator({versionFromTag,scmPosition -> "version"})
snapshotCreator({versionFromTag,scmPosition -> "version"})
versionIncrementer({versionIncrementerContext -> Version})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package pl.allegro.tech.build.axion.release

import org.ajoberstar.grgit.Grgit
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import pl.allegro.tech.build.axion.release.domain.LocalOnlyResolver
import pl.allegro.tech.build.axion.release.domain.properties.PropertiesBuilder
import pl.allegro.tech.build.axion.release.domain.scm.ScmProperties
import pl.allegro.tech.build.axion.release.domain.scm.ScmRepository
import pl.allegro.tech.build.axion.release.infrastructure.di.ScmRepositoryFactory
import pl.allegro.tech.build.axion.release.infrastructure.di.VersionResolutionContext
import spock.lang.Specification
import spock.lang.TempDir

import static pl.allegro.tech.build.axion.release.domain.scm.ScmPropertiesBuilder.scmProperties

class BranchVersionIncrementerKotlinDslTest extends Specification {

@TempDir
File temporaryFolder

ScmRepository repository

VersionResolutionContext context

void setup() {
def rawRepository = Grgit.init(dir: temporaryFolder)

// let's make sure, not to use system wide user settings in tests
rawRepository.repository.jgit.repository.config.baseConfig.clear()

ScmProperties scmProperties = scmProperties(temporaryFolder).build()
ScmRepository scmRepository = ScmRepositoryFactory.create(scmProperties)

context = new VersionResolutionContext(
PropertiesBuilder.properties().build(),
scmRepository,
scmProperties,
temporaryFolder,
new LocalOnlyResolver(true)
)

repository = context.repository()
repository.commit(['*'], 'initial commit')
repository.tag("V1.0.0")

}


def "should not fail using closure as argument for branchVersionIncrementer"() {
given:

new FileTreeBuilder(temporaryFolder).file("build.gradle.kts",
"""
import com.github.zafarkhaja.semver.Version
import pl.allegro.tech.build.axion.release.domain.VersionIncrementerContext
import pl.allegro.tech.build.axion.release.domain.properties.VersionProperties
plugins {
id ("pl.allegro.tech.build.axion-release")
}
scmVersion {
tag {
prefix.set("V")
}
ignoreUncommittedChanges.set(false)
branchVersionIncrementer.putAll(
mapOf<String, Any>(
"master" to VersionProperties.Incrementer { _: VersionIncrementerContext -> Version.valueOf("42.42.42") }
)
)
}
project.version = scmVersion.version
""")

when:
def result = GradleRunner.create()
.withProjectDir(temporaryFolder)
.withPluginClasspath()
.withArguments('currentVersion', '-s')
.build()

then:
result.output.contains("42.42.42")
result.task(":currentVersion").outcome == TaskOutcome.SUCCESS


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ class KotlinDslCompatibilityTests extends Specification {
monorepos {
}
branchVersionIncrementer.putAll(
mapOf<String, Any>(
"master" to VersionProperties.Incrementer { c: VersionIncrementerContext -> c.currentVersion.incrementMajorVersion() }
)
)
versionCreator(VersionProperties.Creator({a,b -> "c"}))
versionCreator({a,b -> "c"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ class VersionPropertiesFactory {

if (value == null) {
return defaultValue
} else if (!(value instanceof Closure)) {
return converter.call(value)
} else {
} else if ((value instanceof Closure) || (value instanceof VersionProperties.Incrementer)) {
return value
} else {
return converter.call(value)
}
}

Expand Down

0 comments on commit b5f4262

Please sign in to comment.