Skip to content

Commit

Permalink
Add release version to setCompatibleVersions task (elastic#111489)
Browse files Browse the repository at this point in the history
The release version is used to determine if it actually needs to update the CCS version or not
  • Loading branch information
thecoop authored Aug 1, 2024
1 parent 4034615 commit 1329dc3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void apply(Project project) {

project.getTasks().register("extractCurrentVersions", ExtractCurrentVersionsTask.class);
project.getTasks().register("tagVersions", TagVersionsTask.class);
project.getTasks().register("setCompatibleVersions", SetCompatibleVersionsTask.class);
project.getTasks().register("setCompatibleVersions", SetCompatibleVersionsTask.class, t -> t.setThisVersion(version));

final FileTree yamlFiles = projectDirectory.dir("docs/changelog")
.getAsFileTree()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.github.javaparser.ast.expr.NameExpr;
import com.github.javaparser.printer.lexicalpreservation.LexicalPreservingPrinter;

import org.elasticsearch.gradle.Version;
import org.gradle.api.tasks.TaskAction;
import org.gradle.api.tasks.options.Option;
import org.gradle.initialization.layout.BuildLayout;
Expand All @@ -28,28 +29,44 @@

public class SetCompatibleVersionsTask extends AbstractVersionsTask {

private Version thisVersion;
private Version releaseVersion;
private Map<String, Integer> versionIds = Map.of();

@Inject
public SetCompatibleVersionsTask(BuildLayout layout) {
super(layout);
}

public void setThisVersion(Version version) {
thisVersion = version;
}

@Option(option = "version-id", description = "Version id used for the release. Of the form <VersionType>:<id>.")
public void versionIds(List<String> version) {
this.versionIds = splitVersionIds(version);
}

@Option(option = "release", description = "The version being released")
public void releaseVersion(String version) {
releaseVersion = Version.fromString(version);
}

@TaskAction
public void executeTask() throws IOException {
if (versionIds.isEmpty()) {
throw new IllegalArgumentException("No version ids specified");
}

if (releaseVersion.getMajor() < thisVersion.getMajor()) {
// don't need to update CCS version - this is for a different major
return;
}

Integer transportVersion = versionIds.get(TRANSPORT_VERSION_TYPE);
if (transportVersion == null) {
throw new IllegalArgumentException("TransportVersion id not specified");
}

Path versionJava = rootDir.resolve(TRANSPORT_VERSIONS_FILE_PATH);
CompilationUnit file = LexicalPreservingPrinter.setup(StaticJavaParser.parse(versionJava));

Expand Down

0 comments on commit 1329dc3

Please sign in to comment.