Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -513,4 +513,19 @@ class TransportVersionGenerationFuncTest extends AbstractTransportVersionFuncTes
assertGenerateAndValidateSuccess(result)
assertUpperBound("9.2", "existing_92,8123000")
}

def "generation cannot run on release branch"() {
given:
file("myserver/build.gradle") << """
tasks.named('generateTransportVersion') {
currentUpperBoundName = '9.1'
}
"""

when:
def result = runGenerateTask().buildAndFail()

then:
assertGenerateFailure(result, "Transport version generation cannot run on release branches")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ public abstract class GenerateTransportVersionDefinitionTask extends DefaultTask
@TaskAction
public void run() throws IOException {
TransportVersionResourcesService resources = getResourceService().get();
List<TransportVersionUpperBound> upstreamUpperBounds = resources.getUpperBoundsFromGitBase();
boolean onReleaseBranch = resources.checkIfDefinitelyOnReleaseBranch(upstreamUpperBounds, getCurrentUpperBoundName().get());
if (onReleaseBranch) {
throw new IllegalArgumentException("Transport version generation cannot run on release branches");
}

Set<String> referencedNames = TransportVersionReference.collectNames(getReferencesFiles());
Set<String> changedDefinitionNames = resources.getChangedReferableDefinitionNames();
String targetDefinitionName = getTargetDefinitionName(resources, referencedNames, changedDefinitionNames);
Expand All @@ -109,7 +115,7 @@ public void run() throws IOException {
resetAllUpperBounds(resources, idsByBase);
} else {
getLogger().lifecycle("Generating transport version name: " + targetDefinitionName);
List<TransportVersionUpperBound> upstreamUpperBounds = resources.getUpperBoundsFromGitBase();

Set<String> targetUpperBoundNames = getTargetUpperBoundNames(resources, upstreamUpperBounds, targetDefinitionName);

List<TransportVersionId> ids = updateUpperBounds(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
Expand Down Expand Up @@ -259,6 +260,20 @@ private Path getUpperBoundRelativePath(String name) {
return UPPER_BOUNDS_DIR.resolve(name + ".csv");
}

boolean checkIfDefinitelyOnReleaseBranch(Collection<TransportVersionUpperBound> upperBounds, String currentUpperBoundName) {
// only want to look at definitions <= the current upper bound.
// TODO: we should filter all of the upper bounds/definitions that are validated by this, not just in this method
TransportVersionUpperBound currentUpperBound = upperBounds.stream()
.filter(u -> u.name().equals(currentUpperBoundName))
.findFirst()
.orElse(null);
if (currentUpperBound == null) {
// since there is no current upper bound, we don't know if we are on a release branch
return false;
}
return upperBounds.stream().anyMatch(u -> u.definitionId().complete() > currentUpperBound.definitionId().complete());
}

private String getBaseRefName() {
if (baseRefName.get() == null) {
synchronized (baseRefName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void validateTransportVersions() throws IOException {
Map<Integer, List<IdAndDefinition>> idsByBase = resources.getIdsByBase();
Map<String, TransportVersionUpperBound> upperBounds = resources.getUpperBounds();
TransportVersionUpperBound currentUpperBound = upperBounds.get(getCurrentUpperBoundName().get());
boolean onReleaseBranch = checkIfDefinitelyOnReleaseBranch(upperBounds);
boolean onReleaseBranch = resources.checkIfDefinitelyOnReleaseBranch(upperBounds.values(), getCurrentUpperBoundName().get());
boolean validateModifications = onReleaseBranch == false || getCI().get();

for (var definition : referableDefinitions.values()) {
Expand Down Expand Up @@ -330,15 +330,6 @@ private void validatePrimaryIds(
);
}

private boolean checkIfDefinitelyOnReleaseBranch(Map<String, TransportVersionUpperBound> upperBounds) {
// only want to look at definitions <= the current upper bound.
// TODO: we should filter all of the upper bounds/definitions that are validated by this, not just in this method
String currentUpperBoundName = getCurrentUpperBoundName().get();
TransportVersionUpperBound currentUpperBound = upperBounds.get(currentUpperBoundName);

return upperBounds.values().stream().anyMatch(u -> u.definitionId().complete() > currentUpperBound.definitionId().complete());
}

private void throwDefinitionFailure(TransportVersionDefinition definition, String message) {
Path relativePath = getResources().get().getDefinitionPath(definition);
throw new VerificationException("Transport version definition file [" + relativePath + "] " + message);
Expand Down