Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# .editorconfig
root = true

[*.{kt,kts}]
end_of_line = lf
ij_kotlin_packages_to_use_import_on_demand = true
ij_kotlin_allow_trailing_comma = true
ij_kotlin_allow_trailing_comma_on_call_site = true
ij_kotlin_imports_layout = *
ij_kotlin_indent_before_arrow_on_new_line = false
ij_kotlin_line_break_after_multiline_when_entry = true
indent_size = 4
indent_style = space
insert_final_newline = true
ktlint_argument_list_wrapping_ignore_when_parameter_count_greater_or_equal_than = 8
ktlint_chain_method_rule_force_multiline_when_chain_operator_count_greater_or_equal_than = 4
ktlint_code_style = android_studio
ktlint_enum_entry_name_casing = upper_or_camel_cases
ktlint_function_naming_ignore_when_annotated_with = Composable
ktlint_function_signature_body_expression_wrapping = default
ktlint_ignore_back_ticked_identifier = false
max_line_length = 140
parameter-list-wrapping = true
13 changes: 13 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ plugins {
alias(libs.plugins.kotlin) apply false
id("org.jetbrains.kotlin.plugin.allopen") version "1.9.0" apply false
alias(libs.plugins.maven.publish) apply false
id("org.jlleitschuh.gradle.ktlint") version "12.2.0" apply false
}

subprojects {
apply(plugin = "org.jlleitschuh.gradle.ktlint")
repositories {
gradlePluginPortal()
mavenCentral()
Expand All @@ -25,6 +27,14 @@ subprojects {
extensions.findByType<org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension>()?.apply {
jvmToolchain(17)
}
configure<org.jlleitschuh.gradle.ktlint.KtlintExtension> {
version.set("1.4.0")
enableExperimentalRules.set(true)
verbose.set(true)
filter {
exclude { it.file.path.contains("build/") }
}
}

val GROUP: String by project
val VERSION_NAME: String by project
Expand All @@ -36,5 +46,8 @@ subprojects {
tasks.getByName<Test>("test") {
useJUnitPlatform()
}
tasks.named("check") {
dependsOn(tasks.getByName("ktlintCheck"))
}
}
}
27 changes: 14 additions & 13 deletions kmmbridge-github/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,19 @@ gradlePlugin {
id = "co.touchlab.kmmbridge.github"
implementationClass = "co.touchlab.kmmbridge.github.KMMBridgeGitHubPlugin"
displayName = "KMMBridge/GitHub"
tags = listOf(
"kmm",
"kotlin",
"multiplatform",
"mobile",
"ios",
"xcode",
"framework",
"binary",
"publish",
"consume"
)
tags =
listOf(
"kmm",
"kotlin",
"multiplatform",
"mobile",
"ios",
"xcode",
"framework",
"binary",
"publish",
"consume",
)
}
}
}
Expand All @@ -67,4 +68,4 @@ mavenPublishing {
pomFromGradleProperties()
@Suppress("UnstableApiUsage")
configureBasedOnAppliedPlugins()
}
}
18 changes: 6 additions & 12 deletions kmmbridge-github/src/main/kotlin/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,21 @@ import co.touchlab.kmmbridge.github.internal.githubPublishUser
import co.touchlab.kmmbridge.github.internal.githubRepoOrNull
import co.touchlab.kmmbridge.github.kmmBridgeExtension
import co.touchlab.kmmbridge.publishingExtension
import org.gradle.api.Project
import java.net.URI
import org.gradle.api.Project

@Suppress("unused")
fun Project.gitHubReleaseArtifacts(
repository: String? = null,
releasString: String? = null,
useExistingRelease: Boolean = false
) {
fun Project.gitHubReleaseArtifacts(repository: String? = null, releasString: String? = null, useExistingRelease: Boolean = false) {
kmmBridgeExtension.setupGitHubReleaseArtifacts(
GithubReleaseArtifactManager(
repository,
releasString,
useExistingRelease
)
useExistingRelease,
),
)
}

private fun KmmBridgeExtension.setupGitHubReleaseArtifacts(
githubReleaseArtifactManager: GithubReleaseArtifactManager
) {
private fun KmmBridgeExtension.setupGitHubReleaseArtifacts(githubReleaseArtifactManager: GithubReleaseArtifactManager) {
artifactManager.setAndFinalize(githubReleaseArtifactManager)
}

Expand Down Expand Up @@ -53,4 +47,4 @@ fun Project.addGithubPackagesRepository() {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,24 @@ import co.touchlab.kmmbridge.github.internal.githubArtifactIdentifierName
import co.touchlab.kmmbridge.github.internal.githubArtifactReleaseId
import co.touchlab.kmmbridge.github.internal.githubPublishToken
import co.touchlab.kmmbridge.github.internal.githubRepo
import java.io.File
import kotlin.properties.Delegates
import org.gradle.api.GradleException
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.TaskProvider
import org.gradle.kotlin.dsl.getByType
import java.io.File
import kotlin.properties.Delegates

open class GithubReleaseArtifactManager(
private val repository: String?,
private val releaseString: String?,
@Deprecated("Releases should be created externally. This parameter controls the flow for releases created " +
"by this class, which will eventually be unsupported.")
private val useExistingRelease: Boolean
@Deprecated(
"Releases should be created externally. This parameter controls the flow for releases created " +
"by this class, which will eventually be unsupported.",
)
private val useExistingRelease: Boolean,
) : ArtifactManager {

@get:Input
lateinit var releaseVersion: String

Expand All @@ -43,9 +44,7 @@ open class GithubReleaseArtifactManager(
// https://docs.gradle.org/current/userguide/configuration_cache.html#config_cache:secrets
lateinit var githubPublishToken: String

override fun configure(
project: Project, version: String, uploadTask: TaskProvider<Task>, kmmPublishTask: TaskProvider<Task>
) {
override fun configure(project: Project, version: String, uploadTask: TaskProvider<Task>, kmmPublishTask: TaskProvider<Task>) {
this.releaseVersion = releaseString ?: project.version.toString()
this.repoName = this.repository ?: project.githubRepo
this.githubPublishToken = project.githubPublishToken
Expand All @@ -55,47 +54,55 @@ open class GithubReleaseArtifactManager(
}

override fun deployArtifact(task: Task, zipFilePath: File, version: String): String {
val uploadReleaseId = if (artifactReleaseId == 0) {
val existingReleaseId = GithubCalls.findReleaseId(
githubPublishToken, repoName, releaseVersion
)

task.logger.info("existingReleaseId: $existingReleaseId")

if (existingReleaseId != null && !useExistingRelease) {
throw GradleException("Release for '$releaseVersion' exists. Set 'useExistingRelease = true' to update existing releases.")
val uploadReleaseId =
if (artifactReleaseId == 0) {
val existingReleaseId =
GithubCalls.findReleaseId(
githubPublishToken,
repoName,
releaseVersion,
)

task.logger.info("existingReleaseId: $existingReleaseId")

if (existingReleaseId != null && !useExistingRelease) {
throw GradleException(
"Release for '$releaseVersion' exists. Set 'useExistingRelease = true' to update existing releases.",
)
}

val idReply: Int =
existingReleaseId ?: GithubCalls.createRelease(
githubPublishToken,
repoName,
releaseVersion,
null,
)

task.logger.info("GitHub Release created with id: $idReply")

idReply
} else {
artifactReleaseId
}

val idReply: Int = existingReleaseId ?: GithubCalls.createRelease(
githubPublishToken, repoName, releaseVersion, null
)

task.logger.info("GitHub Release created with id: $idReply")

idReply
} else {
artifactReleaseId
}

val fileName = artifactName(version, useExistingRelease)

val uploadUrl = GithubCalls.uploadZipFile(githubPublishToken, zipFilePath, repoName, uploadReleaseId, fileName)
return "${uploadUrl}.zip"
return "$uploadUrl.zip"
}

private fun artifactName(versionString: String, useExistingRelease: Boolean): String {
return if (useExistingRelease) {
"$frameworkName-${versionString}-${(System.currentTimeMillis() / 1000)}.xcframework.zip"
} else {
uploadZipFileName(versionString)
}
private fun artifactName(versionString: String, useExistingRelease: Boolean): String = if (useExistingRelease) {
"$frameworkName-$versionString-${(System.currentTimeMillis() / 1000)}.xcframework.zip"
} else {
uploadZipFileName(versionString)
}

open fun uploadZipFileName(versionString: String) = if (artifactIdentifierName.isNotEmpty()) {
"$frameworkName-${artifactIdentifierName}.xcframework.zip"
"$frameworkName-$artifactIdentifierName.xcframework.zip"
} else {
"$frameworkName.xcframework.zip"
}
}

internal val Project.kmmBridgeExtension get() = extensions.getByType<KmmBridgeExtension>()
internal val Project.kmmBridgeExtension get() = extensions.getByType<KmmBridgeExtension>()
Loading