Skip to content

Commit 0b03cad

Browse files
committed
Merge pull request #98 from allegro/development
merge development to master for 1.3.1
2 parents 3499b27 + ddb0139 commit 0b03cad

24 files changed

+224
-41
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ buildscript {
33
maven { url 'https://plugins.gradle.org/m2/' }
44
}
55
dependencies {
6-
classpath group: 'com.gradle.publish', name: 'plugin-publish-plugin', version: '0.9.0'
6+
classpath group: 'com.gradle.publish', name: 'plugin-publish-plugin', version: '0.9.1'
77
}
88
}
99

@@ -64,7 +64,7 @@ jacocoTestReport {
6464
}
6565

6666
task wrapper(type: Wrapper) {
67-
gradleVersion = '2.4'
67+
gradleVersion = '2.5'
6868
}
6969

7070
pluginBundle {

docs/changelog.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
Changelog
22
=========
3+
4+
* **1.3.1** (16.08.2015)
5+
* added option to treat uncommitted changes as repository change
6+
* added ``push`` hook action
37
* **1.3.0** (11.07.2015)
48
* support for custom version incrementation rules - thanks to `vbuell <https://github.com/vbuell>`_ for contribution
59
* ability to push only tags to remote repo - thanks to `erichsend <https://github.com/erichsend>`_ for contribution

docs/configuration/hooks.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,20 @@ current version and SCM position as arguments::
6060
}
6161
}
6262

63+
push
64+
----
65+
66+
Pushes all changes to the remote::
67+
68+
scmVersion {
69+
hooks {
70+
post 'push'
71+
}
72+
}
73+
74+
There is no additional magic in this action. Use with care, only when you have some commits that need to be pushed for
75+
example as a `post` action. Remember, that push is always done during the release.
76+
6377
Custom action
6478
-------------
6579

docs/configuration/overview.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ All ``axion-release-plugin`` configuration options:
1919
2020
// :doc:`dry_run`
2121
localOnly = false // never connect to remote
22+
23+
// :doc:`uncommitted_changes`
24+
ignoreUncommittedChanges = true // should uncommitted changes force version bump
2225
2326
// :ref:`version-sanitization`
2427
sanitizeVersion = true // should created version be sanitized, true by default
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Uncommitted changes
2+
===================
3+
4+
By default ``axion-release`` uses snapshot version only when there are some commits after tag. Sometimes it might
5+
be useful to scan for uncommitted changes and use snapshot version if they are present.
6+
7+
In order to treat uncommitted changes as trigger for version increment, change setting::
8+
9+
scmVersion {
10+
ignoreUncommittedChanges = false
11+
}
12+
13+
This changes behavior from::
14+
15+
# ./gradlew currentVersion
16+
1.0.0
17+
18+
# cat "hello" > some_uncommitted_file
19+
20+
# ./gradlew currentVersion
21+
1.0.0
22+
23+
to::
24+
25+
# ./gradlew currentVersion
26+
1.0.0
27+
28+
# cat "hello" > some_uncommitted_file
29+
30+
# ./gradlew currentVersion
31+
1.0.1-SNAPSHOT
32+
33+
You can always override this option using command line::
34+
35+
# ./gradlew currentVersion -Prelease.ignoreUncommittedChanges
36+
1.0.0

docs/configuration/version.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ incrementMinorIfNotOnRelease
165165
This rule uses additional parameter ``releaseBranchPattern`` (by default it's set to 'release/.+')::
166166

167167
scmVersion {
168-
versionIncrementingRule 'incrementMinorIfNotOnRelease', [releaseBranchPattern: 'release.*']
168+
versionIncrementer 'incrementMinorIfNotOnRelease', [releaseBranchPattern: 'release.*']
169169
}
170170

171171
branchSpecific
@@ -174,13 +174,13 @@ branchSpecific
174174
This rule accepts map of ``branch pattern -> incrementer name`` and uses first incrementer that matches branch pattern::
175175

176176
scmVersion {
177-
versionIncrementingRule 'branchSpecific', ['master': 'incrementPatch', 'feature/.*': 'incrementMinor']
177+
versionIncrementer 'branchSpecific', ['master': 'incrementPatch', 'feature/.*': 'incrementMinor']
178178
}
179179

180180
The arguments map will be passed on to called incrementer, so you can add some more parameters at the end of it::
181181

182182
scmVersion {
183-
versionIncrementingRule 'branchSpecific', ['master': 'incrementPatch', '.*': 'incrementMinorIfNotOnRelease', releaseBranchPattern: 'release.*']
183+
versionIncrementer 'branchSpecific', ['master': 'incrementPatch', '.*': 'incrementMinorIfNotOnRelease', releaseBranchPattern: 'release.*']
184184
}
185185

186186
.. _version-decorating:

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Configuration
2424
configuration/authorization
2525
configuration/version
2626
configuration/force_version
27+
configuration/uncommitted_changes
2728
configuration/next_version
2829
configuration/checks
2930
configuration/dry_run

gradle/wrapper/gradle-wrapper.jar

-5 Bytes
Binary file not shown.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Sat Jul 11 00:26:26 CEST 2015
1+
#Sat Jul 11 01:04:47 CEST 2015
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-bin.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-bin.zip

src/main/groovy/pl/allegro/tech/build/axion/release/domain/Releaser.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Releaser {
3030
VersionWithPosition positionedVersion = versionConfig.getRawVersion()
3131
Version version = positionedVersion.version
3232

33-
if (notOnTagAlready(positionedVersion) || VersionReadOptions.fromProject(project).forceVersion) {
33+
if (notOnTagAlready(positionedVersion) || VersionReadOptions.fromProject(project, versionConfig).forceVersion) {
3434
String tagName = versionConfig.tag.serialize(versionConfig.tag, version.toString())
3535

3636
if (versionConfig.createReleaseCommit) {

src/main/groovy/pl/allegro/tech/build/axion/release/domain/VersionConfig.groovy

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class VersionConfig {
1616

1717
boolean dryRun
1818

19+
boolean ignoreUncommittedChanges = true
20+
1921
RepositoryConfig repository
2022

2123
TagNameSerializationRules tag = new TagNameSerializationRules()
@@ -105,15 +107,15 @@ class VersionConfig {
105107
String getVersion() {
106108
if (resolvedVersion == null) {
107109
ensureVersionServiceExists()
108-
resolvedVersion = versionService.currentDecoratedVersion(this, VersionReadOptions.fromProject(project))
110+
resolvedVersion = versionService.currentDecoratedVersion(this, VersionReadOptions.fromProject(project, this))
109111
}
110112
return resolvedVersion
111113
}
112114

113115
VersionWithPosition getRawVersion() {
114116
if (rawVersion == null) {
115117
ensureVersionServiceExists()
116-
rawVersion = versionService.currentVersion(this, VersionReadOptions.fromProject(project))
118+
rawVersion = versionService.currentVersion(this, VersionReadOptions.fromProject(project, this))
117119
}
118120
return rawVersion
119121
}

src/main/groovy/pl/allegro/tech/build/axion/release/domain/VersionFactory.groovy

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ class VersionFactory {
1515
version = Version.valueOf(initialVersion(config.tag, context.position))
1616
} else {
1717
version = Version.valueOf(readVersionFromPosition(context, config))
18-
if (!context.position.onTag && !context.nextVersionTag) {
18+
19+
boolean hasUncommitedChanges = !options.ignoreUncommittedChanges && context.position.hasUncommittedChanges
20+
boolean hasChanges = !context.position.onTag || hasUncommitedChanges
21+
22+
if (hasChanges && !context.nextVersionTag) {
1923
version = config.versionIncrementer(new VersionIncrementerContext(version, context.position))
2024
}
2125
}

src/main/groovy/pl/allegro/tech/build/axion/release/domain/VersionReadOptions.groovy

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,27 @@ class VersionReadOptions {
66

77
private static final String FORCE_VERSION_PROPERTY = 'release.forceVersion'
88

9+
private static final String IGNORE_UNCOMMITTED_CHANGES_PROPERTY = 'release.ignoreUncommittedChanges'
10+
911
final boolean forceVersion
1012

1113
final String forcedVersion
14+
15+
final boolean ignoreUncommittedChanges
1216

13-
VersionReadOptions(String forcedVersion) {
17+
VersionReadOptions(String forcedVersion, ignoreUncommittedChanges) {
1418
this.forceVersion = forcedVersion != null
1519
this.forcedVersion = forcedVersion
20+
this.ignoreUncommittedChanges = ignoreUncommittedChanges
1621
}
1722

18-
static VersionReadOptions fromProject(Project project) {
23+
static VersionReadOptions fromProject(Project project, VersionConfig config) {
1924
String forceVersionValue = project.hasProperty(FORCE_VERSION_PROPERTY) ? project.property(FORCE_VERSION_PROPERTY) : null
20-
return new VersionReadOptions(forceVersionValue?.trim() ? forceVersionValue.trim() : null)
25+
boolean ignoreUncommittedChanges = project.hasProperty(IGNORE_UNCOMMITTED_CHANGES_PROPERTY) ?: config.ignoreUncommittedChanges
26+
return new VersionReadOptions(forceVersionValue?.trim() ? forceVersionValue.trim() : null, ignoreUncommittedChanges)
2127
}
2228

2329
static VersionReadOptions defaultOptions() {
24-
return new VersionReadOptions(null)
30+
return new VersionReadOptions(null, true)
2531
}
2632
}

src/main/groovy/pl/allegro/tech/build/axion/release/domain/VersionService.groovy

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class VersionService {
1919
VersionWithPosition currentVersion(VersionConfig versionConfig, VersionReadOptions options) {
2020
VersionWithPosition positionedVersion = versionResolver.resolveVersion(versionConfig, options)
2121

22-
if (!positionedVersion.position.onTag) {
22+
if(isSnapshotVersion(positionedVersion, options)) {
2323
positionedVersion.asSnapshotVersion()
2424
}
2525

@@ -34,10 +34,15 @@ class VersionService {
3434
version = sanitizer.sanitize(version)
3535
}
3636

37-
if (!positionedVersion.position.onTag) {
37+
if(isSnapshotVersion(positionedVersion, options)) {
3838
version = version + '-' + SNAPSHOT
3939
}
4040

4141
return version
4242
}
43+
44+
private boolean isSnapshotVersion(VersionWithPosition positionedVersion, VersionReadOptions options) {
45+
boolean hasUncommittedChanges = !options.ignoreUncommittedChanges && positionedVersion.position.hasUncommittedChanges
46+
return !positionedVersion.position.onTag || hasUncommittedChanges
47+
}
4348
}

src/main/groovy/pl/allegro/tech/build/axion/release/domain/hooks/HookContext.groovy

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class HookContext {
1515

1616
final String previousVersion
1717

18-
final String currentVersion
18+
private String currentVersion
1919

2020
final List<String> patternsToCommit = []
2121

@@ -28,6 +28,14 @@ class HookContext {
2828
this.currentVersion = currentVersion.toString()
2929
}
3030

31+
String getCurrentVersion() {
32+
return currentVersion
33+
}
34+
35+
void updateVersion(Version currentVersion) {
36+
this.currentVersion = currentVersion.toString()
37+
}
38+
3139
void commit(List patterns, String message) {
3240
scmService.commit(patterns, message)
3341
}
@@ -39,4 +47,8 @@ class HookContext {
3947
void addCommitPattern(Collection patterns) {
4048
patternsToCommit.addAll(patterns)
4149
}
50+
51+
void push() {
52+
scmService.push()
53+
}
4254
}

src/main/groovy/pl/allegro/tech/build/axion/release/domain/hooks/PredefinedReleaseHookAction.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ enum PredefinedReleaseHookAction {
44

55
DEFAULT('default', new SimpleReleaseHookAction.Factory()),
66
FILE_UPDATE('fileUpdate', new FileUpdateHookAction.Factory()),
7-
COMMIT('commit', new CommitHookAction.Factory());
7+
COMMIT('commit', new CommitHookAction.Factory()),
8+
PUSH('push', new PushHookAction.Factory());
89

910
private final String type
1011

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package pl.allegro.tech.build.axion.release.domain.hooks
2+
3+
class PushHookAction implements ReleaseHookAction {
4+
5+
@Override
6+
void act(HookContext hookContext) {
7+
hookContext.push()
8+
}
9+
10+
static final class Factory extends DefaultReleaseHookFactory {
11+
12+
@Override
13+
ReleaseHookAction create() {
14+
return new PushHookAction()
15+
}
16+
17+
@Override
18+
ReleaseHookAction create(Closure customAction) {
19+
return create()
20+
}
21+
}
22+
}

src/main/groovy/pl/allegro/tech/build/axion/release/domain/scm/ScmPosition.groovy

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,34 @@ class ScmPosition {
77
final String latestTag
88

99
final boolean onTag
10+
11+
final boolean hasUncommittedChanges
1012

11-
ScmPosition(String branch, String latestTag, boolean onTag) {
13+
ScmPosition(String branch, String latestTag, boolean onTag, boolean hasUncommittedChanges = false) {
1214
this.branch = branch
1315
this.latestTag = latestTag
1416
this.onTag = onTag
17+
this.hasUncommittedChanges = hasUncommittedChanges
1518
}
1619

1720
static ScmPosition defaultPosition() {
18-
return new ScmPosition('master', null, false)
21+
return new ScmPosition('master', null, false, false)
1922
}
2023

2124
static ScmPosition onTag(String tagName) {
22-
return new ScmPosition('master', tagName, true)
25+
return new ScmPosition('master', tagName, true, false)
2326
}
2427

2528
boolean tagless() {
2629
return latestTag == null
2730
}
2831

2932
ScmPosition asOnTagPosition() {
30-
return new ScmPosition(branch, latestTag, latestTag != null)
33+
return new ScmPosition(branch, latestTag, latestTag != null, hasUncommittedChanges)
3134
}
3235

3336
ScmPosition asNotOnTagPosition() {
34-
return new ScmPosition(branch, latestTag, false)
37+
return new ScmPosition(branch, latestTag, false, hasUncommittedChanges)
3538
}
3639

3740
@Override

src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/git/GitRepository.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class GitRepository implements ScmRepository {
180180
walk.dispose()
181181

182182
boolean onTag = (commit == null) ? null : commit.id.name() == headId.name()
183-
return new ScmPosition(branch, tagName, onTag)
183+
return new ScmPosition(branch, tagName, onTag, checkUncommittedChanges())
184184
}
185185

186186
private boolean hasCommits() {

0 commit comments

Comments
 (0)