From 00ca96eec88f3132e652430968c41134f18f16c7 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 8 Jun 2025 18:51:53 +0600 Subject: [PATCH] add nmcp --- build.gradle | 15 ++++ gradle/libs.versions.toml | 2 + gradle/templates/publish.kpsb | 2 +- gradle/templates/publish_jvm.kpsb | 2 +- publish_all_script | 28 ------ uploadSonatypePublication.main.kts | 139 ----------------------------- 6 files changed, 19 insertions(+), 169 deletions(-) delete mode 100755 publish_all_script delete mode 100755 uploadSonatypePublication.main.kts diff --git a/build.gradle b/build.gradle index 97c0f8b9b44..7af6ee04c55 100644 --- a/build.gradle +++ b/build.gradle @@ -19,6 +19,21 @@ buildscript { plugins { alias(libs.plugins.versions) + alias(libs.plugins.nmcp.aggregation) +} + + +if ((project.hasProperty('SONATYPE_USER') || System.getenv('SONATYPE_USER') != null) && (project.hasProperty('SONATYPE_PASSWORD') || System.getenv('SONATYPE_PASSWORD') != null)) { + nmcpAggregation { + centralPortal { + username = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : System.getenv('SONATYPE_USER') + password = project.hasProperty('SONATYPE_PASSWORD') ? project.property('SONATYPE_PASSWORD') : System.getenv('SONATYPE_PASSWORD') + verificationTimeout = Duration.ofSeconds(0) + publishingType = "USER_MANAGED" + } + + publishAllProjectsProbablyBreakingProjectIsolation() + } } allprojects { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index e0fe7f3b3f3..93c1b10dee6 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -29,6 +29,7 @@ ksp = "2.1.20-1.0.31" kotlin-poet = "1.18.1" versions = "0.51.0" +nmcp = "0.1.5" android-gradle = "8.9.+" dexcount = "4.0.0" @@ -123,3 +124,4 @@ jb-compose = { id = "org.jetbrains.compose", version.ref = "jb-compose" } kt-jb-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kt" } versions = { id = "com.github.ben-manes.versions", version.ref = "versions" } +nmcp-aggregation = { id = "com.gradleup.nmcp.aggregation", version.ref = "nmcp" } diff --git a/gradle/templates/publish.kpsb b/gradle/templates/publish.kpsb index 36449579aa3..c3b213dc1cd 100644 --- a/gradle/templates/publish.kpsb +++ b/gradle/templates/publish.kpsb @@ -1 +1 @@ -{"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/MicroUtils/blob/master/LICENSE"}],"mavenConfig":{"name":"${project.name}","description":"It is set of projects with micro tools for avoiding of routines coding","url":"https://github.com/InsanusMokrassar/MicroUtils/","vcsUrl":"https://github.com/InsanusMokrassar/MicroUtils.git","developers":[{"id":"InsanusMokrassar","name":"Aleksei Ovsiannikov","eMail":"ovsyannikov.alexey95@gmail.com"},{"id":"000Sanya","name":"Syrov Aleksandr","eMail":"000sanya.000sanya@gmail.com"}],"repositories":[{"name":"GithubPackages","url":"https://maven.pkg.github.com/InsanusMokrassar/MicroUtils"},{"name":"InmoNexus","url":"https://nexus.inmo.dev/repository/maven-releases/"},{"name":"sonatype","url":"https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2/"}],"gpgSigning":{"type":"dev.inmo.kmppscriptbuilder.core.models.GpgSigning.Optional"},"includeCentralSonatypeUploadingScript":true}} \ No newline at end of file +{"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/MicroUtils/blob/master/LICENSE"}],"mavenConfig":{"name":"${project.name}","description":"It is set of projects with micro tools for avoiding of routines coding","url":"https://github.com/InsanusMokrassar/MicroUtils/","vcsUrl":"https://github.com/InsanusMokrassar/MicroUtils.git","developers":[{"id":"InsanusMokrassar","name":"Aleksei Ovsiannikov","eMail":"ovsyannikov.alexey95@gmail.com"},{"id":"000Sanya","name":"Syrov Aleksandr","eMail":"000sanya.000sanya@gmail.com"}],"repositories":[{"name":"GithubPackages","url":"https://maven.pkg.github.com/InsanusMokrassar/MicroUtils"},{"name":"InmoNexus","url":"https://nexus.inmo.dev/repository/maven-releases/"},{"name":"sonatype","url":"https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2/"}],"gpgSigning":{"type":"dev.inmo.kmppscriptbuilder.core.models.GpgSigning.Optional"},"includeCentralSonatypeUploadingScript":false}} \ No newline at end of file diff --git a/gradle/templates/publish_jvm.kpsb b/gradle/templates/publish_jvm.kpsb index fe56af0efdf..5258fd118ce 100644 --- a/gradle/templates/publish_jvm.kpsb +++ b/gradle/templates/publish_jvm.kpsb @@ -1 +1 @@ -{"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/MicroUtils/blob/master/LICENSE"}],"mavenConfig":{"name":"${project.name}","description":"It is set of projects with micro tools for avoiding of routines coding","url":"https://github.com/InsanusMokrassar/MicroUtils/","vcsUrl":"https://github.com/InsanusMokrassar/MicroUtils.git","developers":[{"id":"InsanusMokrassar","name":"Aleksei Ovsiannikov","eMail":"ovsyannikov.alexey95@gmail.com"},{"id":"000Sanya","name":"Syrov Aleksandr","eMail":"000sanya.000sanya@gmail.com"}],"repositories":[{"name":"GithubPackages","url":"https://maven.pkg.github.com/InsanusMokrassar/MicroUtils"},{"name":"InmoNexus","url":"https://nexus.inmo.dev/repository/maven-releases/"},{"name":"sonatype","url":"https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2/"}],"gpgSigning":{"type":"dev.inmo.kmppscriptbuilder.core.models.GpgSigning.Optional"},"includeCentralSonatypeUploadingScript":true},"type":"JVM"} \ No newline at end of file +{"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/MicroUtils/blob/master/LICENSE"}],"mavenConfig":{"name":"${project.name}","description":"It is set of projects with micro tools for avoiding of routines coding","url":"https://github.com/InsanusMokrassar/MicroUtils/","vcsUrl":"https://github.com/InsanusMokrassar/MicroUtils.git","developers":[{"id":"InsanusMokrassar","name":"Aleksei Ovsiannikov","eMail":"ovsyannikov.alexey95@gmail.com"},{"id":"000Sanya","name":"Syrov Aleksandr","eMail":"000sanya.000sanya@gmail.com"}],"repositories":[{"name":"GithubPackages","url":"https://maven.pkg.github.com/InsanusMokrassar/MicroUtils"},{"name":"InmoNexus","url":"https://nexus.inmo.dev/repository/maven-releases/"},{"name":"sonatype","url":"https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2/"}],"gpgSigning":{"type":"dev.inmo.kmppscriptbuilder.core.models.GpgSigning.Optional"},"includeCentralSonatypeUploadingScript":false},"type":"JVM"} \ No newline at end of file diff --git a/publish_all_script b/publish_all_script deleted file mode 100755 index fff5b3df400..00000000000 --- a/publish_all_script +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash - -function send_notification() { - echo "$1" -} - -function assert_success() { - "${@}" - local status=${?} - if [ ${status} -ne 0 ]; then - send_notification "### Error ${status} at: ${BASH_LINENO[*]} ###" - exit ${status} - fi -} - -assert_success ./uploadSonatypePublication.main.kts --drop - -readarray -t projects <<< "`./gradlew getPublishableModules --quiet`" -for project in "${projects[@]}"; do - echo "Start publishing of $project" - assert_success ./gradlew "$project:publishAllPublicationsToSonatypeRepository" --no-parallel --quiet - echo "Complete publishing of $project" - echo "Start uploading of $project" - assert_success ./uploadSonatypePublication.main.kts --user_manager - echo "Complete uploading of $project" -done - -assert_success ./uploadSonatypePublication.main.kts --automatic diff --git a/uploadSonatypePublication.main.kts b/uploadSonatypePublication.main.kts deleted file mode 100755 index ab3925b9c16..00000000000 --- a/uploadSonatypePublication.main.kts +++ /dev/null @@ -1,139 +0,0 @@ -#!/usr/bin/env kotlin - -@file:Repository("https://repo.maven.apache.org/maven2/") -@file:DependsOn("org.jetbrains.kotlinx:kotlinx-serialization-json:1.8.1") - -import kotlinx.serialization.json.Json -import kotlinx.serialization.json.JsonArray -import kotlinx.serialization.json.JsonObject -import kotlinx.serialization.json.JsonPrimitive -import java.net.http.HttpRequest.BodyPublisher -import java.net.http.HttpClient -import java.net.http.HttpRequest -import java.net.http.HttpResponse -import java.net.URI - -class CentralSonatypeOSSRHApi( - private val bearer: String, -) { - data class SonatypeOSSRHRepository( - val key: String, - val portalDeploymentId: String?, - val state: String, - ) - - private val baseUrl = "https://ossrh-staging-api.central.sonatype.com/manual" - private val client = HttpClient.newHttpClient() - private fun makeRequest( - method: String, - suffix: String, - bodyPublisher: BodyPublisher = HttpRequest.BodyPublishers.ofString("") - ): JsonObject? { - val request = HttpRequest.newBuilder() - .uri(URI.create("$baseUrl/$suffix")) - .method(method, bodyPublisher) - .header("Content-Type", "application/json") - .header("Authorization", "Bearer $bearer") - .build() - val response = client.send(request, HttpResponse.BodyHandlers.ofString()) - println(response) - val responseBody = response.body() - println(responseBody) - return when { - response.statusCode() == 200 && responseBody.isNotEmpty() -> { - return Json.decodeFromString(JsonObject.serializer(), responseBody) - } - response.statusCode() == 200 -> { - return JsonObject(emptyMap()) - } - else -> null - } - } - - fun repositories( - profileId: String? = null, - state: String? = null, - ip: String? = null, - ): List? { - val repositories = makeRequest( - "GET", - "search/repositories?${state ?.let { "state=$it" } ?: ""}${profileId ?.let { "&profile_id=$it" } ?: ""}${ip ?.let { "&ip=$it" } ?: ""}" - ) ?.get("repositories") as? JsonArray - - return repositories ?.mapNotNull { - val asObject = it as? JsonObject ?:return@mapNotNull null - SonatypeOSSRHRepository( - (asObject["key"] as JsonPrimitive).content, - (asObject["portal_deployment_id"] as? JsonPrimitive) ?.content, - (asObject["state"] as JsonPrimitive).content, - ) - } - } - - fun drop(repositoryKey: String, ): Boolean { - val dropped = makeRequest( - "DELETE", - "drop/repository/$repositoryKey" - ) - - return dropped != null - } - - fun uploadDefault(requestedNamespace: String, publishingType: String? = null): Boolean { - val uploaded = makeRequest( - "POST", - "upload/defaultRepository/$requestedNamespace?${publishingType ?.let { "publishing_type=$publishingType" } ?: ""}" - ) - - return uploaded != null - } - - fun upload(repositoryKey: String, publishingType: String? = null): Boolean { - val uploaded = makeRequest( - "POST", - "upload/repository/$repositoryKey?${publishingType ?.let { "publishing_type=$publishingType" } ?: ""}" - ) - - return uploaded != null - } -} - -val repos_state = runCatching { System.getenv("repos_state").takeIf { it.isNotEmpty() } }.getOrNull() ?: "open" -val publishing_type = runCatching { System.getenv("publishing_type").takeIf { it.isNotEmpty() } }.getOrNull() ?: "user_managed" -val api = CentralSonatypeOSSRHApi( - let { - val username = System.getenv("SONATYPE_USER") - val password = System.getenv("SONATYPE_PASSWORD") - java.util.Base64.getEncoder().encodeToString("$username:$password".encodeToByteArray()) - } -) - -if (args.contains("--drop")) { - api.repositories()?.forEach { - println("Start dropping of ${it.key}") - val uploaded = api.drop(it.key) - - println("Complete dropping of ${it.key}. Status ok: $uploaded") - } -} - -if (args.contains("--user_manager")) { - api.repositories()?.forEach { - if (it.state == "open") { - println("Start uploading of ${it.key}") - val uploaded = api.upload(it.key, "user_managed") - - println("Complete uploading of ${it.key}. Status ok: $uploaded") - } - } -} -if (args.contains("--automatic")) { - api.repositories()?.forEach { - if (it.state == "closed") { - println("Start uploading of ${it.key} with auto mode ") - val uploaded = api.upload(it.key, "automatic") - - println("Complete uploading of ${it.key} with auto mode . Status ok: $uploaded") - } - } -}