Switch for updating documentation; fixes gh-102

This commit is contained in:
Marcin Grzejszczak
2018-10-16 18:07:24 +02:00
parent e407255565
commit 2156fab4e7
6 changed files with 95 additions and 30 deletions

View File

@@ -149,6 +149,11 @@ public class ReleaserProperties implements Serializable {
*/
private String documentationBranch = "gh-pages";
/**
* If {@code false}, will not update the documentation repository.
*/
private boolean updateDocumentationRepo = true;
/**
* Where should the Spring Cloud Release repo get cloned to. If {@code null} defaults to a temporary directory
*/
@@ -204,6 +209,14 @@ public class ReleaserProperties implements Serializable {
this.documentationBranch = documentationBranch;
}
public boolean isUpdateDocumentationRepo() {
return this.updateDocumentationRepo;
}
public void setUpdateDocumentationRepo(boolean updateDocumentationRepo) {
this.updateDocumentationRepo = updateDocumentationRepo;
}
public String getCloneDestinationDir() {
return this.cloneDestinationDir;
}

View File

@@ -6,6 +6,8 @@ import java.nio.file.Files;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.release.internal.ReleaserProperties;
import org.springframework.cloud.release.internal.git.ProjectGitHandler;
import org.springframework.cloud.release.internal.pom.ProjectVersion;
@@ -18,9 +20,12 @@ public class DocumentationUpdater {
private static final Logger log = LoggerFactory.getLogger(DocumentationUpdater.class);
private final ProjectGitHandler gitHandler;
private final ReleaserProperties properties;
public DocumentationUpdater(ProjectGitHandler gitHandler) {
public DocumentationUpdater(ReleaserProperties properties,
ProjectGitHandler gitHandler) {
this.gitHandler = gitHandler;
this.properties = properties;
}
/**
@@ -32,6 +37,11 @@ public class DocumentationUpdater {
* @return {@link File cloned temporary directory} - {@code null} if wrong version is used
*/
public File updateDocsRepo(ProjectVersion currentProject, String springCloudReleaseBranch) {
if (!properties.getGit().isUpdateDocumentationRepo()) {
log.info("Will not update documentation repository, since the switch to do so "
+ "is off. Set [releaser.git.update-documentation-repo] to [true] to change that");
return null;
}
if (!currentProject.isReleaseOrServiceRelease()) {
log.info("Will not update documentation repository for non release or service release [{}]", currentProject.version);
return null;

View File

@@ -31,6 +31,7 @@ public class DocumentationUpdaterTests {
File tmpFolder;
ProjectGitHandler handler;
File clonedDocProject;
ReleaserProperties properties = new ReleaserProperties();
@Before
public void setup() throws IOException, URISyntaxException {
@@ -39,7 +40,6 @@ public class DocumentationUpdaterTests {
DocumentationUpdaterTests.class.getResource("/projects/spring-cloud-static").toURI());
TestUtils.prepareLocalRepo();
FileSystemUtils.copyRecursively(file("/projects"), this.tmpFolder);
ReleaserProperties properties = new ReleaserProperties();
properties.getGit().setDocumentationUrl(file("/projects/spring-cloud-static/").toURI().toString());
this.handler = new ProjectGitHandler(properties);
this.clonedDocProject = this.handler.cloneDocumentationProject();
@@ -54,7 +54,7 @@ public class DocumentationUpdaterTests {
properties.getGit().setDocumentationUrl(file("/projects/spring-cloud-release/").toURI().toString());
BDDAssertions.thenThrownBy(() ->
new DocumentationUpdater(new ProjectGitHandler(properties))
new DocumentationUpdater(properties, new ProjectGitHandler(properties))
.updateDocsRepo(releaseTrainVersion, "vAngel.SR33"))
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining("index.html is not present");
@@ -68,7 +68,7 @@ public class DocumentationUpdaterTests {
properties.getGit().setDocumentationUrl(file("/projects/spring-cloud-static/").toURI().toString());
BDDAssertions.thenThrownBy(() ->
new DocumentationUpdater(new ProjectGitHandler(properties)) {
new DocumentationUpdater(properties, new ProjectGitHandler(properties)) {
@Override String readIndexHtmlContents(File indexHtml)
throws IOException {
return "";
@@ -83,7 +83,7 @@ public class DocumentationUpdaterTests {
ProjectVersion releaseTrainVersion = new ProjectVersion("spring-cloud-sleuth", "2.0.0.BUILD-SNAPSHOT");
ReleaserProperties properties = new ReleaserProperties();
File updatedDocs = new DocumentationUpdater(new ProjectGitHandler(properties))
File updatedDocs = new DocumentationUpdater(properties, new ProjectGitHandler(properties))
.updateDocsRepo(releaseTrainVersion, "vAngel.M7");
then(updatedDocs).isNull();
@@ -96,7 +96,7 @@ public class DocumentationUpdaterTests {
ReleaserProperties properties = new ReleaserProperties();
properties.getGit().setDocumentationUrl(file("/projects/spring-cloud-static/").toURI().toString());
File updatedDocs = new DocumentationUpdater(new ProjectGitHandler(properties))
File updatedDocs = new DocumentationUpdater(properties, new ProjectGitHandler(properties))
.updateDocsRepo(releaseTrainVersion, "vAngel.SR33");
String indexHtmlContent = new String(Files.readAllBytes(
@@ -113,7 +113,7 @@ public class DocumentationUpdaterTests {
properties.getGit().setDocumentationUrl(this.clonedDocProject.toURI().toString());
ProjectGitHandler handler = BDDMockito.spy(new ProjectGitHandler(properties));
new DocumentationUpdater(handler)
new DocumentationUpdater(properties, handler)
.updateDocsRepo(releaseTrainVersion, "vDalston.SR3");
BDDMockito.then(handler).should(BDDMockito.never())
@@ -127,7 +127,7 @@ public class DocumentationUpdaterTests {
ReleaserProperties properties = new ReleaserProperties();
properties.getGit().setDocumentationUrl(this.clonedDocProject.toURI().toString());
File updatedDocs = new DocumentationUpdater(new ProjectGitHandler(properties))
File updatedDocs = new DocumentationUpdater(properties, new ProjectGitHandler(properties))
.updateDocsRepo(releaseTrainVersion, "Angel.SR33");
String indexHtmlContent = new String(Files.readAllBytes(
@@ -143,7 +143,7 @@ public class DocumentationUpdaterTests {
ReleaserProperties properties = new ReleaserProperties();
properties.getGit().setDocumentationUrl(this.clonedDocProject.toURI().toString());
File updatedDocs = new DocumentationUpdater(new ProjectGitHandler(properties))
File updatedDocs = new DocumentationUpdater(properties, new ProjectGitHandler(properties))
.updateDocsRepo(releaseTrainVersion, "vFinchley.SR33");
String indexHtmlContent = new String(Files.readAllBytes(
@@ -159,7 +159,7 @@ public class DocumentationUpdaterTests {
ReleaserProperties properties = new ReleaserProperties();
properties.getGit().setDocumentationUrl(this.clonedDocProject.toURI().toString());
File updatedDocs = new DocumentationUpdater(new ProjectGitHandler(properties))
File updatedDocs = new DocumentationUpdater(properties, new ProjectGitHandler(properties))
.updateDocsRepo(releaseTrainVersion, "Finchley.SR33");
String indexHtmlContent = new String(Files.readAllBytes(
@@ -168,6 +168,20 @@ public class DocumentationUpdaterTests {
.contains("http://cloud.spring.io/spring-cloud-static/Finchley.SR33/");
}
@Test
public void should_not_update_current_version_in_the_docs_if_switch_is_off()
throws URISyntaxException, IOException {
ProjectVersion releaseTrainVersion = new ProjectVersion("spring-cloud-sleuth", "2.0.0.SR33");
ReleaserProperties properties = new ReleaserProperties();
properties.getGit().setDocumentationUrl(this.clonedDocProject.toURI().toString());
properties.getGit().setUpdateDocumentationRepo(false);
File updatedDocs = new DocumentationUpdater(properties, new ProjectGitHandler(properties))
.updateDocsRepo(releaseTrainVersion, "Finchley.SR33");
then(updatedDocs).isNull();
}
private File file(String relativePath) throws URISyntaxException {
return new File(DocumentationUpdaterTests.class.getResource(relativePath).toURI());
}

View File

@@ -20,15 +20,14 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.cloud.release.internal.Releaser;
import org.springframework.cloud.release.internal.ReleaserProperties;
import org.springframework.cloud.release.internal.docs.DocumentationUpdater;
import org.springframework.cloud.release.internal.git.ProjectGitHandler;
import org.springframework.cloud.release.internal.gradle.GradleUpdater;
import org.springframework.cloud.release.internal.options.Parser;
import org.springframework.cloud.release.internal.sagan.Release;
import org.springframework.cloud.release.internal.pom.ProjectPomUpdater;
import org.springframework.cloud.release.internal.project.ProjectBuilder;
import org.springframework.cloud.release.internal.sagan.SaganClient;
import org.springframework.cloud.release.internal.sagan.SaganUpdater;
import org.springframework.cloud.release.internal.template.TemplateGenerator;
import org.springframework.cloud.release.internal.project.ProjectBuilder;
import org.springframework.cloud.release.internal.git.ProjectGitHandler;
import org.springframework.cloud.release.internal.pom.ProjectPomUpdater;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -37,28 +36,52 @@ import org.springframework.context.annotation.Configuration;
@EnableConfigurationProperties(ReleaserProperties.class)
class ReleaserConfiguration {
@Autowired ReleaserProperties properties;
@Autowired
ReleaserProperties properties;
@Bean SpringReleaser springReleaser(Releaser releaser,
@Bean
SpringReleaser springReleaser(Releaser releaser,
ReleaserPropertiesUpdater updater) {
return new SpringReleaser(releaser, this.properties, updater);
}
@Bean ProjectBuilder projectBuilder() { return new ProjectBuilder(this.properties); }
@Bean
ProjectBuilder projectBuilder() {
return new ProjectBuilder(this.properties);
}
@Bean ProjectPomUpdater pomUpdater() { return new ProjectPomUpdater(this.properties); }
@Bean
ProjectPomUpdater pomUpdater() {
return new ProjectPomUpdater(this.properties);
}
@Bean ProjectGitHandler projectGitHandler() { return new ProjectGitHandler(this.properties); }
@Bean
ProjectGitHandler projectGitHandler() {
return new ProjectGitHandler(this.properties);
}
@Bean TemplateGenerator templateGenerator(ProjectGitHandler handler) { return new TemplateGenerator(this.properties, handler); }
@Bean
TemplateGenerator templateGenerator(ProjectGitHandler handler) {
return new TemplateGenerator(this.properties, handler);
}
@Bean GradleUpdater gradleUpdater() { return new GradleUpdater(this.properties); }
@Bean
GradleUpdater gradleUpdater() {
return new GradleUpdater(this.properties);
}
@Bean SaganUpdater saganUpdater(SaganClient saganClient) { return new SaganUpdater(saganClient); }
@Bean
SaganUpdater saganUpdater(SaganClient saganClient) {
return new SaganUpdater(saganClient);
}
@Bean DocumentationUpdater documentationUpdater(ProjectGitHandler handler) { return new DocumentationUpdater(handler); }
@Bean
DocumentationUpdater documentationUpdater(ReleaserProperties properties, ProjectGitHandler handler) {
return new DocumentationUpdater(properties, handler);
}
@Bean Releaser releaser(ProjectPomUpdater projectPomUpdater, ProjectBuilder projectBuilder,
@Bean
Releaser releaser(ProjectPomUpdater projectPomUpdater, ProjectBuilder projectBuilder,
ProjectGitHandler projectGitHandler, TemplateGenerator templateGenerator,
GradleUpdater gradleUpdater, SaganUpdater saganUpdater,
DocumentationUpdater documentationUpdater) {
@@ -66,11 +89,13 @@ class ReleaserConfiguration {
templateGenerator, gradleUpdater, saganUpdater, documentationUpdater);
}
@Bean ReleaserPropertiesUpdater releaserPropertiesUpdater(ApplicationContext context) {
@Bean
ReleaserPropertiesUpdater releaserPropertiesUpdater(ApplicationContext context) {
return new ReleaserPropertiesUpdater(context);
}
@Bean Parser optionsParser() {
@Bean
Parser optionsParser() {
return new OptionsParser();
}
}

View File

@@ -3,6 +3,7 @@ package org.springframework.cloud.release.internal.docs;
import java.io.File;
import java.io.IOException;
import org.springframework.cloud.release.internal.ReleaserProperties;
import org.springframework.cloud.release.internal.git.ProjectGitHandler;
/**
@@ -12,8 +13,9 @@ public class TestDocumentationUpdater extends DocumentationUpdater {
private final String version;
public TestDocumentationUpdater(ProjectGitHandler gitHandler, String version) {
super(gitHandler);
public TestDocumentationUpdater(ReleaserProperties properties,
ProjectGitHandler gitHandler, String version) {
super(properties, gitHandler);
this.version = version;
}

View File

@@ -592,7 +592,8 @@ public class AcceptanceTests {
TemplateGenerator templateGenerator = new TemplateGenerator(properties, handler);
GradleUpdater gradleUpdater = new GradleUpdater(properties);
SaganUpdater saganUpdater = new SaganUpdater(this.saganClient);
DocumentationUpdater documentationUpdater = new TestDocumentationUpdater(handler, "Brixton.SR1") {
DocumentationUpdater documentationUpdater = new TestDocumentationUpdater(properties,
handler, "Brixton.SR1") {
@Override public File updateDocsRepo(ProjectVersion currentProject,
String springCloudReleaseBranch) {
File file = super.updateDocsRepo(currentProject, springCloudReleaseBranch);
@@ -613,7 +614,7 @@ public class AcceptanceTests {
TemplateGenerator templateGenerator = Mockito.spy(new TemplateGenerator(properties, handler));
GradleUpdater gradleUpdater = new GradleUpdater(properties);
SaganUpdater saganUpdater = Mockito.spy(new SaganUpdater(this.saganClient));
DocumentationUpdater documentationUpdater = Mockito.spy(new DocumentationUpdater(handler) {
DocumentationUpdater documentationUpdater = Mockito.spy(new DocumentationUpdater(properties, handler) {
@Override public File updateDocsRepo(ProjectVersion currentProject,
String springCloudReleaseBranch) {
File file = super.updateDocsRepo(currentProject, springCloudReleaseBranch);