Fix blog template generator to support calver

This commit is contained in:
Ryan Baxter
2021-12-15 20:26:16 -05:00
parent 430e302aae
commit 2ebd6243a4
2 changed files with 90 additions and 3 deletions

View File

@@ -72,11 +72,13 @@ class BlogTemplateGenerator {
// springframework/cloud/spring-cloud-dependencies/Dalston.RELEASE/)
// - [Spring Milestone](https://repo.spring.io/milestone/) repository
// releaseVersion '- Dalston.RELEASE
boolean release = this.releaseVersion.contains("RELEASE");
boolean release = !SR_PATTERN.matcher(this.releaseVersion).matches()
&& !RC_PATTERN.matcher(this.releaseVersion).matches()
&& !MILESTONE_PATTERN.matcher(this.releaseVersion).matches();
boolean nonRelease = !(release
|| SR_PATTERN.matcher(this.releaseVersion).matches());
String availability = availability(release);
String releaseName = parsedReleaseName(this.releaseVersion);
String releaseName = parsedReleaseName(this.releaseVersion, release);
String releaseLink = link(nonRelease);
Map<String, Object> map = ImmutableMap.<String, Object>builder()
.put("availability", availability).put("releaseName", releaseName)
@@ -94,7 +96,16 @@ class BlogTemplateGenerator {
}
}
private String parsedReleaseName(String version) {
private String parsedReleaseName(String version, boolean release) {
if (version.split("\\.").length > 2) {
// Calver
if (release) {
return version;
}
else {
return version.substring(0, version.lastIndexOf("-"));
}
}
return version.substring(0, version.indexOf("."));
}

View File

@@ -150,6 +150,30 @@ public class TemplateGeneratorTests {
"mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.RELEASE'");
}
@Test
public void should_generate_blog_from_template_for_tag_without_v_prefix_release_using_calver()
throws IOException {
this.props.getPom().setBranch("2020.0.5");
Projects projects = new Projects(new HashSet<ProjectVersion>() {
{
add(new ProjectVersion("spring-cloud-sleuth", "1.0.0"));
add(new ProjectVersion("spring-cloud-consul", "1.0.1"));
}
});
File generatedBlog = new TemplateGenerator(this.props, this.handler)
.blog(projects);
then(content(generatedBlog))
.contains("General Availability (RELEASE) of the [Spring Cloud 2020.0.5]")
.contains("The release can be found in [Maven Central]")
.contains("### Spring Cloud Sleuth")
.contains(
"| Spring Cloud Sleuth | 1.0.0 | ([issues](https://foo.bar.com))")
.contains("<version>2020.0.5</version>").contains(
"mavenBom 'org.springframework.cloud:spring-cloud-dependencies:2020.0.5'");
}
@Test
public void should_generate_sr_blog_from_template_for_tag_with_v_prefix_release()
throws IOException {
@@ -250,6 +274,32 @@ public class TemplateGeneratorTests {
"mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.M1'");
}
@Test
public void should_generate_milestone_blog_from_template_for_tag_without_v_prefix_release_calver()
throws IOException {
this.props.getPom().setBranch("2020.0.0-M1");
Projects projects = new Projects(new HashSet<ProjectVersion>() {
{
add(new ProjectVersion("spring-cloud-sleuth", "1.0.0-M1"));
add(new ProjectVersion("spring-cloud-consul", "1.0.1-M1"));
}
});
File generatedBlog = new TemplateGenerator(this.props, this.handler)
.blog(projects);
then(content(generatedBlog))
.contains("Milestone 1 (M1) of the [Spring Cloud 2020.0.0]")
.contains("The release can be found in [Spring Milestone]")
.contains("### Spring Cloud Sleuth")
.contains(
"| Spring Cloud Sleuth | 1.0.0-M1 | ([issues](https://foo.bar.com))")
.contains("<id>spring-milestones</id>")
.contains("url 'https://repo.spring.io/milestone'")
.contains("<version>2020.0.0-M1</version>").contains(
"mavenBom 'org.springframework.cloud:spring-cloud-dependencies:2020.0.0-M1'");
}
@Test
public void should_generate_rc_blog_from_template_for_tag_with_v_prefix_release()
throws IOException {
@@ -302,6 +352,32 @@ public class TemplateGeneratorTests {
"mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.RC1'");
}
@Test
public void should_generate_rc_blog_from_template_for_tag_without_v_prefix_release_calver()
throws IOException {
this.props.getPom().setBranch("2020.0.0-RC1");
Projects projects = new Projects(new HashSet<ProjectVersion>() {
{
add(new ProjectVersion("spring-cloud-sleuth", "1.0.0-RC1"));
add(new ProjectVersion("spring-cloud-consul", "1.0.1-RC1"));
}
});
File generatedBlog = new TemplateGenerator(this.props, this.handler)
.blog(projects);
then(content(generatedBlog))
.contains("Release Candidate 1 (RC1) of the [Spring Cloud 2020.0.0]")
.contains("The release can be found in [Spring Milestone]")
.contains("### Spring Cloud Sleuth")
.contains(
"| Spring Cloud Sleuth | 1.0.0-RC1 | ([issues](https://foo.bar.com))")
.contains("<id>spring-milestones</id>")
.contains("url 'https://repo.spring.io/milestone'")
.contains("<version>2020.0.0-RC1</version>").contains(
"mavenBom 'org.springframework.cloud:spring-cloud-dependencies:2020.0.0-RC1'");
}
@Test
public void should_generate_release_notes_template_when_url_exists()
throws IOException {