Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow releasing snapshot versions of the Rust SDK #52

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions buildSrc/src/main/kotlin/BuildVersionsSDK.kt
Original file line number Diff line number Diff line change
@@ -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"
}
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
23 changes: 13 additions & 10 deletions scripts/build-rust-for-target.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions scripts/publish-module.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ signing {
rootProject.ext["signing.password"],
)
sign publishing.publications
required { !PUBLISH_VERSION.endsWith("-SNAPSHOT") }
}
3 changes: 3 additions & 0 deletions scripts/publish-root.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@ nexusPublishing {
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
}
}
useStaging.convention(project.provider {
!project.hasProperty("snapshot")
})
}
68 changes: 42 additions & 26 deletions scripts/release_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand Down
Loading