-
-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now, we upload without publishing, we check the uploaded artifacts, and then we attempt publishing uploaded artifacts.
- Loading branch information
Showing
7 changed files
with
216 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/* | ||
* Copyright 2020 Louis Cognault Ayeva Derman. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
import okhttp3.MediaType.Companion.toMediaType | ||
import okhttp3.RequestBody.Companion.toRequestBody | ||
import retrofit2.Response | ||
import kotlin.time.* | ||
|
||
buildscript { | ||
repositories { mavenCentral() } | ||
dependencies.classpath(Square.okHttp3.okHttp) | ||
dependencies.classpath(Square.retrofit2.retrofit) | ||
} | ||
|
||
plugins { | ||
id("com.android.library") | ||
kotlin("multiplatform") | ||
} | ||
|
||
fun bintrayProperty(keySuffix: String): String = project.property("splitties.bintray.$keySuffix") as String | ||
|
||
val bintrayUsername = bintrayProperty("user") | ||
val bintrayApiKey = project.property("bintray_api_key") as String | ||
val isDevVersion = project.isDevVersion | ||
val bintrayRepoName = bintrayProperty(if (isDevVersion) "repo.dev" else "repo.release") | ||
val bintrayPackageName = bintrayProperty("package") | ||
|
||
repositories { | ||
maven("https://dl.bintray.com/$bintrayUsername/$bintrayRepoName/") { | ||
name = "bintray/$bintrayUsername/$bintrayRepoName" | ||
credentials { | ||
username = bintrayUsername | ||
password = bintrayApiKey | ||
} | ||
} | ||
} | ||
|
||
tasks.matching { it.name.startsWith("lint") }.configureEach { enabled = false } | ||
|
||
android { | ||
setDefaults() | ||
} | ||
|
||
kotlin { | ||
android() | ||
js { useCommonJs() } | ||
macos() | ||
ios(supportArm32 = true) | ||
watchos() | ||
tvos() | ||
mingw(x64 = true, x86 = true) | ||
linux(x64 = true, arm32Hfp = true, arm64 = true, mips32 = true, mipsel32 = true) | ||
sourceSets { | ||
commonMain.dependencies { | ||
|
||
val group = "com.louiscad.splitties" | ||
val version = thisLibraryVersion | ||
|
||
rootProject.rootDir.resolve("modules").listFiles { file -> | ||
file.isDirectory && file.resolve("build.gradle.kts").exists() | ||
}!!.also { check(it.isNotEmpty()) }.forEach { | ||
implementation("$group:splitties-${it.name}") { | ||
version { strictly(version) } | ||
} | ||
} | ||
|
||
rootProject.rootDir.resolve("fun-packs").listFiles { file -> | ||
file.isDirectory && file.resolve("build.gradle.kts").exists() | ||
}!!.also { check(it.isNotEmpty()) }.forEach { | ||
implementation("$group:splitties-fun-pack-${it.name}") { | ||
version { strictly(version) } | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
rootProject.tasks.register("publishBintrayRelease") { | ||
group = "publishing" | ||
description = "Publishes the artifacts uploaded on bintray for this version" | ||
|
||
dependsOn(tasks.named("build")) // Ensure publish happens after concurrent build check. | ||
|
||
@Suppress("experimental_is_not_enabled") | ||
@OptIn(ExperimentalTime::class) | ||
doFirst { | ||
|
||
// These durations might need to be raised for larger projects... | ||
// ...(but at this point, isn't the project too large?) | ||
val requestReadTimeout = 10.minutes | ||
val retryBackOff = 30.seconds | ||
val giveUpAfter = 1.hours | ||
|
||
val subject = bintrayUsername | ||
val repo = bintrayRepoName | ||
val version = thisLibraryVersion | ||
val `package` = bintrayPackageName | ||
|
||
val request = okhttp3.Request.Builder() | ||
.header( | ||
name = "Authorization", | ||
value = okhttp3.Credentials.basic(username = bintrayUsername, password = bintrayApiKey) | ||
) | ||
// Bintray API reference: https://bintray.com/docs/api/#_publish_discard_uploaded_content | ||
.url("https://bintray.com/api/v1/content/$subject/$repo/$`package`/$version/publish") | ||
.post("""{"publish_wait_for_secs":-1}""".toRequestBody("application/json".toMediaType())) | ||
.build() | ||
val httpClient = okhttp3.OkHttpClient.Builder() | ||
.readTimeout(requestReadTimeout.toJavaDuration()) | ||
.build() | ||
|
||
/** | ||
* If [isLastAttempt] is true, any failure will be thrown as an exception. | ||
*/ | ||
fun attemptPublishing(isLastAttempt: Boolean = false): Boolean { | ||
println("Attempting bintray publish") | ||
try { | ||
httpClient.newCall(request).execute().use { response -> | ||
if (response.isSuccessful) { | ||
println(response.body?.string()) | ||
return true | ||
} | ||
if (isLastAttempt.not()) when (val code = response.code) { | ||
408, 405 -> { | ||
logger.error("Publish attempt failed (http $code)") | ||
logger.info(response.body?.string() ?: "") | ||
return false | ||
} | ||
} | ||
throw retrofit2.HttpException(Response.error<Any?>(response.code, response.body!!)) | ||
} | ||
} catch (e: java.io.IOException) { | ||
if (isLastAttempt) throw e | ||
logger.error("Publish attempt failed with ${e.javaClass.simpleName}: ${e.message}") | ||
return false | ||
} | ||
} | ||
|
||
println("Will attempt bintray publishing on ${request.url}") | ||
|
||
val deadline = TimeSource.Monotonic.markNow() + giveUpAfter | ||
do { | ||
val didSucceed = attemptPublishing(isLastAttempt = deadline.hasPassedNow()) | ||
if (didSucceed.not()) Thread.sleep(retryBackOff.toLongMilliseconds()) | ||
} while (didSucceed.not()) | ||
|
||
println("Bintray publishing successful!") | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
tools/publication-checker/src/androidMain/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<!-- | ||
~ Copyright 2020 Louis Cognault Ayeva Derman. Use of this source code is governed by the Apache 2.0 license. | ||
--> | ||
|
||
<manifest package="splitties.tools.publication.checker"/> | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
LouisCAD
Author
Owner
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In case you don't know this yet,
auto-manifest
can write this file for you: https://github.com/GradleUp/auto-manifest/