@@ -7,23 +7,24 @@ import co.touchlab.kmmbridge.github.internal.githubArtifactIdentifierName
77import co.touchlab.kmmbridge.github.internal.githubArtifactReleaseId
88import co.touchlab.kmmbridge.github.internal.githubPublishToken
99import co.touchlab.kmmbridge.github.internal.githubRepo
10+ import java.io.File
11+ import kotlin.properties.Delegates
1012import org.gradle.api.GradleException
1113import org.gradle.api.Project
1214import org.gradle.api.Task
1315import org.gradle.api.tasks.Input
1416import org.gradle.api.tasks.TaskProvider
1517import org.gradle.kotlin.dsl.getByType
16- import java.io.File
17- import kotlin.properties.Delegates
1818
1919open class GithubReleaseArtifactManager (
2020 private val repository : String? ,
2121 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
22+ @Deprecated(
23+ " Releases should be created externally. This parameter controls the flow for releases created " +
24+ " by this class, which will eventually be unsupported." ,
25+ )
26+ private val useExistingRelease : Boolean ,
2527) : ArtifactManager {
26-
2728 @get:Input
2829 lateinit var releaseVersion: String
2930
@@ -43,9 +44,7 @@ open class GithubReleaseArtifactManager(
4344 // https://docs.gradle.org/current/userguide/configuration_cache.html#config_cache:secrets
4445 lateinit var githubPublishToken: String
4546
46- override fun configure (
47- project : Project , version : String , uploadTask : TaskProvider <Task >, kmmPublishTask : TaskProvider <Task >
48- ) {
47+ override fun configure (project : Project , version : String , uploadTask : TaskProvider <Task >, kmmPublishTask : TaskProvider <Task >) {
4948 this .releaseVersion = releaseString ? : project.version.toString()
5049 this .repoName = this .repository ? : project.githubRepo
5150 this .githubPublishToken = project.githubPublishToken
@@ -55,47 +54,55 @@ open class GithubReleaseArtifactManager(
5554 }
5655
5756 override fun deployArtifact (task : Task , zipFilePath : File , version : String ): String {
58- val uploadReleaseId = if (artifactReleaseId == 0 ) {
59- val existingReleaseId = GithubCalls .findReleaseId(
60- githubPublishToken, repoName, releaseVersion
61- )
62-
63- task.logger.info(" existingReleaseId: $existingReleaseId " )
64-
65- if (existingReleaseId != null && ! useExistingRelease) {
66- throw GradleException (" Release for '$releaseVersion ' exists. Set 'useExistingRelease = true' to update existing releases." )
57+ val uploadReleaseId =
58+ if (artifactReleaseId == 0 ) {
59+ val existingReleaseId =
60+ GithubCalls .findReleaseId(
61+ githubPublishToken,
62+ repoName,
63+ releaseVersion,
64+ )
65+
66+ task.logger.info(" existingReleaseId: $existingReleaseId " )
67+
68+ if (existingReleaseId != null && ! useExistingRelease) {
69+ throw GradleException (
70+ " Release for '$releaseVersion ' exists. Set 'useExistingRelease = true' to update existing releases." ,
71+ )
72+ }
73+
74+ val idReply: Int =
75+ existingReleaseId ? : GithubCalls .createRelease(
76+ githubPublishToken,
77+ repoName,
78+ releaseVersion,
79+ null ,
80+ )
81+
82+ task.logger.info(" GitHub Release created with id: $idReply " )
83+
84+ idReply
85+ } else {
86+ artifactReleaseId
6787 }
6888
69- val idReply: Int = existingReleaseId ? : GithubCalls .createRelease(
70- githubPublishToken, repoName, releaseVersion, null
71- )
72-
73- task.logger.info(" GitHub Release created with id: $idReply " )
74-
75- idReply
76- } else {
77- artifactReleaseId
78- }
79-
8089 val fileName = artifactName(version, useExistingRelease)
8190
8291 val uploadUrl = GithubCalls .uploadZipFile(githubPublishToken, zipFilePath, repoName, uploadReleaseId, fileName)
83- return " ${ uploadUrl} .zip"
92+ return " $uploadUrl .zip"
8493 }
8594
86- private fun artifactName (versionString : String , useExistingRelease : Boolean ): String {
87- return if (useExistingRelease) {
88- " $frameworkName -${versionString} -${(System .currentTimeMillis() / 1000 )} .xcframework.zip"
89- } else {
90- uploadZipFileName(versionString)
91- }
95+ private fun artifactName (versionString : String , useExistingRelease : Boolean ): String = if (useExistingRelease) {
96+ " $frameworkName -$versionString -${(System .currentTimeMillis() / 1000 )} .xcframework.zip"
97+ } else {
98+ uploadZipFileName(versionString)
9299 }
93100
94101 open fun uploadZipFileName (versionString : String ) = if (artifactIdentifierName.isNotEmpty()) {
95- " $frameworkName -${ artifactIdentifierName} .xcframework.zip"
102+ " $frameworkName -$artifactIdentifierName .xcframework.zip"
96103 } else {
97104 " $frameworkName .xcframework.zip"
98105 }
99106}
100107
101- internal val Project .kmmBridgeExtension get() = extensions.getByType<KmmBridgeExtension >()
108+ internal val Project .kmmBridgeExtension get() = extensions.getByType<KmmBridgeExtension >()
0 commit comments