mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-09-07 00:59:26 +00:00
experiments time
This commit is contained in:
@@ -1,52 +1,4 @@
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.net.http.HttpClient
|
||||
import java.net.http.HttpRequest
|
||||
import java.net.http.HttpResponse
|
||||
|
||||
apply plugin: 'maven-publish'
|
||||
// This script work based on https://ossrh-staging-api.central.sonatype.com/swagger-ui/#/default/manual_upload_repository
|
||||
// and getting available open repos and just uploading them
|
||||
if ((project.hasProperty('SONATYPE_USER') || System.getenv('SONATYPE_USER') != null) && (project.hasProperty('SONATYPE_PASSWORD') || System.getenv('SONATYPE_PASSWORD') != null)) {
|
||||
def taskName = "uploadSonatypePublication"
|
||||
if (rootProject.tasks.names.contains(taskName) == false) {
|
||||
System.setProperty("jdk.httpclient.allowRestrictedHeaders", "Connection,Keep-Alive")
|
||||
rootProject.tasks.register(taskName) {
|
||||
doLast {
|
||||
def username = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : System.getenv('SONATYPE_USER')
|
||||
def password = project.hasProperty('SONATYPE_PASSWORD') ? project.property('SONATYPE_PASSWORD') : System.getenv('SONATYPE_PASSWORD')
|
||||
def bearer = Base64.getEncoder().encodeToString("$username:$password".getBytes(StandardCharsets.UTF_8))
|
||||
|
||||
def client = HttpClient.newHttpClient()
|
||||
def request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://ossrh-staging-api.central.sonatype.com/manual/search/repositories?state=open"))
|
||||
.GET()
|
||||
.header("Content-Type", "application/json")
|
||||
.header("Authorization", "Bearer $bearer")
|
||||
.build()
|
||||
|
||||
def response = client.send(request, HttpResponse.BodyHandlers.ofString())
|
||||
def keys = new ArrayList<String>()
|
||||
response.body().findAll("\"key\"[\\s]*:[\\s]*\"[^\"]+\"").forEach {
|
||||
def key = it.find("[^\"]+\"\$").find("[^\"]+")
|
||||
keys.add(key)
|
||||
}
|
||||
keys.forEach {
|
||||
println("Start uploading $it")
|
||||
def uploadRequest = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://ossrh-staging-api.central.sonatype.com/manual/upload/repository/$it?publishing_type=user_managed"))
|
||||
.POST(HttpRequest.BodyPublishers.ofString(""))
|
||||
.header("Content-Type", "application/json")
|
||||
.header("Authorization", "Bearer $bearer")
|
||||
.build()
|
||||
def uploadResponse = client.send(uploadRequest, HttpResponse.BodyHandlers.ofString())
|
||||
if (uploadResponse.statusCode() != 200) {
|
||||
throw IllegalStateException("Faced error of uploading for repo with key $it. Response: $uploadResponse")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
task javadocsJar(type: Jar) {
|
||||
archiveClassifier = 'javadoc'
|
||||
|
@@ -1,52 +1,4 @@
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.net.http.HttpClient
|
||||
import java.net.http.HttpRequest
|
||||
import java.net.http.HttpResponse
|
||||
|
||||
apply plugin: 'maven-publish'
|
||||
// This script work based on https://ossrh-staging-api.central.sonatype.com/swagger-ui/#/default/manual_upload_repository
|
||||
// and getting available open repos and just uploading them
|
||||
if ((project.hasProperty('SONATYPE_USER') || System.getenv('SONATYPE_USER') != null) && (project.hasProperty('SONATYPE_PASSWORD') || System.getenv('SONATYPE_PASSWORD') != null)) {
|
||||
def taskName = "uploadSonatypePublication"
|
||||
if (rootProject.tasks.names.contains(taskName) == false) {
|
||||
System.setProperty("jdk.httpclient.allowRestrictedHeaders", "Connection,Keep-Alive")
|
||||
rootProject.tasks.register(taskName) {
|
||||
doLast {
|
||||
def username = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : System.getenv('SONATYPE_USER')
|
||||
def password = project.hasProperty('SONATYPE_PASSWORD') ? project.property('SONATYPE_PASSWORD') : System.getenv('SONATYPE_PASSWORD')
|
||||
def bearer = Base64.getEncoder().encodeToString("$username:$password".getBytes(StandardCharsets.UTF_8))
|
||||
|
||||
def client = HttpClient.newHttpClient()
|
||||
def request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://ossrh-staging-api.central.sonatype.com/manual/search/repositories?state=open"))
|
||||
.GET()
|
||||
.header("Content-Type", "application/json")
|
||||
.header("Authorization", "Bearer $bearer")
|
||||
.build()
|
||||
|
||||
def response = client.send(request, HttpResponse.BodyHandlers.ofString())
|
||||
def keys = new ArrayList<String>()
|
||||
response.body().findAll("\"key\"[\\s]*:[\\s]*\"[^\"]+\"").forEach {
|
||||
def key = it.find("[^\"]+\"\$").find("[^\"]+")
|
||||
keys.add(key)
|
||||
}
|
||||
keys.forEach {
|
||||
println("Start uploading $it")
|
||||
def uploadRequest = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://ossrh-staging-api.central.sonatype.com/manual/upload/repository/$it?publishing_type=user_managed"))
|
||||
.POST(HttpRequest.BodyPublishers.ofString(""))
|
||||
.header("Content-Type", "application/json")
|
||||
.header("Authorization", "Bearer $bearer")
|
||||
.build()
|
||||
def uploadResponse = client.send(uploadRequest, HttpResponse.BodyHandlers.ofString())
|
||||
if (uploadResponse.statusCode() != 200) {
|
||||
throw IllegalStateException("Faced error of uploading for repo with key $it. Response: $uploadResponse")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
task javadocJar(type: Jar) {
|
||||
|
@@ -19,6 +19,6 @@ for project in "${projects[@]}"; do
|
||||
assert_success ./gradlew "$project:publishAllPublicationsToSonatypeRepository" --no-parallel --quiet
|
||||
echo "Complete publishing of $project"
|
||||
echo "Start uploading of $project"
|
||||
assert_success ./gradlew uploadSonatypePublication --quiet
|
||||
assert_success ./uploadSonatypePublication.main.kts --quiet
|
||||
echo "Complete uploading of $project"
|
||||
done
|
||||
|
58
uploadSonatypePublication.main.kts
Executable file
58
uploadSonatypePublication.main.kts
Executable file
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env kotlin
|
||||
|
||||
import java.net.http.HttpRequest.BodyPublisher
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.net.http.HttpClient
|
||||
import java.net.http.HttpRequest
|
||||
import java.net.http.HttpResponse
|
||||
import java.net.URI
|
||||
import kotlin.io.encoding.Base64
|
||||
|
||||
@OptIn(kotlin.io.encoding.ExperimentalEncodingApi::class)
|
||||
fun uploadSonatypePublication (repos_state: String, publishing_type: String) {
|
||||
val bearer = let {
|
||||
val username = System.getenv("SONATYPE_USER")
|
||||
val password = System.getenv("SONATYPE_PASSWORD")
|
||||
Base64.encodeToByteArray("$username:$password".encodeToByteArray())
|
||||
}
|
||||
val baseUrl = "https://ossrh-staging-api.central.sonatype.com/manual"
|
||||
val client = HttpClient.newHttpClient()
|
||||
val makeRequest: (String, BodyPublisher, String) -> HttpResponse<String> = { method, bodyPublisher, suffix ->
|
||||
val request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("$baseUrl/$suffix"))
|
||||
.method(method, bodyPublisher)
|
||||
.header("Content-Type", "application/json")
|
||||
.header("Authorization", "Bearer $bearer")
|
||||
.build()
|
||||
client.send(request, HttpResponse.BodyHandlers.ofString())
|
||||
}
|
||||
|
||||
val response = makeRequest(
|
||||
"GET",
|
||||
HttpRequest.BodyPublishers.ofString(""),
|
||||
"/search/repositories?state=$repos_state"
|
||||
)
|
||||
val keys = mutableListOf<String>()
|
||||
Regex("\"key\"[\\s]*:[\\s]*\"[^\"]+\"").findAll(
|
||||
response.body()
|
||||
).forEach {
|
||||
val key = Regex("[^\"]+").find(Regex("[^\"]+\"\$").find(it.value) ?.value ?: return@forEach) ?.value ?: return@forEach
|
||||
keys.add(key)
|
||||
}
|
||||
keys.forEach {
|
||||
println("Start uploading $it")
|
||||
val uploadResponse = makeRequest(
|
||||
"POST",
|
||||
HttpRequest.BodyPublishers.ofString(""),
|
||||
"upload/repository/$it?publishing_type=$publishing_type"
|
||||
)
|
||||
if (uploadResponse.statusCode() != 200) {
|
||||
println("Faced error of uploading for repo with key $it. Response: $uploadResponse")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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"
|
||||
|
||||
uploadSonatypePublication(repos_state, publishing_type)
|
Reference in New Issue
Block a user