Switch for updating documentation; fixes gh-102
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user