Bump snapshot version in Segan after a RELEASE; fixes #57

This commit is contained in:
Marcin Grzejszczak
2017-11-22 14:11:35 +01:00
parent e16a4eb823
commit df3ea5744d
6 changed files with 55 additions and 3 deletions

View File

@@ -10,6 +10,7 @@ import org.springframework.cloud.release.internal.ReleaserProperties;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
@@ -38,6 +39,14 @@ class RestTemplateSaganClient implements SaganClient {
return this.restTemplate.getForObject(this.baseUrl + "/project_metadata/{projectName}/releases/{releaseVersion}", Release.class, projectName, releaseVersion);
}
@Override public Release deleteRelease(String projectName, String releaseVersion) {
ResponseEntity<Release> entity = this.restTemplate.exchange(this.baseUrl + "/project_metadata/{projectName}/releases/{releaseVersion}",
HttpMethod.DELETE, new HttpEntity<>(""), Release.class, projectName, releaseVersion);
Release release = entity.getBody();
log.info("Response from Sagan\n\n[{}] \n with body [{}]", entity, release);
return release;
}
@Override
public Project updateRelease(String projectName, List<ReleaseUpdate> releaseUpdates) {
RequestEntity<List<ReleaseUpdate>> request = RequestEntity

View File

@@ -10,5 +10,7 @@ public interface SaganClient {
Release getRelease(String projectName, String releaseVersion);
Release deleteRelease(String projectName, String releaseVersion);
Project updateRelease(String projectName, List<ReleaseUpdate> releaseUpdate);
}

View File

@@ -20,6 +20,24 @@ public class SaganUpdater {
}
public void updateSagan(String branch, ProjectVersion originalVersion, ProjectVersion version) {
ReleaseUpdate update = releaseUpdate(branch, originalVersion, version);
log.info("Updating Sagan with \n\n{}", update);
this.saganClient.updateRelease(version.projectName, Collections.singletonList(update));
if (version.isRelease() || version.isServiceRelease()) {
log.info("Version is GA [{}]. Will remove old snapshot and add a new one", version);
String snapshot = toSnapshot(version.version);
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);
this.saganClient.updateRelease(version.projectName, Collections.singletonList(snapshotUpdate));
}
}
private ReleaseUpdate releaseUpdate(String branch, ProjectVersion originalVersion,
ProjectVersion version) {
ReleaseUpdate update = new ReleaseUpdate();
update.groupId = originalVersion.groupId();
update.artifactId = version.projectName;
@@ -27,8 +45,16 @@ public class SaganUpdater {
update.releaseStatus = version(version);
update.apiDocUrl = referenceUrl(branch, version);
update.refDocUrl = referenceUrl(branch, version);
log.info("Updating Sagan with \n\n{}", update);
this.saganClient.updateRelease(version.projectName, Collections.singletonList(update));
return update;
}
private String toSnapshot(String version) {
if (version.contains("RELEASE")) {
return version.replace("RELEASE", "BUILD-SNAPSHOT");
} else if (version.matches(".*SR[0-9]+")) {
return version.substring(0, version.lastIndexOf(".")) + ".BUILD-SNAPSHOT";
}
return version;
}
private String version(ProjectVersion version) {

View File

@@ -92,6 +92,14 @@ public class RestTemplateSaganClientTests {
then(release.snapshot).isFalse();
}
@Test
public void should_delete_a_release() {
Release release = this.client.deleteRelease("spring-framework", "5.0.0.RC4");
then(release).isNotNull();
then(release.releaseStatus).isEqualTo("PRERELEASE");
}
@Test
public void should_update_a_release() {
Repository snapshots = snapshots();

View File

@@ -59,6 +59,10 @@ public class SaganUpdaterTest {
BDDMockito.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"),
BDDMockito.argThat(withReleaseUpdate("1.0.1.BUILD-SNAPSHOT",
"http://cloud.spring.io/foo/foo.html", "SNAPSHOT")));
}
@Test public void should_update_sagan_from_non_master() throws Exception {

View File

@@ -98,8 +98,11 @@ public class AcceptanceTests {
.contains("Camden.SR5")
.contains("- Spring Cloud Config `1.2.2.RELEASE` ([issues](http://foo.bar.com/1.2.2.RELEASE))")
.contains("- Spring Cloud Aws `1.1.3.RELEASE` ([issues](http://foo.bar.com/1.1.3.RELEASE))");
BDDMockito.then(this.saganClient).should().updateRelease(BDDMockito.eq("spring-cloud-consul"),
// once for updating GA
// second time to update SNAPSHOT
BDDMockito.then(this.saganClient).should(BDDMockito.times(2)).updateRelease(BDDMockito.eq("spring-cloud-consul"),
BDDMockito.anyList());
BDDMockito.then(this.saganClient).should().deleteRelease("spring-cloud-consul", "1.1.2.BUILD-SNAPSHOT");
}
@Test