@@ -3,6 +3,8 @@ package co.touchlab.kmmbridge.github
33import co.touchlab.kmmbridge.KmmBridgeExtension
44import co.touchlab.kmmbridge.artifactmanager.ArtifactManager
55import co.touchlab.kmmbridge.github.internal.GithubCalls
6+ import co.touchlab.kmmbridge.github.internal.githubArtifactIdentifierName
7+ import co.touchlab.kmmbridge.github.internal.githubArtifactReleaseId
68import co.touchlab.kmmbridge.github.internal.githubPublishToken
79import co.touchlab.kmmbridge.github.internal.githubRepo
810import org.gradle.api.GradleException
@@ -12,9 +14,14 @@ import org.gradle.api.tasks.Input
1214import org.gradle.api.tasks.TaskProvider
1315import org.gradle.kotlin.dsl.getByType
1416import java.io.File
15-
16- internal class GithubReleaseArtifactManager (
17- private val repository : String? , private val releaseString : String? , private val useExistingRelease : Boolean
17+ import kotlin.properties.Delegates
18+
19+ open class GithubReleaseArtifactManager (
20+ private val repository : String? ,
21+ private val releaseString : String? ,
22+ @Deprecated(" Releases should be created externally. This parameter controls the flow for releases created " +
23+ " by this class, which will eventually be unsupported." )
24+ private val useExistingRelease : Boolean
1825) : ArtifactManager {
1926
2027 @get:Input
@@ -26,52 +33,69 @@ internal class GithubReleaseArtifactManager(
2633 @get:Input
2734 lateinit var frameworkName: String
2835
36+ @get:Input
37+ lateinit var artifactIdentifierName: String
38+
39+ @get:Input
40+ var artifactReleaseId by Delegates .notNull<Int >()
41+
2942 // TODO: This value is stored in the config cache. It is encrypted, but this still feels insecure. Review alternatives.
3043 // https://docs.gradle.org/current/userguide/configuration_cache.html#config_cache:secrets
3144 lateinit var githubPublishToken: String
3245
3346 override fun configure (
34- project : Project ,
35- version : String ,
36- uploadTask : TaskProvider <Task >,
37- kmmPublishTask : TaskProvider <Task >
47+ project : Project , version : String , uploadTask : TaskProvider <Task >, kmmPublishTask : TaskProvider <Task >
3848 ) {
3949 this .releaseVersion = releaseString ? : project.version.toString()
4050 this .repoName = this .repository ? : project.githubRepo
4151 this .githubPublishToken = project.githubPublishToken
4252 this .frameworkName = project.kmmBridgeExtension.frameworkName.get()
53+ artifactReleaseId = project.githubArtifactReleaseId?.toInt() ? : 0
54+ this .artifactIdentifierName = project.githubArtifactIdentifierName ? : " "
4355 }
4456
4557 override fun deployArtifact (task : Task , zipFilePath : File , version : String ): String {
46- val existingReleaseId = GithubCalls .findReleaseId(
47- githubPublishToken, repoName, releaseVersion
48- )
58+ val uploadReleaseId = if (artifactReleaseId == 0 ) {
59+ val existingReleaseId = GithubCalls .findReleaseId(
60+ githubPublishToken, repoName, releaseVersion
61+ )
4962
50- task.logger.info(" existingReleaseId: $existingReleaseId " )
63+ task.logger.info(" existingReleaseId: $existingReleaseId " )
5164
52- if (existingReleaseId != null && ! useExistingRelease) {
53- throw GradleException (" Release for '$releaseVersion ' exists. Set 'useExistingRelease = true' to update existing releases." )
54- }
65+ if (existingReleaseId != null && ! useExistingRelease) {
66+ throw GradleException (" Release for '$releaseVersion ' exists. Set 'useExistingRelease = true' to update existing releases." )
67+ }
5568
56- val idReply: Int = existingReleaseId ? : GithubCalls .createRelease(
57- githubPublishToken, repoName, releaseVersion, null
58- )
69+ val idReply: Int = existingReleaseId ? : GithubCalls .createRelease(
70+ githubPublishToken, repoName, releaseVersion, null
71+ )
5972
60- task.logger.info(" GitHub Release created with id: $idReply " )
73+ task.logger.info(" GitHub Release created with id: $idReply " )
74+
75+ idReply
76+ } else {
77+ artifactReleaseId
78+ }
6179
6280 val fileName = artifactName(version, useExistingRelease)
6381
64- val uploadUrl = GithubCalls .uploadZipFile(githubPublishToken, zipFilePath, repoName, idReply , fileName)
82+ val uploadUrl = GithubCalls .uploadZipFile(githubPublishToken, zipFilePath, repoName, uploadReleaseId , fileName)
6583 return " ${uploadUrl} .zip"
6684 }
6785
6886 private fun artifactName (versionString : String , useExistingRelease : Boolean ): String {
6987 return if (useExistingRelease) {
7088 " $frameworkName -${versionString} -${(System .currentTimeMillis() / 1000 )} .xcframework.zip"
7189 } else {
72- " $frameworkName .xcframework.zip "
90+ uploadZipFileName(versionString)
7391 }
7492 }
93+
94+ open fun uploadZipFileName (versionString : String ) = if (artifactIdentifierName.isNotEmpty()) {
95+ " $frameworkName -${artifactIdentifierName} .xcframework.zip"
96+ } else {
97+ " $frameworkName .xcframework.zip"
98+ }
7599}
76100
77101internal val Project .kmmBridgeExtension get() = extensions.getByType<KmmBridgeExtension >()
0 commit comments