This is an automated email from the ASF dual-hosted git repository.

mpochatkin pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


The following commit(s) were added to refs/heads/main by this push:
     new 36a7414767 IGNITE-23443 Create Gradle task to update versions (#4628)
36a7414767 is described below

commit 36a7414767fe0362af137b859566fdb90bfdc72b
Author: Vadim Pakhnushev <[email protected]>
AuthorDate: Mon Oct 28 12:30:38 2024 +0300

    IGNITE-23443 Create Gradle task to update versions (#4628)
---
 build.gradle                                       |  7 +-
 gradle.properties                                  |  4 +
 modules/platforms/build.gradle                     | 87 ++++++++++++++++------
 modules/platforms/cpp/CMakeLists.txt               |  9 ++-
 modules/platforms/cpp/_version.txt                 |  1 +
 .../dotnet/Apache.Ignite.Tests/VersionTests.cs     |  4 +-
 modules/platforms/dotnet/version.json              | 20 ++---
 modules/platforms/python/CMakeLists.txt            |  2 +-
 modules/platforms/python/pyignite3/__init__.py     |  3 +-
 modules/platforms/python/pyignite3/_version.txt    |  1 +
 modules/platforms/python/setup.py                  | 15 +++-
 modules/rest-api/build.gradle                      |  4 +-
 .../ignite/internal/rest/api/Definition.java       |  4 +-
 13 files changed, 115 insertions(+), 46 deletions(-)

diff --git a/build.gradle b/build.gradle
index b07abe80f0..1ed0a87571 100644
--- a/build.gradle
+++ b/build.gradle
@@ -70,11 +70,16 @@ ext {
     ]
 
     product = "Apache Ignite"
+    projectVersion = project.hasProperty('projectVersion') ? 
project.property('projectVersion') : '3.0.0-SNAPSHOT'
+    def versionPattern = '\\d+\\.\\d+\\.\\d+(?:\\.(\\d+))?(?:-[0-9A-Za-z]+)?'
+    if (!projectVersion.matches(versionPattern)) {
+        throw new GradleException("Project version $projectVersion doesn't 
conform to the semver format")
+    }
 }
 
 allprojects {
     group 'org.apache.ignite'
-    version = "3.0.0-SNAPSHOT"
+    version = projectVersion
 
     tasks.withType(Jar).configureEach {
         duplicatesStrategy = DuplicatesStrategy.EXCLUDE
diff --git a/gradle.properties b/gradle.properties
index 63fa112ebb..87a6213a7e 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -27,3 +27,7 @@ org.gradle.jvmargs=-Xmx4g -Dfile.encoding=UTF-8
 
 ##Use in case when need to build odbc drivers, cpp client and/or dotnet client
 #platforms.enable=true
+
+# Project version to assign to the java projects and native platform builds.
+# After modifying this version run `./gradlew :platforms:updateVersion` to 
update files needed for C/C++, .NET and Python builds.
+projectVersion = 3.0.0-SNAPSHOT
diff --git a/modules/platforms/build.gradle b/modules/platforms/build.gradle
index 0271dbc84a..a419855c6f 100644
--- a/modules/platforms/build.gradle
+++ b/modules/platforms/build.gradle
@@ -23,6 +23,8 @@ plugins {
 
 import dev.welbyseely.CMakeBuildTask
 import dev.welbyseely.CMakeConfigureTask
+import groovy.json.JsonOutput
+import groovy.json.JsonSlurper
 import org.apache.tools.ant.taskdefs.condition.Os
 import org.gradle.crypto.checksum.Checksum
 
@@ -37,7 +39,7 @@ cmakeConfigure.enabled = false
 cmakeBuild.enabled = false
 
 def restoreTool = tasks.register('restoreTool', Exec) {
-    workingDir "$rootDir/modules/platforms/dotnet"
+    workingDir "$projectDir/dotnet"
 
     commandLine "dotnet", "tool", "restore"
 }
@@ -52,36 +54,36 @@ def docfx = tasks.register('docfx', Exec) {
 def aggregateDotnetDocs = tasks.register('aggregateDotnetDocs', Copy) {
     dependsOn docfx
 
-    from("$rootDir/modules/platforms/dotnet/docs/_site")
+    from("$projectDir/dotnet/docs/_site")
     into("$rootDir/build/docs/dotnet")
 }
 
 def doxygenCppClient = tasks.register('doxygenCppClient', Exec) {
-    workingDir "$rootDir/modules/platforms/cpp"
+    workingDir "$projectDir/cpp"
 
     commandLine "doxygen"
 }
 
 def copyNativeLibs = tasks.register('copyNativeLibs', Copy) {
     include "**/*.so"
-    from("$rootDir/modules/platforms/cpp")
+    from("$projectDir/cpp")
     into("$buildDir/classes/")
 }
 
 cmake {
-    workingFolder=file("$buildDir/cpp")
-    sourceFolder=file("$projectDir/cpp")
-    buildConfig='Release'
-    buildTarget='install'
-    getDef().CMAKE_INSTALL_PREFIX="$buildDir/install"
-    getDef().CMAKE_BUILD_TYPE='Release'
-    getDef().CMAKE_CONFIGURATION_TYPES='Release'
+    workingFolder = file("$buildDir/cpp")
+    sourceFolder = file("$projectDir/cpp")
+    buildConfig = 'Release'
+    buildTarget = 'install'
+    getDef().CMAKE_INSTALL_PREFIX = "$buildDir/install"
+    getDef().CMAKE_BUILD_TYPE = 'Release'
+    getDef().CMAKE_CONFIGURATION_TYPES = 'Release'
 }
 
 def cmakeConfigureClient = tasks.register('cmakeConfigureClient', 
CMakeConfigureTask) {
     configureFromProject() // uses everything in the cmake { ... } section.
-    getDef().ENABLE_CLIENT='ON'
-    getDef().ENABLE_ODBC='OFF'
+    getDef().ENABLE_CLIENT = 'ON'
+    getDef().ENABLE_ODBC = 'OFF'
 }
 
 def cmakeBuildClient = tasks.register('cmakeBuildClient', CMakeBuildTask) {
@@ -91,8 +93,8 @@ def cmakeBuildClient = tasks.register('cmakeBuildClient', 
CMakeBuildTask) {
 
 def cmakeConfigureOdbc = tasks.register('cmakeConfigureOdbc', 
CMakeConfigureTask) {
     configureFromProject() // uses everything in the cmake { ... } section.
-    getDef().ENABLE_CLIENT='OFF'
-    getDef().ENABLE_ODBC='ON'
+    getDef().ENABLE_CLIENT = 'OFF'
+    getDef().ENABLE_ODBC = 'ON'
 }
 
 def cmakeBuildOdbc = tasks.register('cmakeBuildOdbc', CMakeBuildTask) {
@@ -101,7 +103,7 @@ def cmakeBuildOdbc = tasks.register('cmakeBuildOdbc', 
CMakeBuildTask) {
 }
 
 def buildNuGet = tasks.register('buildNuGet', Exec) {
-    workingDir "$rootDir/modules/platforms/dotnet"
+    workingDir "$projectDir/dotnet"
 
     commandLine "dotnet", "pack", "Apache.Ignite",
             "--configuration", "Release",
@@ -111,7 +113,7 @@ def buildNuGet = tasks.register('buildNuGet', Exec) {
 }
 
 def buildDotNet = tasks.register('buildDotNet', Exec) {
-    workingDir "$rootDir/modules/platforms/dotnet"
+    workingDir "$projectDir/dotnet"
 
     commandLine "dotnet", "build", "Apache.Ignite",
             "--configuration", "Release",
@@ -122,7 +124,7 @@ def buildDotNet = tasks.register('buildDotNet', Exec) {
 task zipNuGet(type: Zip) {
     archiveFileName = "apache-ignite-${project.version}-nuget.zip"
 
-    from ("$buildDir/nupkg") {
+    from("$buildDir/nupkg") {
         include "*.nupkg"
         include "*.snupkg"
     }
@@ -133,7 +135,7 @@ task zipNuGet(type: Zip) {
 task zipCppClient(type: Zip) {
     archiveFileName = "apache-ignite-${project.version}-cpp.zip"
 
-    from ("$projectDir/cpp") {
+    from("$projectDir/cpp") {
         exclude "CMakeFiles"
         exclude "pom.xml"
         exclude "StyleGuide.md"
@@ -155,7 +157,7 @@ def signArtifacts = tasks.register('signArtifacts', Sign) {
 }
 
 tasks.register('dotnetTest', Exec) {
-    workingDir "$rootDir/modules/platforms/dotnet"
+    workingDir "$projectDir/dotnet"
 
     // Do not require external server, it will be started as part of tests.
     // Alternatively, start PlatformTestNodeRunner manually before executing 
this task.
@@ -190,8 +192,9 @@ artifacts {
         cppClientHeaders(file("$buildDir/install/include")) {
             builtBy cmakeBuildClient
         }
-        //TODO https://issues.apache.org/jira/browse/IGNITE-23443
-        cppClient(file("$buildDir/cpp/lib/libignite3-client.so.3.0.0")) {
+
+        def cmakeProjectVersion = 
cmakeProjectVersion(project.projectVersion.toString())
+        
cppClient(file("$buildDir/cpp/lib/libignite3-client.so.$cmakeProjectVersion")) {
             builtBy cmakeBuildClient
         }
         cppClient(file("$buildDir/cpp/lib/libignite3-client.so")) {
@@ -206,10 +209,46 @@ artifacts {
             odbc(file("$buildDir/cpp/lib/libignite3-odbc.so")) {
                 builtBy cmakeBuildOdbc
             }
-            //TODO https://issues.apache.org/jira/browse/IGNITE-23443
-            odbc(file("$buildDir/cpp/lib/libignite3-odbc.so.3.0.0")) {
+            
odbc(file("$buildDir/cpp/lib/libignite3-odbc.so.$cmakeProjectVersion")) {
                 builtBy cmakeBuildOdbc
             }
         }
     }
 }
+
+def updateVersion = tasks.register('updateVersion', Task) {
+    description = 'Updates the version of the platforms artifacts'
+    def version = project.projectVersion.toString()
+    updateCMakeVersion(version)
+    updateDotnetVersion(version)
+    updatePythonVersion(version)
+}
+
+private void updateCMakeVersion(String version) {
+    def versionFile = file("$projectDir/cpp/_version.txt")
+    versionFile.text = cmakeProjectVersion(version)
+}
+
+/**
+ * Strips the pre-release portion of the project version string to satisfy 
CMake requirements
+ */
+private String cmakeProjectVersion(String version) {
+    def dashIndex = version.indexOf('-')
+    if (dashIndex != -1) {
+        return version.substring(0, dashIndex)
+    }
+    return version
+}
+
+private void updateDotnetVersion(String version) {
+    def versionFile = file("$projectDir/dotnet/version.json")
+    def json = new JsonSlurper().parseText(versionFile.text)
+    // Apparently dotnet doesn't like upper-case in version: 
https://github.com/dotnet/Nerdbank.GitVersioning/issues/1110
+    json.version = version.toLowerCase()
+    versionFile.text = JsonOutput.prettyPrint(JsonOutput.toJson(json)) + '\n'
+}
+
+private void updatePythonVersion(String version) {
+    def versionFile = file("$projectDir/python/pyignite3/_version.txt")
+    versionFile.text = version
+}
diff --git a/modules/platforms/cpp/CMakeLists.txt 
b/modules/platforms/cpp/CMakeLists.txt
index f7fdb8318f..006224d0cf 100644
--- a/modules/platforms/cpp/CMakeLists.txt
+++ b/modules/platforms/cpp/CMakeLists.txt
@@ -16,7 +16,14 @@
 #
 
 cmake_minimum_required(VERSION 3.18)
-project(Ignite.C++ VERSION 3.0.0 LANGUAGES CXX)
+
+file(READ _version.txt IGNITE_VERSION)
+if(NOT DEFINED IGNITE_VERSION)
+  set(IGNITE_VERSION 3.0.0)
+  message(WARNING "Failed to read version from _version.txt file. Using 
default version \"${IGNITE_VERSION}\".")
+endif()
+
+project(Ignite.C++ VERSION ${IGNITE_VERSION} LANGUAGES CXX)
 
 set(CMAKE_CXX_STANDARD 17)
 set(CMAKE_CXX_STANDARD_REQUIRED ON)
diff --git a/modules/platforms/cpp/_version.txt 
b/modules/platforms/cpp/_version.txt
new file mode 100644
index 0000000000..56fea8a08d
--- /dev/null
+++ b/modules/platforms/cpp/_version.txt
@@ -0,0 +1 @@
+3.0.0
\ No newline at end of file
diff --git a/modules/platforms/dotnet/Apache.Ignite.Tests/VersionTests.cs 
b/modules/platforms/dotnet/Apache.Ignite.Tests/VersionTests.cs
index 36618ac337..153dfa35fc 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Tests/VersionTests.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Tests/VersionTests.cs
@@ -38,9 +38,9 @@ public class VersionTests
     [Test]
     public void TestAssemblyVersionMatchesJavaServerVersion()
     {
-        var buildGradle = Path.Combine(TestUtils.RepoRootDir, "build.gradle");
+        var buildGradle = Path.Combine(TestUtils.RepoRootDir, 
"gradle.properties");
         var buildGradleText = File.ReadAllText(buildGradle);
-        var versionMatch = Regex.Match(buildGradleText, 
@"version\s*=\s*""(.*?)""");
+        var versionMatch = Regex.Match(buildGradleText, 
@"projectVersion\s*=\s*(.*?)\s");
 
         Assert.IsTrue(versionMatch.Success);
 
diff --git a/modules/platforms/dotnet/version.json 
b/modules/platforms/dotnet/version.json
index da4c31ac00..7b9d1fb544 100644
--- a/modules/platforms/dotnet/version.json
+++ b/modules/platforms/dotnet/version.json
@@ -1,13 +1,13 @@
 {
-  "$schema": 
"https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json";,
-  "version": "3.0.0-beta2",
-  "publicReleaseRefSpec": [
-    "^refs/heads/main",
-    "^refs/heads/\\d+.*$"
-  ],
-  "cloudBuild": {
-    "buildNumber": {
-      "enabled": false
+    "$schema": 
"https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json";,
+    "version": "3.0.0-snapshot",
+    "publicReleaseRefSpec": [
+        "^refs/heads/main",
+        "^refs/heads/\\d+.*$"
+    ],
+    "cloudBuild": {
+        "buildNumber": {
+            "enabled": false
+        }
     }
-  }
 }
diff --git a/modules/platforms/python/CMakeLists.txt 
b/modules/platforms/python/CMakeLists.txt
index 1be294ce4a..43cde09b40 100644
--- a/modules/platforms/python/CMakeLists.txt
+++ b/modules/platforms/python/CMakeLists.txt
@@ -16,7 +16,7 @@
 #
 
 cmake_minimum_required(VERSION 3.18)
-project(pyignite3 VERSION 3 LANGUAGES CXX)
+project(pyignite3 VERSION ${IGNITE_VERSION} LANGUAGES CXX)
 
 set(CMAKE_CXX_STANDARD 17)
 set(CMAKE_CXX_STANDARD_REQUIRED ON)
diff --git a/modules/platforms/python/pyignite3/__init__.py 
b/modules/platforms/python/pyignite3/__init__.py
index a29ab750ff..5358f61862 100644
--- a/modules/platforms/python/pyignite3/__init__.py
+++ b/modules/platforms/python/pyignite3/__init__.py
@@ -16,12 +16,13 @@
 import datetime
 import decimal
 import uuid
+import pkgutil
 from typing import Optional, List, Any, Sequence, Tuple, Union
 
 from pyignite3 import _pyignite3_extension
 from pyignite3 import native_type_code
 
-__version__ = '3.0.0-beta2'
+__version__ = pkgutil.get_data(__name__, "_version.txt").decode
 
 apilevel = '2.0'
 """PEP 249 is supported."""
diff --git a/modules/platforms/python/pyignite3/_version.txt 
b/modules/platforms/python/pyignite3/_version.txt
new file mode 100644
index 0000000000..096bf47efe
--- /dev/null
+++ b/modules/platforms/python/pyignite3/_version.txt
@@ -0,0 +1 @@
+3.0.0-SNAPSHOT
\ No newline at end of file
diff --git a/modules/platforms/python/setup.py 
b/modules/platforms/python/setup.py
index 53628e5618..121c4aa8a7 100644
--- a/modules/platforms/python/setup.py
+++ b/modules/platforms/python/setup.py
@@ -19,6 +19,7 @@ import subprocess
 import setuptools
 import sys
 import multiprocessing
+import pkgutil
 from pprint import pprint
 from setuptools.command.build_ext import build_ext
 from setuptools.extension import Extension
@@ -46,12 +47,19 @@ with open('README.md', 'r', encoding='utf-8') as 
readme_file:
     long_description = readme_file.read()
 
 version = None
-with open(PACKAGE_NAME + '/__init__.py', 'r') as fd:
-    version = re.search(r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]',
-                        fd.read(), re.MULTILINE).group(1)
+with open(os.path.join(PACKAGE_NAME, '_version.txt'), 'r') as fd:
+    version = fd.read()
     if not version:
         raise RuntimeError('Cannot find version information')
 
+def cmake_project_version(version):
+    """
+    Strips the pre-release portion of the project version string to satisfy 
CMake requirements
+    """
+    dash_index = version.find("-")
+    if dash_index != -1:
+        return version[:dash_index]
+    return version
 
 def _get_env_variable(name, default='OFF'):
     if name not in os.environ.keys():
@@ -90,6 +98,7 @@ class CMakeBuild(build_ext):
                 
f'-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_{cfg.upper()}={self.build_temp}',
                 f'-DPYTHON_EXECUTABLE={sys.executable}',
                 f'-DEXTENSION_FILENAME={ext_file}',
+                f'-DIGNITE_VERSION={cmake_project_version(version)}',
             ]
 
             if platform.system() == 'Windows':
diff --git a/modules/rest-api/build.gradle b/modules/rest-api/build.gradle
index 86281fe2b1..bd9f94229a 100644
--- a/modules/rest-api/build.gradle
+++ b/modules/rest-api/build.gradle
@@ -64,7 +64,9 @@ ext {
     openapiProps = [
             'micronaut.openapi.property.naming.strategy' : 'LOWER_CAMEL_CASE',
             'micronaut.openapi.target.file' : openapiFile.path,
-            'micronaut.openapi.field.visibility.level' : 'PRIVATE'
+            'micronaut.openapi.field.visibility.level' : 'PRIVATE',
+            'api.version' : project.version,
+            'api.product' : project.product
     ]
 }
 
diff --git 
a/modules/rest-api/src/main/java/org/apache/ignite/internal/rest/api/Definition.java
 
b/modules/rest-api/src/main/java/org/apache/ignite/internal/rest/api/Definition.java
index dcbb78a2d2..ef12ada47e 100644
--- 
a/modules/rest-api/src/main/java/org/apache/ignite/internal/rest/api/Definition.java
+++ 
b/modules/rest-api/src/main/java/org/apache/ignite/internal/rest/api/Definition.java
@@ -32,8 +32,8 @@ import io.swagger.v3.oas.annotations.servers.Server;
 @OpenAPIDefinition(
         servers = @Server(url = "http://localhost:10300";),
         info = @Info(
-                title = "Ignite REST module",
-                version = "3.0.0-SNAPSHOT",
+                title = "${api.product} REST module",
+                version = "${api.version}",
                 license = @License(name = "Apache 2.0", url = 
"https://ignite.apache.org";),
                 contact = @Contact(email = "[email protected]")))
 @SecurityRequirement(name = "basicAuth")

Reply via email to