Skip to content

Commit

Permalink
Backported fixes and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
soywiz committed Jul 24, 2024
1 parent 56deb41 commit 7832e31
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 28 deletions.
59 changes: 52 additions & 7 deletions .github/workflows/DEPLOY.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,63 @@ env:
JAVA_DISTRIBUTION: zulu

jobs:
##start:
## runs-on: ubuntu-latest
## outputs:
## stagedRepositoryId: ${{ steps.releaseStep.outputs.stagedRepositoryId }}
## steps:
## - { name: Checkout, uses: actions/checkout@v3 }
## - { name: Set up JDK, uses: actions/setup-java@v3, with: { distribution: "${{ env.JAVA_DISTRIBUTION }}", java-version: "${{ env.JAVA_VERSION }}" } }
## - { name: Prepare Gradle, uses: gradle/actions/setup-gradle@d9c87d481d55275bb5441eef3fe0e46805f9ef70 } # https://github.com/gradle/actions/releases/tag/v3.5.0
## - { id: releaseStep, name: Start Maven Central Staging Repository, run: ./gradlew --no-configuration-cache startReleasingMavenCentral }

publish:
runs-on: macos-latest
strategy:
fail-fast: true # Once working, comment this
matrix:
include:
- { os: ubuntu-latest, publishTask: "publishLinuxX64PublicationToMavenLocal publishLinuxArm64PublicationToMavenLocal" }
- { os: ubuntu-latest, publishTask: "publishMingwX64PublicationToMavenLocal" }
- { os: ubuntu-latest, publishTask: "publishAndroidDebugPublicationToMavenLocal publishAndroidReleasePublicationToMavenLocal" }
- { os: ubuntu-latest, publishTask: "publishKotlinMultiplatformPublicationToMavenLocal publishJvmPublicationToMavenLocal" }
- { os: ubuntu-latest, publishTask: "publishJsPublicationToMavenLocal publishWasmJsPublicationToMavenLocal" }
- { os: macos-latest, publishTask: "publishMacosX64PublicationToMavenLocal publishMacosArm64PublicationToMavenLocal" }
- { os: macos-latest, publishTask: "publishTvosArm64PublicationToMavenLocal publishTvosSimulatorArm64PublicationToMavenLocal publishTvosX64PublicationToMavenLocal" }
- { os: macos-latest, publishTask: "publishIosArm64PublicationToMavenLocal publishIosSimulatorArm64PublicationToMavenLocal publishIosX64PublicationToMavenLocal" }
- { os: macos-latest, publishTask: "publishWatchosArm64PublicationToMavenLocal publishWatchosArm32PublicationToMavenLocal publishWatchosDeviceArm64PublicationToMavenLocal publishWatchosSimulatorArm64PublicationToMavenLocal" }
timeout-minutes: 300
runs-on: ${{ matrix.os }}
##needs: [start]
##env: { stagedRepositoryId: "${{ needs.start.outputs.stagedRepositoryId }}" }
steps:
##- { name: Print stagedRepositoryId=$stagedRepositoryId, run: "echo 'stagedRepositoryId: $stagedRepositoryId'" }
- name: Replace MavenLocal with MavenLocal
id: replace
run: |
publishTaskLocal=$(echo "${{ matrix.publishTask }}" | tr -d '\n')
publishTaskRepository=$(echo "${{ matrix.publishTask }}" | sed 's/MavenLocal/MavenRepository/g' | tr -d '\n')
echo "publishTaskLocal=${publishTaskLocal}" >> $GITHUB_ENV
echo "publishTaskRepository=${publishTaskRepository}" >> $GITHUB_ENV
- { name: Print publishTaskLocal, run: "echo 'publishTaskLocal: ${{ env.publishTaskLocal }}'" }
- { name: Print publishTaskRepository, run: "echo 'publishTaskRepository: ${{ env.publishTaskRepository }}'" }
- { name: Checkout, uses: actions/checkout@v3 }
- { name: Use Node.js 20.x, uses: actions/setup-node@v3, with: { node-version: 20.x } }
- { name: Set up JDK, uses: actions/setup-java@v3, with: { distribution: "${{ env.JAVA_DISTRIBUTION }}", java-version: "${{ env.JAVA_VERSION }}" } }
- { name: Replace Gradle Wrapper, run: "sed 's/-all/-bin/g' gradle/wrapper/gradle-wrapper.properties > gradle/wrapper/gradle-wrapper.properties.bak; cp gradle/wrapper/gradle-wrapper.properties.bak gradle/wrapper/gradle-wrapper.properties" }
- { name: Prepare Gradle, uses: gradle/gradle-build-action@ef76a971e2fa3f867b617efd72f2fbd72cf6f8bc } # v2.8.0
- { name: Prepare Gradle, uses: gradle/actions/setup-gradle@d9c87d481d55275bb5441eef3fe0e46805f9ef70 } # https://github.com/gradle/actions/releases/tag/v3.5.0
- { name: Initialize Gradle, run: ./gradlew --no-configuration-cache }

# To ensure we are fine before staging repository
- { name: Publish Publications To Maven Local, run: ./gradlew --no-configuration-cache publishToMavenLocal }
- { name: Publish Publications To Maven Local, run: "./gradlew --no-configuration-cache --parallel ${{ env.publishTaskLocal }}" }
- { name: Start Maven Central Staging Repository, run: ./gradlew --no-configuration-cache startReleasingMavenCentral }
- { name: Publish Publications To Maven Repository, run: "./gradlew --no-configuration-cache --parallel --max-workers=32 publishAllPublicationsToMavenRepository" }
- { name: Publish Publications To Maven Repository, run: "./gradlew --no-configuration-cache --parallel --max-workers=8 ${{ env.publishTaskRepository }}" }
- { name: Release to Maven Central, run: ./gradlew --no-configuration-cache releaseMavenCentral }

##finalize:
## runs-on: ubuntu-latest
## needs: [start, publish]
## env: { stagedRepositoryId: "${{ needs.start.outputs.stagedRepositoryId }}" }
## steps:
## - { name: Checkout, uses: actions/checkout@v3 }
## - { name: Use Node.js 20.x, uses: actions/setup-node@v3, with: { node-version: 20.x } }
## - { name: Set up JDK, uses: actions/setup-java@v3, with: { distribution: "${{ env.JAVA_DISTRIBUTION }}", java-version: "${{ env.JAVA_VERSION }}" } }
## - { name: Prepare Gradle, uses: gradle/actions/setup-gradle@d9c87d481d55275bb5441eef3fe0e46805f9ef70 } # https://github.com/gradle/actions/releases/tag/v3.5.0
## - { name: Initialize Gradle, run: ./gradlew --no-configuration-cache }
## - { name: Release to Maven Central, run: ./gradlew --no-configuration-cache releaseMavenCentral }
2 changes: 1 addition & 1 deletion .github/workflows/TEST.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- { name: Setup Deno, uses: denoland/setup-deno@v1, with: { deno-version: "1.44.4" } }
- { name: Replace gradle wrapper, run: "sed 's/-all/-bin/g' gradle/wrapper/gradle-wrapper.properties > gradle/wrapper/gradle-wrapper.properties.bak; cp gradle/wrapper/gradle-wrapper.properties.bak gradle/wrapper/gradle-wrapper.properties" }
- { name: Set up JDK, uses: actions/setup-java@v4, with: { distribution: "${{ env.JAVA_DISTRIBUTION }}", java-version: "${{ env.JAVA_VERSION }}" } }
- { name: Prepare Gradle, uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 } # v3.1.0
- { name: Prepare Gradle, uses: gradle/actions/setup-gradle@d9c87d481d55275bb5441eef3fe0e46805f9ef70 } # https://github.com/gradle/actions/releases/tag/v3.5.0
- { name: Start gradle, run: ./gradlew }
- { if: "${{ matrix.precompileTask }}", name: "Building ${{ matrix.precompileTask }} classes", run: "./gradlew --no-configuration-cache --stacktrace ${{ matrix.precompileTask }}" }
- { if: "${{ matrix.testTask }}", name: "Run ${{ matrix.testTask }} tests", run: "./gradlew --no-configuration-cache ${{ matrix.testTask }}" }
Expand Down
52 changes: 32 additions & 20 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -660,18 +660,7 @@ open class Sonatype(
repositoryIds.remove(repositoryId)
continue@repo
}
// Server error
// @TODO: We should handle retrying on other operations too
in 500..599 -> { // Sometimes HTTP Error 502 Bad Gateway
e.printStackTrace()
println("Retrying...")
Thread.sleep(15_000L)
retryCount++
continue@repo
}
else -> {
throw e
}
else -> throw e
}
}
when {
Expand Down Expand Up @@ -711,7 +700,7 @@ open class Sonatype(
private val client get() = SimpleHttpClient(user, pass)

fun getRepositoryState(repositoryId: String): RepoState {
val info = client.request("${BASE}/repository/$repositoryId")
val info = client.requestWithRetry("${BASE}/repository/$repositoryId")
//println("info: ${info.toStringPretty()}")
return RepoState(
repositoryId = repositoryId,
Expand All @@ -722,7 +711,7 @@ open class Sonatype(
}

fun getRepositoryActivity(repositoryId: String): String {
val info = client.request("${BASE}/repository/$repositoryId/activity")
val info = client.requestWithRetry("${BASE}/repository/$repositoryId/activity")
//println("info: ${info.toStringPretty()}")
return info.toStringPretty()
}
Expand All @@ -748,33 +737,33 @@ open class Sonatype(
}

fun repositoryClose(repositoryId: String) {
client.request("${BASE}/bulk/close", getDataMapForRepository(repositoryId))
client.requestWithRetry("${BASE}/bulk/close", getDataMapForRepository(repositoryId))
}

fun repositoryPromote(repositoryId: String) {
client.request("${BASE}/bulk/promote", getDataMapForRepository(repositoryId))
client.requestWithRetry("${BASE}/bulk/promote", getDataMapForRepository(repositoryId))
}

fun repositoryDrop(repositoryId: String) {
client.request("${BASE}/bulk/drop", getDataMapForRepository(repositoryId))
client.requestWithRetry("${BASE}/bulk/drop", getDataMapForRepository(repositoryId))
}

fun findProfileRepositories(profileId: String): List<String> {
return client.request("${BASE}/profile_repositories")["data"].list
return client.requestWithRetry("${BASE}/profile_repositories")["data"].list
.filter { it["profileId"].asString == profileId }
.map { it["repositoryId"].asString }
}

fun findProfileIdByGroupId(groupId: String): String {
val profiles = client.request("$BASE/profiles")["data"].list
val profiles = client.requestWithRetry("$BASE/profiles")["data"].list
return profiles
.filter { groupId.startsWith(it["name"].asString) }
.map { it["id"].asString }
.firstOrNull() ?: error("Can't find profile with group id '$groupId'")
}

fun startStagedRepository(profileId: String): String {
return client.request("${BASE}/profiles/$profileId/start", mapOf(
return client.requestWithRetry("${BASE}/profiles/$profileId/start", mapOf(
"data" to mapOf("description" to "Explicitly created by easy-kotlin-mpp-gradle-plugin")
))["data"]["stagedRepositoryId"].asString
}
Expand All @@ -788,6 +777,29 @@ open class SimpleHttpClient(
val user: String? = null,
val pass: String? = null
) {
open fun requestWithRetry(url: String, body: Any? = null, nretries: Int = 5): JsonElement {
var retryCount = 0
while (true) {
try {
return request(url, body)
} catch (e: SimpleHttpException) {
when (e.responseCode) {
in 500..599 -> { // Sometimes HTTP Error 502 Bad Gateway
e.printStackTrace()
retryCount++
if (retryCount >= nretries) throw RuntimeException("Couldn't access $url after $nretries retries :: ${e.responseCode} : ${e.message}", e)
println("Retrying... retryCount=$retryCount/$nretries")
Thread.sleep(15_000L)
continue
}
else -> {
throw e
}
}
}
}
}

open fun request(url: String, body: Any? = null): JsonElement {
val post = (URL(url).openConnection()) as HttpURLConnection
post.connectTimeout = 300 * 1000 // 300 seconds // 5 minutes
Expand Down
6 changes: 6 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ kotlin.native.ignoreDisabledTargets=true
kotlin.mpp.enableCInteropCommonization=true
kotlin.mpp.applyDefaultHierarchyTemplate=false
kotlin.daemon.useFallbackStrategy=false

# gradle
systemProp.org.gradle.internal.http.connectionTimeout=160000
systemProp.org.gradle.internal.http.socketTimeout=160000
systemProp.org.gradle.internal.repository.max.retries=16
systemProp.org.gradle.internal.repository.initial.backoff=500

0 comments on commit 7832e31

Please sign in to comment.