Should remove all previous, same minor versions for a GA release
fixes #61
This commit is contained in:
@@ -83,6 +83,13 @@ public class ProjectVersion {
|
||||
return this.version.matches(".*.SR[0-9]+");
|
||||
}
|
||||
|
||||
public boolean isSameMinor(String version) {
|
||||
String[] splitThis = this.version.split("\\.");
|
||||
String[] splitThat = version.split("\\.");
|
||||
return splitThis.length == splitThat.length &&
|
||||
splitThis[0].equals(splitThat[0]) && splitThis[1].equals(splitThat[1]);
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
return this.version;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package org.springframework.cloud.release.internal.sagan;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cloud.release.internal.pom.ProjectVersion;
|
||||
@@ -21,14 +24,22 @@ public class SaganUpdater {
|
||||
|
||||
public void updateSagan(String branch, ProjectVersion originalVersion, ProjectVersion version) {
|
||||
ReleaseUpdate update = releaseUpdate(branch, originalVersion, version);
|
||||
updateSaganForGa(branch, originalVersion, version);
|
||||
log.info("Updating Sagan with \n\n{}", update);
|
||||
this.saganClient.updateRelease(version.projectName, Collections.singletonList(update));
|
||||
}
|
||||
|
||||
private void updateSaganForGa(String branch, ProjectVersion originalVersion,
|
||||
ProjectVersion version) {
|
||||
if (version.isRelease() || version.isServiceRelease()) {
|
||||
log.info("Version is GA [{}]. Will remove old snapshot and add a new one", version);
|
||||
log.info("Version is GA [{}]. Will remove all older versions and mark this as current", version);
|
||||
Project project = this.saganClient.getProject(version.projectName);
|
||||
if (project != null) {
|
||||
removeAllSameMinorVersions(version, project);
|
||||
}
|
||||
String snapshot = toSnapshot(version.version);
|
||||
removeVersionFromSagan(version, snapshot);
|
||||
String bumpedSnapshot = toSnapshot(version.bumpedVersion());
|
||||
log.info("Removing [{}/{}] from Sagan", version.projectName, snapshot);
|
||||
this.saganClient.deleteRelease(version.projectName, snapshot);
|
||||
ReleaseUpdate snapshotUpdate =
|
||||
releaseUpdate(branch, originalVersion, new ProjectVersion(version.projectName, bumpedSnapshot));
|
||||
log.info("Updating Sagan with \n\n[{}]", snapshotUpdate);
|
||||
@@ -36,6 +47,18 @@ public class SaganUpdater {
|
||||
}
|
||||
}
|
||||
|
||||
private void removeAllSameMinorVersions(ProjectVersion version, Project project) {
|
||||
project.projectReleases.stream()
|
||||
.filter(release -> version.isSameMinor(release.version))
|
||||
.collect(Collectors.toList())
|
||||
.forEach(release -> removeVersionFromSagan(version, release.version));
|
||||
}
|
||||
|
||||
private void removeVersionFromSagan(ProjectVersion version, String snapshot) {
|
||||
log.info("Removing [{}/{}] from Sagan", version.projectName, snapshot);
|
||||
this.saganClient.deleteRelease(version.projectName, snapshot);
|
||||
}
|
||||
|
||||
private ReleaseUpdate releaseUpdate(String branch, ProjectVersion originalVersion,
|
||||
ProjectVersion version) {
|
||||
ReleaseUpdate update = new ReleaseUpdate();
|
||||
@@ -45,6 +68,7 @@ public class SaganUpdater {
|
||||
update.releaseStatus = version(version);
|
||||
update.apiDocUrl = referenceUrl(branch, version);
|
||||
update.refDocUrl = referenceUrl(branch, version);
|
||||
update.current = true;
|
||||
return update;
|
||||
}
|
||||
|
||||
|
||||
@@ -152,6 +152,30 @@ public class ProjectVersionTests {
|
||||
then(projectVersion(version).isRc()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_return_true_when_versions_are_from_same_minor() {
|
||||
String thisVersion = "1.3.1.RC3";
|
||||
String thatVersion = "1.3.2.SR3";
|
||||
|
||||
then(projectVersion(thisVersion).isSameMinor(thatVersion)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_return_false_when_versions_of_different_sizes() {
|
||||
String thisVersion = "1.3.1.RC3";
|
||||
String thatVersion = "1.3.RC3";
|
||||
|
||||
then(projectVersion(thisVersion).isSameMinor(thatVersion)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_return_false_when_versions_not_of_same_minor() {
|
||||
String thisVersion = "1.3.1.RC3";
|
||||
String thatVersion = "1.4.2.RC3";
|
||||
|
||||
then(projectVersion(thisVersion).isSameMinor(thatVersion)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_return_empty_group_id_when_it_is_missing() {
|
||||
ProjectVersion projectVersion = projectVersion("1.0.0.RC1");
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package org.springframework.cloud.release.internal.sagan;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.hamcrest.Description;
|
||||
import org.hamcrest.TypeSafeMatcher;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.BDDMockito;
|
||||
@@ -12,6 +14,10 @@ import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.springframework.cloud.release.internal.pom.ProjectVersion;
|
||||
|
||||
import static org.mockito.BDDMockito.then;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.never;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
@@ -21,10 +27,29 @@ public class SaganUpdaterTest {
|
||||
@Mock SaganClient saganClient;
|
||||
@InjectMocks SaganUpdater saganUpdater;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
Project project = new Project();
|
||||
project.projectReleases.addAll(Arrays.asList(
|
||||
release("1.0.0.RC1"),
|
||||
release("1.1.0.BUILD-SNAPSHOT"),
|
||||
release("2.0.0.M4"))
|
||||
);
|
||||
BDDMockito.given(this.saganClient.getProject(anyString()))
|
||||
.willReturn(project);
|
||||
}
|
||||
|
||||
private Release release(String version) {
|
||||
Release release = new Release();
|
||||
release.version = version;
|
||||
release.current = true;
|
||||
return release;
|
||||
}
|
||||
|
||||
@Test public void should_update_sagan_for_milestone() throws Exception {
|
||||
this.saganUpdater.updateSagan("master", version("1.0.0.M1"), version("1.0.0.M1"));
|
||||
|
||||
BDDMockito.then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"),
|
||||
then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"),
|
||||
BDDMockito.argThat(withReleaseUpdate("1.0.0.M1",
|
||||
"http://cloud.spring.io/spring-cloud-static/foo/{version}/", "PRERELEASE")));
|
||||
}
|
||||
@@ -32,7 +57,7 @@ public class SaganUpdaterTest {
|
||||
@Test public void should_update_sagan_for_rc() throws Exception {
|
||||
this.saganUpdater.updateSagan("master", version("1.0.0.RC1"), version("1.0.0.RC1"));
|
||||
|
||||
BDDMockito.then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"),
|
||||
then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"),
|
||||
BDDMockito.argThat(withReleaseUpdate("1.0.0.RC1",
|
||||
"http://cloud.spring.io/spring-cloud-static/foo/{version}/", "PRERELEASE")));
|
||||
}
|
||||
@@ -46,7 +71,7 @@ public class SaganUpdaterTest {
|
||||
|
||||
this.saganUpdater.updateSagan("master", projectVersion, projectVersion);
|
||||
|
||||
BDDMockito.then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"),
|
||||
then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"),
|
||||
BDDMockito.argThat(withReleaseUpdate("1.0.0.BUILD-SNAPSHOT",
|
||||
"http://cloud.spring.io/foo/foo.html", "SNAPSHOT")));
|
||||
}
|
||||
@@ -56,11 +81,13 @@ public class SaganUpdaterTest {
|
||||
|
||||
this.saganUpdater.updateSagan("master", projectVersion, projectVersion);
|
||||
|
||||
BDDMockito.then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"),
|
||||
then(this.saganClient).should().deleteRelease("foo", "1.0.0.RC1");
|
||||
then(this.saganClient).should().deleteRelease("foo", "1.0.0.BUILD-SNAPSHOT");
|
||||
then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"),
|
||||
BDDMockito.argThat(withReleaseUpdate("1.0.0.RELEASE",
|
||||
"http://cloud.spring.io/spring-cloud-static/foo/{version}/", "GENERAL_AVAILABILITY")));
|
||||
BDDMockito.then(this.saganClient).should().deleteRelease("foo", "1.0.0.BUILD-SNAPSHOT");
|
||||
BDDMockito.then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"),
|
||||
then(this.saganClient).should().deleteRelease("foo", "1.0.0.BUILD-SNAPSHOT");
|
||||
then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"),
|
||||
BDDMockito.argThat(withReleaseUpdate("1.0.1.BUILD-SNAPSHOT",
|
||||
"http://cloud.spring.io/foo/foo.html", "SNAPSHOT")));
|
||||
}
|
||||
@@ -70,7 +97,8 @@ public class SaganUpdaterTest {
|
||||
|
||||
this.saganUpdater.updateSagan("1.1.x", projectVersion, projectVersion);
|
||||
|
||||
BDDMockito.then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"),
|
||||
then(this.saganClient).should(never()).deleteRelease(anyString(), anyString());
|
||||
then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"),
|
||||
BDDMockito.argThat(withReleaseUpdate("1.1.0.BUILD-SNAPSHOT",
|
||||
"http://cloud.spring.io/foo/1.1.x/", "SNAPSHOT")));
|
||||
}
|
||||
@@ -84,7 +112,8 @@ public class SaganUpdaterTest {
|
||||
releaseStatus.equals(item.releaseStatus) &&
|
||||
version.equals(item.version) &&
|
||||
refDocUrl.equals(item.apiDocUrl) &&
|
||||
refDocUrl.equals(item.refDocUrl);
|
||||
refDocUrl.equals(item.refDocUrl) &&
|
||||
item.current;
|
||||
}
|
||||
|
||||
@Override public void describeTo(Description description) {
|
||||
|
||||
Reference in New Issue
Block a user