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

fixed previousVersion for tagged commits #413

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package pl.allegro.tech.build.axion.release

import org.gradle.testkit.runner.TaskOutcome

import static pl.allegro.tech.build.axion.release.TagPrefixConf.fullPrefix

class PreviousVersionIntegrationTest extends BaseIntegrationTest {

def "should return undecorated current version if no previous releases"() {
given:
buildFile("""
task outputDecorated { doLast {
println "Previous: \${scmVersion.previousVersion}"
} }
""")

when:
def result = runGradle('outputDecorated')

then:
result.output.contains('Previous: 0.1.0')
result.task(":outputDecorated").outcome == TaskOutcome.SUCCESS
}

def "should return previous version even if current commit is tagged"() {
given:
buildFile("""
task outputDecorated { doLast {
println "Previous: \${scmVersion.previousVersion}"
} }
""")

runGradle('release', '-Prelease.version=1.1.0', '-Prelease.localOnly', '-Prelease.disableChecks')

repository.commit(['*'], "commit after " + fullPrefix() + "1.1.0")

runGradle('release', '-Prelease.version=1.2.0', '-Prelease.localOnly', '-Prelease.disableChecks')

when:
def result = runGradle('outputDecorated')

then:
result.output.contains('Previous: 1.1.0')
result.task(":outputDecorated").outcome == TaskOutcome.SUCCESS
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private VersionInfo readVersions(

boolean onCommitWithLatestChange = currentVersionInfo.isSameCommit(latestChangePosition.getRevision());

TaggedCommits previousTaggedCommit = TaggedCommits.fromLatestCommitBeforeNextVersion(repository, releaseTagPattern, nextVersionTagPattern, latestChangePosition);
TaggedCommits previousTaggedCommit = TaggedCommits.fromPreviousCommitBeforeNextVersion(repository, releaseTagPattern, nextVersionTagPattern, latestChangePosition);
VersionSorter.Result previousVersionInfo = versionFromTaggedCommits(previousTaggedCommit, true, nextVersionTagPattern,
versionFactory, forceSnapshot);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ public static TaggedCommits fromAllCommits(ScmRepository repository, Pattern tag
return new TaggedCommits(latestTagPosition, taggedCommits);
}

public static TaggedCommits fromLatestCommitBeforeNextVersion(ScmRepository repository, Pattern releaseTagPattern, Pattern nextVersionTagPattern, ScmPosition latestTagPosition) {
TagsOnCommit previousTags = repository.latestTags(releaseTagPattern);
public static TaggedCommits fromPreviousCommitBeforeNextVersion(ScmRepository repository, Pattern releaseTagPattern, Pattern nextVersionTagPattern, ScmPosition latestChangePosition) {
TagsOnCommit previousTags = repository.latestTags(releaseTagPattern, latestChangePosition.getRevision());
while (previousTags.hasOnlyMatching(nextVersionTagPattern)) {
previousTags = repository.latestTags(releaseTagPattern, previousTags.getCommitId());
}
return new TaggedCommits(latestTagPosition, Arrays.asList(previousTags));
return new TaggedCommits(latestChangePosition, Arrays.asList(previousTags));
}

public List<TagsOnCommit> getCommits() {
Expand Down