[CI] Add task to update next boot snapshot version
This commit is contained in:
@@ -24,12 +24,24 @@ public class UpdateProjectVersionPlugin implements Plugin<Project> {
|
||||
public void apply(Project project) {
|
||||
project.getTasks().register("updateToReleaseVersion", UpdateToReleaseVersionTask.class, updateToReleaseVersionTask -> {
|
||||
updateToReleaseVersionTask.setGroup("Release");
|
||||
updateToReleaseVersionTask.setDescription("Updates the project version to the next release in gradle.properties");
|
||||
updateToReleaseVersionTask.setDescription("""
|
||||
Updates the project version to the release version in gradle.properties and
|
||||
the boot version used by docs to the upcoming boot release version in libs.versions.toml.""");
|
||||
updateToReleaseVersionTask.setReleaseVersion((String) project.findProperty("releaseVersion"));
|
||||
});
|
||||
project.getTasks().register("updateToSnapshotVersion", UpdateToSnapshotVersionTask.class, updateToSnapshotVersionTask -> {
|
||||
updateToSnapshotVersionTask.setGroup("Release");
|
||||
updateToSnapshotVersionTask.setDescription("Updates the project version to the next snapshot in gradle.properties");
|
||||
updateToSnapshotVersionTask.setDescription("""
|
||||
Updates the project version to the next snapshot version and the project version
|
||||
used by samples to the current released version in gradle.properties.""");
|
||||
});
|
||||
project.getTasks().register("updateToNextBootSnapshotVersion", UpdateToNextBootSnapshotVersionTask.class, updateToNextBootSnapshotVersionTask -> {
|
||||
updateToNextBootSnapshotVersionTask.setGroup("Release");
|
||||
updateToNextBootSnapshotVersionTask.setDescription("""
|
||||
Updates the project version used by samples to the current project version in
|
||||
gradle.properties and boot version used by docs and samples to the next boot
|
||||
snapshot version in libs.versions.toml.""");
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,8 @@ public abstract class UpdateProjectVersionTask extends DefaultTask {
|
||||
|
||||
static final String VERSION_FOR_SAMPLES_PROPERTY = "version.samples";
|
||||
|
||||
static final String SPRING_BOOT_VERSION_FOR_SAMPLES_PROPERTY = "spring-boot";
|
||||
|
||||
static final String SPRING_BOOT_VERSION_FOR_DOCS_PROPERTY = "spring-boot-for-docs";
|
||||
|
||||
static final Pattern VERSION_PATTERN = Pattern.compile("^([0-9]+)\\.([0-9]+)\\.([0-9]+)(-M\\d+|-RC\\d+|-SNAPSHOT)?$");
|
||||
@@ -54,6 +56,17 @@ public abstract class UpdateProjectVersionTask extends DefaultTask {
|
||||
(newValue) -> "%s = \"%s\"".formatted(versionPropertyName, newValue));
|
||||
}
|
||||
|
||||
protected void updateVersionInTomlVersions(String versionPropertyName, String sourcePropertyName,
|
||||
Function<String, String> newPropertyValueGivenCurrentValue) {
|
||||
var currentVersionPropertyValue = currentVersionInCatalog(getProject(), versionPropertyName);
|
||||
var currentSourcePropertyValue = currentVersionInCatalog(getProject(), sourcePropertyName);
|
||||
this.updatePropertyInFile("gradle/libs.versions.toml", versionPropertyName,
|
||||
(__) -> currentSourcePropertyValue,
|
||||
newPropertyValueGivenCurrentValue,
|
||||
(__) -> "%s = \"%s\"".formatted(versionPropertyName, currentVersionPropertyValue),
|
||||
(newValue) -> "%s = \"%s\"".formatted(versionPropertyName, newValue));
|
||||
}
|
||||
|
||||
protected void updatePropertyInFile(String propertyFile, String propertyName,
|
||||
Function<Project, String> currentPropertyValueGivenProject,
|
||||
Function<String, String> newPropertyValueGivenCurrentValue,
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2019-2024 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
|
||||
*
|
||||
* https://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.pulsar.gradle.versions;
|
||||
|
||||
import org.gradle.api.tasks.TaskAction;
|
||||
|
||||
public abstract class UpdateToNextBootSnapshotVersionTask extends UpdateProjectVersionTask {
|
||||
|
||||
@TaskAction
|
||||
public void updateToBootSnapshotVersion() {
|
||||
String currentVersion = getProject().getVersion().toString();
|
||||
updateVersionInGradleProperties(VERSION_FOR_SAMPLES_PROPERTY, currentVersion);
|
||||
updateVersionInTomlVersions(SPRING_BOOT_VERSION_FOR_DOCS_PROPERTY, this::calculateNextSnapshotVersion);
|
||||
updateVersionInTomlVersions(SPRING_BOOT_VERSION_FOR_SAMPLES_PROPERTY, SPRING_BOOT_VERSION_FOR_DOCS_PROPERTY, this::calculateNextSnapshotVersion);
|
||||
}
|
||||
|
||||
private String calculateNextSnapshotVersion(String version) {
|
||||
VersionInfo versionSegments = parseVersion(version);
|
||||
String majorSegment = versionSegments.major();
|
||||
String minorSegment = versionSegments.minor();
|
||||
String patchSegment = versionSegments.patch();
|
||||
String modifier = versionSegments.modifier();
|
||||
if (modifier == null) {
|
||||
patchSegment = String.valueOf(Integer.parseInt(patchSegment) + 1);
|
||||
}
|
||||
return "%s.%s.%s-SNAPSHOT".formatted(majorSegment, minorSegment, patchSegment);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,8 +25,7 @@ public abstract class UpdateToSnapshotVersionTask extends UpdateProjectVersionTa
|
||||
String currentVersion = getProject().getVersion().toString();
|
||||
String nextSnapshotVersion = calculateNextSnapshotVersion(currentVersion);
|
||||
updateVersionInGradleProperties(VERSION_PROPERTY, nextSnapshotVersion);
|
||||
updateVersionInGradleProperties(VERSION_FOR_SAMPLES_PROPERTY, nextSnapshotVersion);
|
||||
updateVersionInTomlVersions(SPRING_BOOT_VERSION_FOR_DOCS_PROPERTY, this::calculateNextSnapshotVersion);
|
||||
updateVersionInGradleProperties(VERSION_FOR_SAMPLES_PROPERTY, currentVersion);
|
||||
}
|
||||
|
||||
private String calculateNextSnapshotVersion(String version) {
|
||||
|
||||
Reference in New Issue
Block a user