Skip to content

Commit 11be960

Browse files
committed
[CI] Add task to update next boot snapshot version [skip ci]
1 parent 8933250 commit 11be960

File tree

4 files changed

+71
-4
lines changed

4 files changed

+71
-4
lines changed

buildSrc/src/main/java/org/springframework/pulsar/gradle/versions/UpdateProjectVersionPlugin.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,24 @@ public class UpdateProjectVersionPlugin implements Plugin<Project> {
2424
public void apply(Project project) {
2525
project.getTasks().register("updateToReleaseVersion", UpdateToReleaseVersionTask.class, updateToReleaseVersionTask -> {
2626
updateToReleaseVersionTask.setGroup("Release");
27-
updateToReleaseVersionTask.setDescription("Updates the project version to the next release in gradle.properties");
27+
updateToReleaseVersionTask.setDescription("""
28+
Updates the project version to the release version in gradle.properties and
29+
the boot version used by docs to the upcoming boot release version in libs.versions.toml.""");
2830
updateToReleaseVersionTask.setReleaseVersion((String) project.findProperty("releaseVersion"));
2931
});
3032
project.getTasks().register("updateToSnapshotVersion", UpdateToSnapshotVersionTask.class, updateToSnapshotVersionTask -> {
3133
updateToSnapshotVersionTask.setGroup("Release");
32-
updateToSnapshotVersionTask.setDescription("Updates the project version to the next snapshot in gradle.properties");
34+
updateToSnapshotVersionTask.setDescription("""
35+
Updates the project version to the next snapshot version and the project version
36+
used by samples to the current released version in gradle.properties.""");
3337
});
38+
project.getTasks().register("updateToNextBootSnapshotVersion", UpdateToNextBootSnapshotVersionTask.class, updateToNextBootSnapshotVersionTask -> {
39+
updateToNextBootSnapshotVersionTask.setGroup("Release");
40+
updateToNextBootSnapshotVersionTask.setDescription("""
41+
Updates the project version used by samples to the current project version in
42+
gradle.properties and boot version used by docs and samples to the next boot
43+
snapshot version in libs.versions.toml.""");
44+
});
45+
3446
}
3547
}

buildSrc/src/main/java/org/springframework/pulsar/gradle/versions/UpdateProjectVersionTask.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public abstract class UpdateProjectVersionTask extends DefaultTask {
3333

3434
static final String VERSION_FOR_SAMPLES_PROPERTY = "version.samples";
3535

36+
static final String SPRING_BOOT_VERSION_FOR_SAMPLES_PROPERTY = "spring-boot";
37+
3638
static final String SPRING_BOOT_VERSION_FOR_DOCS_PROPERTY = "spring-boot-for-docs";
3739

3840
static final Pattern VERSION_PATTERN = Pattern.compile("^([0-9]+)\\.([0-9]+)\\.([0-9]+)(-M\\d+|-RC\\d+|-SNAPSHOT)?$");
@@ -54,6 +56,17 @@ protected void updateVersionInTomlVersions(String versionPropertyName,
5456
(newValue) -> "%s = \"%s\"".formatted(versionPropertyName, newValue));
5557
}
5658

59+
protected void updateVersionInTomlVersions(String versionPropertyName, String sourcePropertyName,
60+
Function<String, String> newPropertyValueGivenCurrentValue) {
61+
var currentVersionPropertyValue = currentVersionInCatalog(getProject(), versionPropertyName);
62+
var currentSourcePropertyValue = currentVersionInCatalog(getProject(), sourcePropertyName);
63+
this.updatePropertyInFile("gradle/libs.versions.toml", versionPropertyName,
64+
(__) -> currentSourcePropertyValue,
65+
newPropertyValueGivenCurrentValue,
66+
(__) -> "%s = \"%s\"".formatted(versionPropertyName, currentVersionPropertyValue),
67+
(newValue) -> "%s = \"%s\"".formatted(versionPropertyName, newValue));
68+
}
69+
5770
protected void updatePropertyInFile(String propertyFile, String propertyName,
5871
Function<Project, String> currentPropertyValueGivenProject,
5972
Function<String, String> newPropertyValueGivenCurrentValue,
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2019-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.pulsar.gradle.versions;
18+
19+
import org.gradle.api.tasks.TaskAction;
20+
21+
public abstract class UpdateToNextBootSnapshotVersionTask extends UpdateProjectVersionTask {
22+
23+
@TaskAction
24+
public void updateToBootSnapshotVersion() {
25+
String currentVersion = getProject().getVersion().toString();
26+
updateVersionInGradleProperties(VERSION_FOR_SAMPLES_PROPERTY, currentVersion);
27+
updateVersionInTomlVersions(SPRING_BOOT_VERSION_FOR_DOCS_PROPERTY, this::calculateNextSnapshotVersion);
28+
updateVersionInTomlVersions(SPRING_BOOT_VERSION_FOR_SAMPLES_PROPERTY, SPRING_BOOT_VERSION_FOR_DOCS_PROPERTY, this::calculateNextSnapshotVersion);
29+
}
30+
31+
private String calculateNextSnapshotVersion(String version) {
32+
VersionInfo versionSegments = parseVersion(version);
33+
String majorSegment = versionSegments.major();
34+
String minorSegment = versionSegments.minor();
35+
String patchSegment = versionSegments.patch();
36+
String modifier = versionSegments.modifier();
37+
if (modifier == null) {
38+
patchSegment = String.valueOf(Integer.parseInt(patchSegment) + 1);
39+
}
40+
return "%s.%s.%s-SNAPSHOT".formatted(majorSegment, minorSegment, patchSegment);
41+
}
42+
43+
}

buildSrc/src/main/java/org/springframework/pulsar/gradle/versions/UpdateToSnapshotVersionTask.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ public void updateToSnapshotVersion() {
2525
String currentVersion = getProject().getVersion().toString();
2626
String nextSnapshotVersion = calculateNextSnapshotVersion(currentVersion);
2727
updateVersionInGradleProperties(VERSION_PROPERTY, nextSnapshotVersion);
28-
updateVersionInGradleProperties(VERSION_FOR_SAMPLES_PROPERTY, nextSnapshotVersion);
29-
updateVersionInTomlVersions(SPRING_BOOT_VERSION_FOR_DOCS_PROPERTY, this::calculateNextSnapshotVersion);
28+
updateVersionInGradleProperties(VERSION_FOR_SAMPLES_PROPERTY, currentVersion);
3029
}
3130

3231
private String calculateNextSnapshotVersion(String version) {

0 commit comments

Comments
 (0)