Skip to content

Commit 8dd9708

Browse files
Ignore non-semver tags (#830)
1 parent 62dc4af commit 8dd9708

File tree

3 files changed

+40
-33
lines changed

3 files changed

+40
-33
lines changed

.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ root = true
44
[*]
55
indent_style = space
66
indent_size = 4
7+
ij_continuation_indent_size = 4
78
end_of_line = lf
89
charset = utf-8
910
trim_trailing_whitespace = true

src/main/java/pl/allegro/tech/build/axion/release/domain/VersionResolver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ private VersionInfo readVersions(
7070

7171
List<Pattern> releaseTagPatterns = tagProperties.getAllPrefixes().stream()
7272
.map(prefix -> prefix.isEmpty() ? "" : prefix + tagProperties.getVersionSeparator())
73-
.map(pattern -> Pattern.compile("^" + pattern + ".*"))
73+
.map(pattern -> Pattern.compile("^" + pattern + "(.+)\\.(.+)\\.(.+)"))
7474
.collect(toList());
75-
Pattern nextVersionTagPattern = Pattern.compile(".*" + nextVersionProperties.getSuffix() + "$");
75+
Pattern nextVersionTagPattern = Pattern.compile("(.+)\\.(.+)\\.(.+)" + nextVersionProperties.getSuffix() + "$");
7676
boolean forceSnapshot = versionProperties.isForceSnapshot();
7777
boolean useHighestVersion = versionProperties.isUseHighestVersion();
7878

src/test/groovy/pl/allegro/tech/build/axion/release/infrastructure/git/GitRepositoryTest.groovy

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ import org.eclipse.jgit.lib.Constants
99
import org.eclipse.jgit.transport.RemoteConfig
1010
import org.eclipse.jgit.transport.URIish
1111
import org.gradle.testfixtures.ProjectBuilder
12-
import pl.allegro.tech.build.axion.release.domain.scm.*
12+
import pl.allegro.tech.build.axion.release.domain.scm.ScmException
13+
import pl.allegro.tech.build.axion.release.domain.scm.ScmIdentity
14+
import pl.allegro.tech.build.axion.release.domain.scm.ScmPosition
15+
import pl.allegro.tech.build.axion.release.domain.scm.ScmProperties
16+
import pl.allegro.tech.build.axion.release.domain.scm.ScmPushOptions
17+
import pl.allegro.tech.build.axion.release.domain.scm.ScmRepositoryUnavailableException
18+
import pl.allegro.tech.build.axion.release.domain.scm.TagsOnCommit
1319
import pl.allegro.tech.build.axion.release.util.WithEnvironment
1420
import spock.lang.Specification
1521

@@ -71,50 +77,50 @@ class GitRepositoryTest extends Specification {
7177
File lightweightTagRepositoryDir = File.createTempDir('axion-release', 'tmp')
7278
Map repositories = GitProjectBuilder.gitProject(lightweightTagRepositoryDir)
7379
.withInitialCommit()
74-
.withLightweightTag(fullPrefix() + '1')
80+
.withLightweightTag(fullPrefix() + '1.0.0')
7581
.build()
7682

7783
GitRepository lightweightTagRepository = repositories[GitRepository] as GitRepository
7884

7985
when:
80-
lightweightTagRepository.tag(fullPrefix() + '2')
86+
lightweightTagRepository.tag(fullPrefix() + '2.0.0')
8187
TagsOnCommit tags = lightweightTagRepository.latestTags(List.of(compile('^' + defaultPrefix() + '.*')))
8288

8389
then:
84-
tags.tags == [fullPrefix() + '1', fullPrefix() + '2']
90+
tags.tags == [fullPrefix() + '1.0.0', fullPrefix() + '2.0.0']
8591
}
8692

8793
def "should create new tag on current commit"() {
8894
when:
89-
repository.tag(fullPrefix() + '1')
95+
repository.tag(fullPrefix() + '1.0.0')
9096

9197
then:
92-
rawRepository.tag.list()*.fullName == ['refs/tags/' + fullPrefix() + '1']
98+
rawRepository.tag.list()*.fullName == ['refs/tags/' + fullPrefix() + '1.0.0']
9399
}
94100

95101
def "should create tag when on HEAD even if it already exists on the same commit"() {
96102
given:
97-
repository.tag(fullPrefix() + '1')
103+
repository.tag(fullPrefix() + '1.0.0')
98104

99105
when:
100-
repository.tag(fullPrefix() + '1')
106+
repository.tag(fullPrefix() + '1.0.0')
101107

102108
then:
103-
rawRepository.tag.list()*.fullName == ['refs/tags/' + fullPrefix() + '1']
109+
rawRepository.tag.list()*.fullName == ['refs/tags/' + fullPrefix() + '1.0.0']
104110
}
105111

106112
def "should throw an exception when creating new tag that already exists and it's not on HEAD"() {
107113
given:
108-
repository.tag(fullPrefix() + '1')
114+
repository.tag(fullPrefix() + '1.0.0')
109115
repository.commit(['*'], "commit after release")
110116

111117
when:
112-
repository.tag(fullPrefix() + '1')
118+
repository.tag(fullPrefix() + '1.0.0')
113119

114120
then:
115121
ScmException e = thrown(ScmException)
116122
e.getCause() instanceof RefAlreadyExistsException
117-
rawRepository.tag.list()*.fullName == ['refs/tags/' + fullPrefix() + '1']
123+
rawRepository.tag.list()*.fullName == ['refs/tags/' + fullPrefix() + '1.0.0']
118124
}
119125

120126
def "should create commit with given message"() {
@@ -135,14 +141,14 @@ class GitRepositoryTest extends Specification {
135141

136142
def "should return last tag in current position in simple case"() {
137143
given:
138-
repository.tag(fullPrefix() + '1')
144+
repository.tag(fullPrefix() + '1.0.0')
139145
repository.commit(['*'], "commit after release")
140146

141147
when:
142148
TagsOnCommit tags = repository.latestTags(List.of(Pattern.compile('^' + defaultPrefix() + '.*')))
143149

144150
then:
145-
tags.tags == [fullPrefix() + '1']
151+
tags.tags == [fullPrefix() + '1.0.0']
146152
}
147153

148154
def "should return no tags when no commit in repository"() {
@@ -158,37 +164,37 @@ class GitRepositoryTest extends Specification {
158164

159165
def "should indicate that position is on tag when latest commit is tagged"() {
160166
given:
161-
repository.tag(fullPrefix() + '1')
167+
repository.tag(fullPrefix() + '1.0.0')
162168

163169
when:
164170
TagsOnCommit tags = repository.latestTags(List.of(Pattern.compile('' + defaultPrefix() + '.*')))
165171

166172
then:
167-
tags.tags == [fullPrefix() + '1']
173+
tags.tags == [fullPrefix() + '1.0.0']
168174
}
169175

170176
def "should track back to older tag when commit was made after checking out older version"() {
171177
given:
172-
repository.tag(fullPrefix() + '1')
178+
repository.tag(fullPrefix() + '1.0.0')
173179
repository.commit(['*'], "commit after " + fullPrefix() + "1")
174-
repository.tag(fullPrefix() + '2')
180+
repository.tag(fullPrefix() + '2.0.0')
175181
repository.commit(['*'], "commit after " + fullPrefix() + "2")
176182

177-
rawRepository.checkout(branch: fullPrefix() + '1')
183+
rawRepository.checkout(branch: fullPrefix() + '1.0.0')
178184
repository.commit(['*'], "bugfix after " + fullPrefix() + "1")
179185

180186
when:
181187
TagsOnCommit tags = repository.latestTags(List.of(Pattern.compile("^" + defaultPrefix() + ".*")))
182188

183189
then:
184-
tags.tags == [fullPrefix() + '1']
190+
tags.tags == [fullPrefix() + '1.0.0']
185191
}
186192

187193
def "should return all tagged commits matching the pattern provided"() {
188194
given:
189-
repository.tag(fullPrefix() + '1')
195+
repository.tag(fullPrefix() + '1.0.0')
190196
repository.commit(['*'], "commit after " + fullPrefix() + "1")
191-
repository.tag(fullPrefix() + '2')
197+
repository.tag(fullPrefix() + '2.0.0')
192198
repository.commit(['*'], "commit after " + fullPrefix() + "2")
193199
repository.tag('another-tag-1')
194200
repository.commit(['*'], "commit after another-tag-1")
@@ -202,20 +208,20 @@ class GitRepositoryTest extends Specification {
202208
List<TagsOnCommit> allTaggedCommits = repository.taggedCommits(List.of(compile('^' + defaultPrefix() + '.*')))
203209

204210
then:
205-
allTaggedCommits.collect { c -> c.tags[0] } == [fullPrefix() + '3', fullPrefix() + '4', fullPrefix() + '2', fullPrefix() + '1']
211+
allTaggedCommits.collect { c -> c.tags[0] } == [fullPrefix() + '3', fullPrefix() + '4', fullPrefix() + '2.0.0', fullPrefix() + '1.0.0']
206212
}
207213

208214
def "should return only tags that match with prefix"() {
209215
given:
210-
repository.tag(fullPrefix() + '1')
216+
repository.tag(fullPrefix() + '1.0.0')
211217
repository.commit(['*'], "commit after " + fullPrefix() + "1")
212218
repository.tag('otherTag')
213219

214220
when:
215221
TagsOnCommit tags = repository.latestTags(List.of(Pattern.compile('^' + defaultPrefix() + '.*')))
216222

217223
then:
218-
tags.tags == [fullPrefix() + '1']
224+
tags.tags == [fullPrefix() + '1.0.0']
219225
}
220226

221227
def "should return latest tagged commit before the given commit id"() {
@@ -235,14 +241,14 @@ class GitRepositoryTest extends Specification {
235241

236242
def "should return list of tags when multiple matching tags found on same commit"() {
237243
given:
238-
repository.tag(fullPrefix() + '1')
239-
repository.tag(fullPrefix() + '2')
244+
repository.tag(fullPrefix() + '1.0.0')
245+
repository.tag(fullPrefix() + '2.0.0')
240246

241247
when:
242248
TagsOnCommit tags = repository.latestTags(List.of(compile('^' + defaultPrefix() + '.*')))
243249

244250
then:
245-
tags.tags == [fullPrefix() + '1', fullPrefix() + '2']
251+
tags.tags == [fullPrefix() + '1.0.0', fullPrefix() + '2.0.0']
246252
}
247253

248254
def "should attach to remote repository"() {
@@ -656,7 +662,7 @@ class GitRepositoryTest extends Specification {
656662
])
657663
def 'should unshallow repo on CI'() {
658664
given:
659-
remoteRepository.tag(fullPrefix() + '1')
665+
remoteRepository.tag(fullPrefix() + '1.0.0')
660666
100.times { remoteRepository.commit(['*'], "commit after release") }
661667
File repoDir = File.createTempDir('axion-release', 'tmp')
662668
Map repositories = GitProjectBuilder.gitProject(repoDir, remoteRepositoryDir, 1).build()
@@ -666,15 +672,15 @@ class GitRepositoryTest extends Specification {
666672
TagsOnCommit tags = repository.latestTags(List.of(compile('^' + defaultPrefix() + '.*')))
667673

668674
then:
669-
tags.tags == [fullPrefix() + '1']
675+
tags.tags == [fullPrefix() + '1.0.0']
670676
}
671677

672678
@WithEnvironment([
673679
'CI=false'
674680
])
675681
def 'should not unshallow repo locally'() {
676682
given:
677-
remoteRepository.tag(fullPrefix() + '1')
683+
remoteRepository.tag(fullPrefix() + '1.0.0')
678684
100.times { remoteRepository.commit(['*'], "commit after release") }
679685
File repoDir = File.createTempDir('axion-release', 'tmp')
680686
Map repositories = GitProjectBuilder.gitProject(repoDir, remoteRepositoryDir, 1).build()

0 commit comments

Comments
 (0)