Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try using last tag when -Prelease.tryUsingLastTag=true is provided #171

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ provide the release.useLastTag project property, e.g.

git tag v1.0.0
./gradlew -Prelease.useLastTag=true final

The build will fail if the current commit does not have a tag name following the versioning scheme. If you want to use the tag name if available and otherwise fallback to the default versioning strategy, you may provide the release.tryUsingLastTag project property, e.g.

./gradlew -Prelease.tryUsingLastTag=true build

# Overriding version from the command line

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,28 @@ class ReleasePluginIntegrationSpec extends GitVersioningIntegrationSpec {
then:
new File(projectDir, "build/libs/${moduleName}-19.71.1.jar").exists()
}
def 'try using last tag on tagged version succeeds'() {
git.tag.add(name: 'v42.5.3')

when:
runTasksSuccessfully('final', '-Prelease.tryUsingLastTag=true')

then:
new File(projectDir, "build/libs/${moduleName}-42.5.3.jar").exists()
}

def 'tryUsingLastTag not on tagged version succeeds with fallback to default strategy'() {
git.tag.add(name: 'v42.5.3')
new File(projectDir, "foo").text = "Hi"
git.add(patterns: ['foo'] as Set)
git.commit(message: 'Something got committed')

when:
def version = inferredVersionForTask('-Prelease.tryUsingLastTag=true', 'build')

then:
version.toString().contains('42.6.0-dev.1+')
}

def 'able to release with the override of version calculation'() {
when:
Expand Down
26 changes: 26 additions & 0 deletions src/main/groovy/nebula/plugin/release/OverrideStrategies.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,32 @@ import org.slf4j.LoggerFactory
*/
class OverrideStrategies {

static class TryReleaseLastTagStrategy implements VersionStrategy {
static final String PROPERTY_NAME = 'release.tryUsingLastTag'

@Override
String getName() {
return 'try-using-last-tag'
}

@Override
boolean selector(Project project, Grgit grgit) {
if (!(project.hasProperty(PROPERTY_NAME) && project.property(PROPERTY_NAME).toString().toBoolean())) {
return false
}
try {
new ReleaseLastTagStrategy(project).infer(project, grgit)
} catch (GradleException e) {
return false
}
return true
}

@Override
ReleaseVersion infer(Project project, Grgit grgit) {
return new ReleaseLastTagStrategy(project).infer(project, grgit)
}
}

static class ReleaseLastTagStrategy implements VersionStrategy {
static final String PROPERTY_NAME = 'release.useLastTag'
Expand Down
1 change: 1 addition & 0 deletions src/main/groovy/nebula/plugin/release/ReleasePlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class ReleasePlugin implements Plugin<Project> {
releaseExtension.with {
versionStrategy new OverrideStrategies.NoCommitStrategy()
versionStrategy new OverrideStrategies.ReleaseLastTagStrategy(project)
versionStrategy new OverrideStrategies.TryReleaseLastTagStrategy()
versionStrategy new OverrideStrategies.GradlePropertyStrategy(project)
versionStrategy NetflixOssStrategies.SNAPSHOT(project)
versionStrategy NetflixOssStrategies.IMMUTABLE_SNAPSHOT(project)
Expand Down