-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resolving #18 - added option to create empty commit to mark release
- Loading branch information
1 parent
cab90ad
commit 262cb85
Showing
12 changed files
with
209 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...y/pl/allegro/tech/build/axion/release/domain/PredefinedReleaseCommitMessageCreator.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package pl.allegro.tech.build.axion.release.domain | ||
|
||
import pl.allegro.tech.build.axion.release.domain.scm.ScmPosition | ||
|
||
enum PredefinedReleaseCommitMessageCreator { | ||
|
||
DEFAULT('default', { String version, ScmPosition position -> | ||
return "release version: $version" | ||
}); | ||
|
||
private final String type | ||
|
||
final Closure commitMessageCreator | ||
|
||
private PredefinedReleaseCommitMessageCreator(String type, Closure c) { | ||
this.type = type | ||
this.commitMessageCreator = c | ||
} | ||
|
||
static Closure commitMessageCreatorFor(String type) { | ||
PredefinedReleaseCommitMessageCreator creator = PredefinedReleaseCommitMessageCreator.values().find { it.type == type } | ||
if (creator == null) { | ||
throw new IllegalArgumentException("There is no predefined commit message creator with $type type. " + | ||
"You can choose from: ${PredefinedReleaseCommitMessageCreator.values().collect { it.type }}"); | ||
} | ||
return creator.commitMessageCreator | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
src/main/groovy/pl/allegro/tech/build/axion/release/domain/Releaser.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package pl.allegro.tech.build.axion.release.domain | ||
|
||
import com.github.zafarkhaja.semver.Version | ||
import org.gradle.api.logging.Logger | ||
import pl.allegro.tech.build.axion.release.domain.scm.ScmRepository | ||
|
||
class Releaser { | ||
|
||
private final ScmRepository repository | ||
|
||
private final LocalOnlyResolver localOnlyResolver | ||
|
||
private final Logger logger | ||
|
||
Releaser(ScmRepository repository, LocalOnlyResolver localOnlyResolver, Logger logger) { | ||
this.repository = repository | ||
this.localOnlyResolver = localOnlyResolver | ||
this.logger = logger | ||
} | ||
|
||
void release(VersionConfig versionConfig) { | ||
VersionWithPosition positionedVersion = versionConfig.getRawVersion() | ||
Version version = positionedVersion.version | ||
|
||
if (version.preReleaseVersion == VersionService.SNAPSHOT) { | ||
version = version.setPreReleaseVersion(null) | ||
String tagName = versionConfig.tag.serialize(versionConfig.tag, version.toString()) | ||
|
||
if(versionConfig.createReleaseCommit) { | ||
logger.quiet("Creating release commit") | ||
repository.commit(versionConfig.releaseCommitMessage(version.toString(), positionedVersion.position)) | ||
} | ||
|
||
logger.quiet("Creating tag: $tagName") | ||
repository.tag(tagName) | ||
|
||
if(!localOnlyResolver.localOnly(repository.remoteAttached(versionConfig.remote))) { | ||
logger.quiet("Pushing all to remote: ${versionConfig.remote}") | ||
repository.push(versionConfig.remote) | ||
} | ||
else { | ||
logger.quiet("Changes made to local repository only") | ||
} | ||
} | ||
else { | ||
logger.quiet("Working on released version ${versionConfig.version}, nothing to do here.") | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,5 @@ interface ScmRepository { | |
|
||
boolean checkAheadOfRemote() | ||
|
||
List<String> lastLogMessages(int messageCount) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/test/groovy/pl/allegro/tech/build/axion/release/domain/ReleaserTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package pl.allegro.tech.build.axion.release.domain | ||
|
||
import org.ajoberstar.grgit.Grgit | ||
import org.gradle.api.Project | ||
import org.gradle.testfixtures.ProjectBuilder | ||
import pl.allegro.tech.build.axion.release.domain.scm.ScmRepository | ||
import pl.allegro.tech.build.axion.release.infrastructure.ComponentFactory | ||
import spock.lang.Specification | ||
|
||
class ReleaserTest extends Specification { | ||
|
||
Project project | ||
|
||
ScmRepository repository | ||
|
||
Releaser releaser | ||
|
||
VersionConfig config | ||
|
||
def setup() { | ||
project = ProjectBuilder.builder().build() | ||
|
||
Grgit.init(dir: project.rootDir) | ||
|
||
config = ComponentFactory.versionConfig(project, 'scmVersion') | ||
repository = ComponentFactory.scmRepository(project, config) | ||
|
||
repository.commit('initial commit') | ||
|
||
releaser = new Releaser(repository, new LocalOnlyResolver(config, project), project.logger) | ||
} | ||
|
||
def "should release new version when not on tag"() { | ||
given: | ||
project.extensions.extraProperties.set('release.forceVersion', '2.0.0') | ||
|
||
when: | ||
releaser.release(config) | ||
|
||
then: | ||
config.getVersion() == '2.0.0' | ||
} | ||
|
||
def "should not release version when on tag"() { | ||
given: | ||
repository.tag('release-1.0.0') | ||
|
||
when: | ||
releaser.release(config) | ||
|
||
then: | ||
config.getVersion() == '1.0.0' | ||
} | ||
|
||
def "should create release commit if configured"() { | ||
given: | ||
project.extensions.extraProperties.set('release.forceVersion', '3.0.0') | ||
config.createReleaseCommit = true | ||
|
||
when: | ||
releaser.release(config) | ||
|
||
then: | ||
config.getVersion() == '3.0.0' | ||
repository.lastLogMessages(1) == ['release version: 3.0.0'] | ||
} | ||
} |