#159 - Dependency upgrade automation.

Add commands to check for dependency upgrades and to perform an upgrade for Spring Data Build.
This commit is contained in:
Mark Paluch
2020-11-13 16:26:55 +01:00
parent fd66965428
commit 055146e96c
20 changed files with 1718 additions and 27 deletions

View File

@@ -0,0 +1,82 @@
/*
* Copyright 2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.release.dependency;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assume.*;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.release.AbstractIntegrationTests;
import org.springframework.data.release.git.GitOperations;
import org.springframework.data.release.model.Iteration;
import org.springframework.data.release.model.Projects;
/**
* Integration tests for {@link DependencyOperations}.
*
* @author Mark Paluch
*/
@Disabled
class DependencyOperationsIntegrationTests extends AbstractIntegrationTests {
@Autowired GitOperations git;
@Autowired DependencyOperations operations;
@BeforeAll
static void beforeAll() {
try {
URL url = new URL("https://repo1.maven.org");
URLConnection urlConnection = url.openConnection();
urlConnection.connect();
urlConnection.getInputStream().close();
} catch (IOException e) {
assumeTrue("Test requires connectivity to Maven: " + e.toString(), false);
}
}
@Test
void shouldDiscoverDependencyVersions() {
assertThat(operations.getAvailableVersions(Dependencies.PROJECT_REACTOR)).isNotEmpty();
}
@Test
void shouldReportExistingDependencyVersions() {
assertThat(operations.getCurrentDependencies(Projects.BUILD)).isNotEmpty();
}
@Test
void shouldReportExistingOptionalDependencies() {
// git.checkout(ReleaseTrains.MOORE);
assertThat(operations.getCurrentDependencies(Projects.CASSANDRA)).hasSize(1);
assertThat(operations.getCurrentDependencies(Projects.MONGO_DB)).hasSize(1);
assertThat(operations.getCurrentDependencies(Projects.NEO4J)).hasSize(1);
}
@Test
void getUpgradeProposals() {
System.out.println(operations.getDependencyUpgradeProposals(Projects.BUILD, Iteration.M1));
}
}

View File

@@ -0,0 +1,132 @@
/*
* Copyright 2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.release.dependency;
import static org.assertj.core.api.Assertions.*;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import org.springframework.data.release.model.Iteration;
/**
* Unit tests for {@link DependencyOperations}.
*
* @author Mark Paluch
*/
class DependencyOperationsUnitTests {
@Test
void shouldRetainCurrentVersion() {
List<DependencyVersion> availableVersions = Stream.of("5.7.0", "5.7.0-M1") //
.map(DependencyVersion::of) //
.sorted() //
.collect(Collectors.toList());
DependencyUpgradeProposal proposal = DependencyOperations.getDependencyUpgradeProposal(Iteration.SR1,
DependencyVersion.of("5.7.0"), availableVersions);
assertThat(proposal.getCurrent()).isEqualTo(DependencyVersion.of("5.7.0"));
assertThat(proposal.getLatestMinor()).isEqualTo(DependencyVersion.of("5.7.0"));
assertThat(proposal.getProposal()).isEqualTo(DependencyVersion.of("5.7.0"));
assertThat(proposal.getLatest()).isEqualTo(DependencyVersion.of("5.7.0"));
}
@Test
void shouldSelectNextMinorVersion() {
List<DependencyVersion> availableVersions = Stream.of("5.7.0", "5.7.1", "5.8.0") //
.map(DependencyVersion::of) //
.sorted() //
.collect(Collectors.toList());
DependencyUpgradeProposal proposal = DependencyOperations.getDependencyUpgradeProposal(Iteration.SR1,
DependencyVersion.of("5.7.0"), availableVersions);
assertThat(proposal.getCurrent()).isEqualTo(DependencyVersion.of("5.7.0"));
assertThat(proposal.getLatestMinor()).isEqualTo(DependencyVersion.of("5.7.1"));
assertThat(proposal.getProposal()).isEqualTo(DependencyVersion.of("5.7.1"));
assertThat(proposal.getLatest()).isEqualTo(DependencyVersion.of("5.8.0"));
}
@Test
void shouldSelectLatestVersion() {
List<DependencyVersion> availableVersions = Stream.of("5.7.0", "5.7.1", "5.8.0") //
.map(DependencyVersion::of) //
.sorted() //
.collect(Collectors.toList());
DependencyUpgradeProposal proposal = DependencyOperations.getDependencyUpgradeProposal(Iteration.M1,
DependencyVersion.of("5.7.0"), availableVersions);
assertThat(proposal.getCurrent()).isEqualTo(DependencyVersion.of("5.7.0"));
assertThat(proposal.getLatestMinor()).isEqualTo(DependencyVersion.of("5.7.1"));
assertThat(proposal.getProposal()).isEqualTo(DependencyVersion.of("5.8.0"));
assertThat(proposal.getLatest()).isEqualTo(DependencyVersion.of("5.8.0"));
}
@Test
void shouldReportNewerVersions() {
List<DependencyVersion> availableVersions = Stream.of("5.7.0", "5.7.1", "5.7.2-M2", "5.7.2", "5.8.0") //
.map(DependencyVersion::of) //
.sorted() //
.collect(Collectors.toList());
DependencyUpgradeProposal proposal = DependencyOperations.getDependencyUpgradeProposal(Iteration.SR1,
DependencyVersion.of("5.7.1"), availableVersions);
assertThat(proposal.getNewerVersions()).extracting(DependencyVersion::getIdentifier).containsExactly("5.7.2-M2",
"5.7.2", "5.8.0");
}
@Test
void shouldReportMilestoneVersionForMilestoneIteration() {
List<DependencyVersion> availableVersions = Stream.of("5.7.0", "5.7.1", "5.7.2-M2") //
.map(DependencyVersion::of) //
.sorted() //
.collect(Collectors.toList());
DependencyUpgradeProposal proposal = DependencyOperations.getDependencyUpgradeProposal(Iteration.M1,
DependencyVersion.of("5.7.1"), availableVersions);
assertThat(proposal.getLatest()).extracting(DependencyVersion::getIdentifier).isEqualTo("5.7.2-M2");
assertThat(proposal.getProposal()).extracting(DependencyVersion::getIdentifier).isEqualTo("5.7.2-M2");
assertThat(proposal.getNewerVersions()).extracting(DependencyVersion::getIdentifier).containsExactly("5.7.2-M2");
}
@Test
void shouldSkipMilestoneVersionForNonMilestoneIteration() {
List<DependencyVersion> availableVersions = Stream.of("5.7.0", "5.7.1", "5.7.2-M2") //
.map(DependencyVersion::of) //
.sorted() //
.collect(Collectors.toList());
DependencyUpgradeProposal proposal = DependencyOperations.getDependencyUpgradeProposal(Iteration.RC1,
DependencyVersion.of("5.7.1"), availableVersions);
assertThat(proposal.getLatest()).extracting(DependencyVersion::getIdentifier).isEqualTo("5.7.1");
assertThat(proposal.getProposal()).extracting(DependencyVersion::getIdentifier).isEqualTo("5.7.1");
assertThat(proposal.getNewerVersions()).extracting(DependencyVersion::getIdentifier).containsExactly("5.7.2-M2");
}
}

View File

@@ -0,0 +1,48 @@
/*
* Copyright 2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.release.dependency;
import static org.assertj.core.api.Assertions.*;
import java.util.Map;
import java.util.Properties;
import org.junit.jupiter.api.Test;
import org.springframework.data.release.model.Iteration;
import org.springframework.data.release.model.ReleaseTrains;
/**
* Unit tests for {@link DependencyUpgradeProposals}.
*
* @author Mark Paluch
*/
class DependencyUpgradeProposalsUnitTests {
@Test
void shouldParseDependencies() {
Properties properties = new Properties();
properties.put("dependency.train", "Pascal");
properties.put("dependency.iteration", "M1");
properties.put("dependency[org.assertj:assertj-core]", "3.18.1");
Map<Dependency, DependencyVersion> dependencies = DependencyUpgradeProposals
.fromProperties(ReleaseTrains.PASCAL.getIteration(Iteration.M1), properties);
assertThat(dependencies).hasSize(1).containsEntry(Dependencies.ASSERTJ, DependencyVersion.of("3.18.1"));
}
}

View File

@@ -0,0 +1,56 @@
/*
* Copyright 2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.release.dependency;
import static org.assertj.core.api.Assertions.*;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
/**
* Unit tests for {@link DependencyVersion}.
*
* @author Mark Paluch
*/
class DependencyVersionUnitTests {
@Test
void shouldConsiderSemVerSortOrder() {
List<String> sorted = Stream.of("1.0.0", "1.0.0-m1", "1.0.0-rc1", "1.0.0-m2") //
.map(DependencyVersion::of) //
.sorted() //
.map(DependencyVersion::getIdentifier) //
.collect(Collectors.toList());
assertThat(sorted).containsExactly("1.0.0-m1", "1.0.0-m2", "1.0.0-rc1", "1.0.0");
}
@Test
void shouldConsiderReleaseTrainSortOrder() {
List<String> sorted = Stream.of("Bismuth-SR1", "Aluminium-SR1", "Aluminium-RELEASE", "Aluminium-SR2") //
.map(DependencyVersion::of) //
.sorted() //
.map(DependencyVersion::getIdentifier) //
.collect(Collectors.toList());
assertThat(sorted).containsExactly("Aluminium-RELEASE", "Aluminium-SR1", "Aluminium-SR2", "Bismuth-SR1");
}
}

View File

@@ -56,7 +56,7 @@ class ReleaseOperationsIntegrationTests extends AbstractIntegrationTests {
List<TicketReference> ticketReferences = gitOperations.getTicketReferencesBetween(Projects.MONGO_DB, from, to);
IssueTracker tracker = trackers.getRequiredPluginFor(Projects.MONGO_DB);
Tickets tickets = tracker.resolve(to.getModule(Projects.MONGO_DB), ticketReferences);
Tickets tickets = tracker.findTickets(to.getModule(Projects.MONGO_DB), ticketReferences);
assertThat(tickets).hasSize(15);
}
@@ -70,7 +70,7 @@ class ReleaseOperationsIntegrationTests extends AbstractIntegrationTests {
List<TicketReference> ticketReferences = gitOperations.getTicketReferencesBetween(Projects.R2DBC, from, to);
IssueTracker tracker = trackers.getRequiredPluginFor(Projects.R2DBC);
Tickets tickets = tracker.resolve(to.getModule(Projects.R2DBC), ticketReferences);
Tickets tickets = tracker.findTickets(to.getModule(Projects.R2DBC), ticketReferences);
assertThat(tickets).hasSize(22);
}