|
5 | 5 | import re |
6 | 6 | import requests |
7 | 7 | import subprocess |
| 8 | +import time |
8 | 9 | from enum import Enum, auto |
9 | 10 |
|
10 | 11 |
|
@@ -119,6 +120,7 @@ def commit_and_push_changes(directory: str, message: str): |
119 | 120 |
|
120 | 121 |
|
121 | 122 | def upload_asset_to_github_release(upload_url: str, asset_path: str, asset_name: str): |
| 123 | + print(f"Uploading {asset_name} to github release..") |
122 | 124 | # Build headers with token and content type |
123 | 125 | headers = { |
124 | 126 | "Authorization": f"token {github_token}", |
@@ -176,42 +178,37 @@ def create_github_release(repo_url: str, tag_name: str, release_name: str, relea |
176 | 178 |
|
177 | 179 | def get_asset_name(module: Module) -> str: |
178 | 180 | if module == Module.SDK: |
179 | | - return "sdk-android-release.aar" |
| 181 | + return "matrix-android-sdk.aar" |
180 | 182 | elif module == Module.CRYPTO: |
181 | | - return "crypto-android-release.aar" |
| 183 | + return "matrix-android-crypto.aar" |
182 | 184 | else: |
183 | 185 | raise ValueError(f"Unknown module: {module}") |
184 | 186 |
|
185 | 187 |
|
186 | 188 | def get_asset_path(root_project_dir: str, module: Module) -> str: |
187 | 189 | if module == Module.SDK: |
188 | 190 | return os.path.join(root_project_dir, "sdk/sdk-android/build/outputs/aar", |
189 | | - get_asset_name(module)) |
| 191 | + "sdk-android-release.aar") |
190 | 192 | elif module == Module.CRYPTO: |
191 | 193 | return os.path.join(root_project_dir, "crypto/crypto-android/build/outputs/aar", |
192 | | - get_asset_name(module)) |
| 194 | + "crypto-android-release.aar") |
193 | 195 | else: |
194 | 196 | raise ValueError(f"Unknown module: {module}") |
195 | 197 |
|
196 | | -def get_gradle_module_dir(module: Module, root_project_dir: str) -> str: |
| 198 | + |
| 199 | +def get_publish_task(module: Module) -> str: |
197 | 200 | if module == Module.SDK: |
198 | | - return os.path.join(root_project_dir, "sdk") |
| 201 | + return ":sdk:sdk-android:publishToSonatype" |
199 | 202 | elif module == Module.CRYPTO: |
200 | | - return os.path.join(root_project_dir, "crypto") |
| 203 | + return ":crypto:crypto-android:publishToSonatype" |
201 | 204 | else: |
202 | 205 | raise ValueError(f"Unknown module: {module}") |
203 | 206 |
|
204 | | -def run_gradle_task(module_dir: str, task_name: str): |
205 | | - # Build Gradle command |
206 | | - gradle_command = f"cd {module_dir} && ./gradlew {task_name}" |
207 | | - |
208 | | - # Run Gradle command |
209 | | - result = subprocess.run(gradle_command, shell=True) |
210 | | - if result.returncode == 0: |
211 | | - print(f"Gradle task '{task_name}' completed successfully.") |
212 | | - else: |
213 | | - print(f"Failed to run Gradle task '{task_name}'.") |
214 | | - |
| 207 | +def run_publish_close_and_release_tasks(root_project_dir, publish_task: str): |
| 208 | + gradle_command = f"./gradlew {publish_task} closeAndReleaseStagingRepository" |
| 209 | + result = subprocess.run(gradle_command, shell=True, cwd=root_project_dir, text=True) |
| 210 | + if result.returncode != 0: |
| 211 | + raise Exception(f"Gradle tasks failed with return code {result.returncode}") |
215 | 212 |
|
216 | 213 | github_token = os.environ['GITHUB_API_TOKEN'] |
217 | 214 |
|
@@ -254,12 +251,14 @@ def run_gradle_task(module_dir: str, task_name: str): |
254 | 251 | commit_and_push_changes(project_root, commit_message) |
255 | 252 |
|
256 | 253 | release_name = f"{args.module.name.lower()}-v{args.version}" |
257 | | -release_notes = f"{release_name} using matrix-rust-sdk {sdk_commit_hash}" |
| 254 | +release_notes = f"https://github.com/matrix-org/matrix-rust-sdk/tree/{sdk_commit_hash}" |
258 | 255 | asset_path = get_asset_path(project_root, args.module) |
259 | 256 | asset_name = get_asset_name(args.module) |
260 | 257 |
|
261 | 258 | create_github_release("https://api.github.com/repos/matrix-org/matrix-rust-components-kotlin", |
262 | 259 | release_name, release_name, release_notes) |
263 | 260 |
|
264 | | -run_gradle_task(get_gradle_module_dir(args.module, project_root), "publishReleasePublicationToSonatypeRepository") |
265 | | -run_gradle_task(project_root, "closeAndReleaseSonatypeStagingRepository") |
| 261 | +run_publish_close_and_release_tasks( |
| 262 | + project_root, |
| 263 | + get_publish_task(args.module), |
| 264 | +) |
0 commit comments