From 206621203d50a6db4ad77c2c3816ff12ca3b6a31 Mon Sep 17 00:00:00 2001 From: Chris Bono Date: Mon, 15 Jan 2024 21:42:55 -0600 Subject: [PATCH] [CI] Include `version.samples` property update in release workflow --- .../versions/UpdateProjectVersionTask.java | 22 ++++++++++--------- .../versions/UpdateToReleaseVersionTask.java | 6 ++--- .../versions/UpdateToSnapshotVersionTask.java | 8 ++++--- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/buildSrc/src/main/java/org/springframework/pulsar/gradle/versions/UpdateProjectVersionTask.java b/buildSrc/src/main/java/org/springframework/pulsar/gradle/versions/UpdateProjectVersionTask.java index 9b65f4d0..5baa20f6 100644 --- a/buildSrc/src/main/java/org/springframework/pulsar/gradle/versions/UpdateProjectVersionTask.java +++ b/buildSrc/src/main/java/org/springframework/pulsar/gradle/versions/UpdateProjectVersionTask.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 the original author or authors. + * 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. @@ -31,22 +31,24 @@ public abstract class UpdateProjectVersionTask extends DefaultTask { static final String VERSION_PROPERTY = "version"; - static final String SPRING_BOOT_VERSION_PROPERTY = "spring-boot-for-docs"; + static final String VERSION_FOR_SAMPLES_PROPERTY = "version.samples"; + + 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)?$"); - protected void updateVersionInGradleProperties(String newVersion) { - this.updatePropertyInFile(Project.GRADLE_PROPERTIES, VERSION_PROPERTY, - (p) -> p.getVersion().toString(), - (__) -> newVersion, - (currentValue) -> "%s=%s".formatted(VERSION_PROPERTY, currentValue), - (__) -> "%s=%s".formatted(VERSION_PROPERTY, newVersion)); + protected void updateVersionInGradleProperties(String versionPropertyName, String newVersion) { + this.updatePropertyInFile(Project.GRADLE_PROPERTIES, versionPropertyName, + (p) -> p.property(versionPropertyName).toString(), + (currentValue) -> newVersion, + (currentValue) -> "%s=%s".formatted(versionPropertyName, currentValue), + (newValue) -> "%s=%s".formatted(versionPropertyName, newValue)); } protected void updateVersionInTomlVersions(String versionPropertyName, Function newPropertyValueGivenCurrentValue) { this.updatePropertyInFile("gradle/libs.versions.toml", versionPropertyName, - (p) -> currentVersionForProperty(p, versionPropertyName), + (p) -> currentVersionInCatalog(p, versionPropertyName), newPropertyValueGivenCurrentValue, (currentValue) -> "%s = \"%s\"".formatted(versionPropertyName, currentValue), (newValue) -> "%s = \"%s\"".formatted(versionPropertyName, newValue)); @@ -85,7 +87,7 @@ public abstract class UpdateProjectVersionTask extends DefaultTask { } } - protected String currentVersionForProperty(Project project, String versionProperty) { + protected String currentVersionInCatalog(Project project, String versionProperty) { VersionCatalogsExtension catalog = project.getExtensions().getByType(VersionCatalogsExtension.class); return catalog.named("libs").findVersion(versionProperty) .orElseThrow(() -> new IllegalStateException("% property not found".formatted(versionProperty))) diff --git a/buildSrc/src/main/java/org/springframework/pulsar/gradle/versions/UpdateToReleaseVersionTask.java b/buildSrc/src/main/java/org/springframework/pulsar/gradle/versions/UpdateToReleaseVersionTask.java index 0395b5ac..9c4d934f 100644 --- a/buildSrc/src/main/java/org/springframework/pulsar/gradle/versions/UpdateToReleaseVersionTask.java +++ b/buildSrc/src/main/java/org/springframework/pulsar/gradle/versions/UpdateToReleaseVersionTask.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2023 the original author or authors. + * 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. @@ -26,8 +26,8 @@ public abstract class UpdateToReleaseVersionTask extends UpdateProjectVersionTas @TaskAction public void updateToReleaseVersion() { - updateVersionInGradleProperties(this.releaseVersion); - updateVersionInTomlVersions(SPRING_BOOT_VERSION_PROPERTY, this::calculateReleaseBootVersion); + updateVersionInGradleProperties(VERSION_PROPERTY, this.releaseVersion); + updateVersionInTomlVersions(SPRING_BOOT_VERSION_FOR_DOCS_PROPERTY, this::calculateReleaseBootVersion); } public String getReleaseVersion() { diff --git a/buildSrc/src/main/java/org/springframework/pulsar/gradle/versions/UpdateToSnapshotVersionTask.java b/buildSrc/src/main/java/org/springframework/pulsar/gradle/versions/UpdateToSnapshotVersionTask.java index 2557f510..30b11257 100644 --- a/buildSrc/src/main/java/org/springframework/pulsar/gradle/versions/UpdateToSnapshotVersionTask.java +++ b/buildSrc/src/main/java/org/springframework/pulsar/gradle/versions/UpdateToSnapshotVersionTask.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2023 the original author or authors. + * 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. @@ -23,8 +23,10 @@ public abstract class UpdateToSnapshotVersionTask extends UpdateProjectVersionTa @TaskAction public void updateToSnapshotVersion() { String currentVersion = getProject().getVersion().toString(); - updateVersionInGradleProperties(calculateNextSnapshotVersion(currentVersion)); - updateVersionInTomlVersions(SPRING_BOOT_VERSION_PROPERTY, this::calculateNextSnapshotVersion); + String nextSnapshotVersion = calculateNextSnapshotVersion(currentVersion); + updateVersionInGradleProperties(VERSION_PROPERTY, nextSnapshotVersion); + updateVersionInGradleProperties(VERSION_FOR_SAMPLES_PROPERTY, nextSnapshotVersion); + updateVersionInTomlVersions(SPRING_BOOT_VERSION_FOR_DOCS_PROPERTY, this::calculateNextSnapshotVersion); } private String calculateNextSnapshotVersion(String version) {