diff --git a/buildSrc/src/main/kotlin/BuildVersionsSDK.kt b/buildSrc/src/main/kotlin/BuildVersionsSDK.kt index 999fa07..1ee3798 100644 --- a/buildSrc/src/main/kotlin/BuildVersionsSDK.kt +++ b/buildSrc/src/main/kotlin/BuildVersionsSDK.kt @@ -1,5 +1,5 @@ object BuildVersionsSDK { - const val majorVersion = 0 - const val minorVersion = 2 - const val patchVersion = 18 + const val majorVersion = "0" + const val minorVersion = "2" + const val patchVersion = "18" } diff --git a/buildSrc/src/main/kotlin/Dependencies.kt b/buildSrc/src/main/kotlin/Dependencies.kt index 31803e4..3da5fd6 100644 --- a/buildSrc/src/main/kotlin/Dependencies.kt +++ b/buildSrc/src/main/kotlin/Dependencies.kt @@ -2,7 +2,7 @@ object DependenciesVersions { const val androidGradlePlugin = "8.2.2" const val kotlin = "1.9.22" const val jUnit = "4.13.2" - const val nexusPublishGradlePlugin = "1.3.0" + const val nexusPublishGradlePlugin = "2.0.0" const val jna = "5.14.0" const val coroutines = "1.7.3" const val annotations = "1.7.1" diff --git a/scripts/build-rust-for-target.py b/scripts/build-rust-for-target.py index 9a31a45..cb36153 100755 --- a/scripts/build-rust-for-target.py +++ b/scripts/build-rust-for-target.py @@ -32,9 +32,9 @@ def read_version_numbers_from_kotlin_file(file_path): with open(file_path, "r") as file: content = file.read() - major_version = int(re.search(r"majorVersion\s*=\s*(\d+)", content).group(1)) - minor_version = int(re.search(r"minorVersion\s*=\s*(\d+)", content).group(1)) - patch_version = int(re.search(r"patchVersion\s*=\s*(\d+)", content).group(1)) + major_version = re.search(r"majorVersion\s*=\s*\"(.+)\"", content).group(1) + minor_version = re.search(r"minorVersion\s*=\s*\"(.+)\"", content).group(1) + patch_version = re.search(r"patchVersion\s*=\s*\"(.+)\"", content).group(1) return major_version, minor_version, patch_version @@ -110,13 +110,16 @@ def execute_build_script(script_directory: str, sdk_path: str, module: Module, t build_version_file_path = get_build_version_file_path(args.module, project_root) major, minor, patch = read_version_numbers_from_kotlin_file(build_version_file_path) -if is_provided_version_higher(major, minor, patch, args.version): - print( - f"The provided version ({args.version}) is higher than the previous version ({major}.{minor}.{patch}) so we can start the release process") -else: - print( - f"The provided version ({args.version}) is not higher than the previous version ({major}.{minor}.{patch}) so bump the version before retrying.") - exit(0) +is_snapshot_version = args.version.endswith("-SNAPSHOT") + +if not is_snapshot_version: + if is_provided_version_higher(major, minor, patch, args.version): + print( + f"The provided version ({args.version}) is higher than the previous version ({major}.{minor}.{patch}) so we can start the release process") + else: + print( + f"The provided version ({args.version}) is not higher than the previous version ({major}.{minor}.{patch}) so bump the version before retrying.") + exit(0) if skip_clone is False: clone_repo_and_checkout_ref(sdk_path, sdk_git_url, args.ref) diff --git a/scripts/publish-module.gradle b/scripts/publish-module.gradle index cca5194..078187a 100644 --- a/scripts/publish-module.gradle +++ b/scripts/publish-module.gradle @@ -53,4 +53,5 @@ signing { rootProject.ext["signing.password"], ) sign publishing.publications + required { !PUBLISH_VERSION.endsWith("-SNAPSHOT") } } \ No newline at end of file diff --git a/scripts/publish-root.gradle b/scripts/publish-root.gradle index 728a2bc..ef146d1 100644 --- a/scripts/publish-root.gradle +++ b/scripts/publish-root.gradle @@ -31,4 +31,7 @@ nexusPublishing { snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")) } } + useStaging.convention(project.provider { + !project.hasProperty("snapshot") + }) } \ No newline at end of file diff --git a/scripts/release_sdk.py b/scripts/release_sdk.py index b7184cb..f409bae 100644 --- a/scripts/release_sdk.py +++ b/scripts/release_sdk.py @@ -25,11 +25,11 @@ def override_version_in_build_version_file(file_path: str, new_version: str): with open(file_path, 'r') as file: content = file.read() - new_major, new_minor, new_patch = map(int, new_version.split('.')) + new_major, new_minor, new_patch = new_version.split('.') - content = re.sub(r"(majorVersion\s*=\s*)(\d+)", rf"\g<1>{new_major}", content) - content = re.sub(r"(minorVersion\s*=\s*)(\d+)", rf"\g<1>{new_minor}", content) - content = re.sub(r"(patchVersion\s*=\s*)(\d+)", rf"\g<1>{new_patch}", content) + content = re.sub(r"(majorVersion\s*=\s*)\"(.+)\"", rf'\g<1>"{new_major}"', content) + content = re.sub(r"(minorVersion\s*=\s*)\"(.+)\"", rf'\g<1>"{new_minor}"', content) + content = re.sub(r"(patchVersion\s*=\s*)\"(.+)\"", rf'\g<1>"{new_patch}"', content) with open(file_path, 'w') as file: file.write(content) @@ -161,6 +161,11 @@ def get_publish_task(module: Module) -> str: else: raise ValueError(f"Unknown module: {module}") +def run_publish_snapshot_task(root_project_dir, publish_task: str): + gradle_command = f"./gradlew {publish_task} -Psnapshot" + result = subprocess.run(gradle_command, shell=True, cwd=root_project_dir, text=True) + if result.returncode != 0: + raise Exception(f"Gradle tasks failed with return code {result.returncode}") def run_publish_close_and_release_tasks(root_project_dir, publish_task: str): gradle_command = f"./gradlew {publish_task} closeAndReleaseStagingRepository" @@ -206,32 +211,43 @@ def main(args: argparse.Namespace): build_aar_files(current_dir, args.module) + is_snapshot_version = args.version.endswith("-SNAPSHOT") + override_version_in_build_version_file(build_version_file_path, args.version) + publish_task = get_publish_task(args.module) + # First release on Maven - run_publish_close_and_release_tasks( - project_root, - get_publish_task(args.module), - ) + if is_snapshot_version: + run_publish_snapshot_task( + project_root, + publish_task, + ) + else: + run_publish_close_and_release_tasks( + project_root, + publish_task, + ) - # Success, commit and push changes, then create github release - commit_message = f"Bump {args.module.name} version to {args.version} (matrix-rust-sdk to {args.linkable_ref})" - print(f"Commit message: {commit_message}") - commit_and_push_changes(project_root, commit_message) - - release_name = f"{args.module.name.lower()}-v{args.version}" - release_notes = f"https://github.com/matrix-org/matrix-rust-sdk/tree/{args.linkable_ref}" - asset_path = get_asset_path(project_root, args.module) - asset_name = get_asset_name(args.module) - create_github_release( - github_token, - "https://api.github.com/repos/matrix-org/matrix-rust-components-kotlin", - release_name, - release_name, - release_notes, - asset_path, - asset_name, - ) + if not is_snapshot_version: + # Success, commit and push changes, then create github release + commit_message = f"Bump {args.module.name} version to {args.version} (matrix-rust-sdk to {args.linkable_ref})" + print(f"Commit message: {commit_message}") + commit_and_push_changes(project_root, commit_message) + + release_name = f"{args.module.name.lower()}-v{args.version}" + release_notes = f"https://github.com/matrix-org/matrix-rust-sdk/tree/{args.linkable_ref}" + asset_path = get_asset_path(project_root, args.module) + asset_name = get_asset_name(args.module) + create_github_release( + github_token, + "https://api.github.com/repos/matrix-org/matrix-rust-components-kotlin", + release_name, + release_name, + release_notes, + asset_path, + asset_name, + ) parser = argparse.ArgumentParser()