Skip to content

Commit ecfdbf7

Browse files
committed
Remove tag trick and cleanup
1 parent 37a357f commit ecfdbf7

File tree

12 files changed

+85
-138
lines changed

12 files changed

+85
-138
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ org.gradle.jvmargs=-Xmx4g
1818
#RELEASE_SIGNING_ENABLED=false
1919

2020
GROUP=co.touchlab.kmmbridge
21-
VERSION_NAME=1.0.4-SNAPSHOT
21+
VERSION_NAME=1.0.5-SNAPSHOT
2222
VERSION_NAME_3x=0.3.7
2323

2424
POM_URL=https://github.com/touchlab/KMMBridge

kmmbridge/src/main/kotlin/BuildFileHelper.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
* the License.
1212
*/
1313

14-
import co.touchlab.faktory.internal.githubPublishTokenOrNull
15-
import co.touchlab.faktory.internal.githubPublishUser
16-
import co.touchlab.faktory.internal.githubRepoOrNull
14+
import co.touchlab.faktory.internal.gitLabDomain
1715
import co.touchlab.faktory.internal.gitLabPublishTokenOrNull
1816
import co.touchlab.faktory.internal.gitLabPublishUser
1917
import co.touchlab.faktory.internal.gitLabRepoOrNull
20-
import co.touchlab.faktory.internal.gitLabDomain
18+
import co.touchlab.faktory.internal.githubPublishTokenOrNull
19+
import co.touchlab.faktory.internal.githubPublishUser
20+
import co.touchlab.faktory.internal.githubRepoOrNull
2121
import co.touchlab.faktory.publishingExtension
2222
import org.gradle.api.Project
2323
import org.gradle.api.credentials.HttpHeaderCredentials

kmmbridge/src/main/kotlin/co/touchlab/faktory/KMMBridge.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class KMMBridgePlugin : Plugin<Project> {
4545
afterEvaluate {
4646
configureXcFramework()
4747
configureLocalDev()
48-
if(enablePublishing) {
48+
if (enablePublishing) {
4949
configureArtifactManagerAndDeploy()
5050
}
5151
}
@@ -68,7 +68,8 @@ class KMMBridgePlugin : Plugin<Project> {
6868
val extension = kmmBridgeExtension
6969
var xcFrameworkConfig: XCFrameworkConfig? = null
7070

71-
val spmBuildTargets: Set<String> = project.spmBuildTargets?.split(",")?.map { it.trim() }?.filter { it.isNotEmpty() }?.toSet() ?: emptySet()
71+
val spmBuildTargets: Set<String> =
72+
project.spmBuildTargets?.split(",")?.map { it.trim() }?.filter { it.isNotEmpty() }?.toSet() ?: emptySet()
7273

7374
kotlin.targets
7475
.withType<KotlinNativeTarget>()
@@ -84,8 +85,9 @@ class KMMBridgePlugin : Plugin<Project> {
8485
throw IllegalStateException("Only one framework name currently allowed. Found $currentName and $theName")
8586
}
8687
}
87-
val shouldAddTarget = spmBuildTargets.isEmpty() || spmBuildTargets.contains(framework.target.konanTarget.name)
88-
if(shouldAddTarget) {
88+
val shouldAddTarget =
89+
spmBuildTargets.isEmpty() || spmBuildTargets.contains(framework.target.konanTarget.name)
90+
if (shouldAddTarget) {
8991
if (xcFrameworkConfig == null) {
9092
xcFrameworkConfig = XCFramework(theName)
9193
}

kmmbridge/src/main/kotlin/co/touchlab/faktory/KmmBridgeExtension.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ interface KmmBridgeExtension {
7979
* the name in here.
8080
*/
8181
@Suppress("unused")
82-
fun Project.mavenPublishArtifacts(repository: String? = null, publication: String? = null, artifactSuffix: String? = null) {
82+
fun Project.mavenPublishArtifacts(
83+
repository: String? = null,
84+
publication: String? = null,
85+
artifactSuffix: String? = null
86+
) {
8387
artifactManager.setAndFinalize(MavenPublishArtifactManager(this, publication, artifactSuffix, repository))
8488
}
8589

@@ -99,7 +103,13 @@ interface KmmBridgeExtension {
99103
swiftToolVersion: String = SwiftToolVersion.Default,
100104
targetPlatforms: TargetPlatformDsl.() -> Unit = { iOS { v("13") } },
101105
) {
102-
val dependencyManager = SpmDependencyManager(spmDirectory, useCustomPackageFile, perModuleVariablesBlock, swiftToolVersion, targetPlatforms)
106+
val dependencyManager = SpmDependencyManager(
107+
spmDirectory,
108+
useCustomPackageFile,
109+
perModuleVariablesBlock,
110+
swiftToolVersion,
111+
targetPlatforms
112+
)
103113
dependencyManagers.set(dependencyManagers.getOrElse(emptyList()) + dependencyManager)
104114
localDevManager.setAndFinalize(dependencyManager)
105115
}

kmmbridge/src/main/kotlin/co/touchlab/faktory/StringExtensions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package co.touchlab.faktory
22

3-
import java.util.Locale
3+
import java.util.*
44

55
fun String.capitalized(): String {
66
return this.replaceFirstChar {

kmmbridge/src/main/kotlin/co/touchlab/faktory/artifactmanager/ArtifactManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ interface ArtifactManager {
3939
/**
4040
* Run after file written. This is essentially for GitHub releases.
4141
*/
42-
fun finishArtifact(project: Project, version: String, dependencyManagers:List<DependencyManager>) {}
42+
fun finishArtifact(project: Project, version: String, dependencyManagers: List<DependencyManager>) {}
4343
}

kmmbridge/src/main/kotlin/co/touchlab/faktory/artifactmanager/GithubReleaseArtifactManager.kt

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
package co.touchlab.faktory.artifactmanager
22

3-
import co.touchlab.faktory.dependencymanager.DependencyManager
4-
import co.touchlab.faktory.dependencymanager.SpmDependencyManager
53
import co.touchlab.faktory.internal.GithubCalls
64
import co.touchlab.faktory.internal.githubRepo
7-
import co.touchlab.faktory.internal.procRunFailLog
8-
import co.touchlab.faktory.internal.skipGitHumReleaseSpmChecks
95
import co.touchlab.faktory.kmmBridgeExtension
106
import org.gradle.api.GradleException
117
import org.gradle.api.Project
128
import java.io.File
13-
import java.util.*
149

1510
class GithubReleaseArtifactManager(
1611
private val repository: String?, private val releaseString: String?, private val useExistingRelease: Boolean
@@ -36,86 +31,6 @@ class GithubReleaseArtifactManager(
3631
val uploadUrl = GithubCalls.uploadZipFile(project, zipFilePath, repoName, idReply, fileName)
3732
return "${uploadUrl}.zip"
3833
}
39-
40-
override fun finishArtifact(project: Project, version: String, dependencyManagers: List<DependencyManager>) {
41-
val needsSpmReleaseTagUpdate = dependencyManagers.any { it is SpmDependencyManager }
42-
if (needsSpmReleaseTagUpdate) {
43-
44-
val gitCommonDir = project.procRunFailLog("git", "rev-parse", "--git-common-dir").first().trim()
45-
project.logger.warn("gitCommonDir: $gitCommonDir")
46-
val trimmedPath = gitCommonDir.substring(0, gitCommonDir.length - ".git".length)
47-
val repoHomeDir = if (trimmedPath.isEmpty()) {
48-
null
49-
} else {
50-
File(trimmedPath)
51-
}
52-
53-
project.logger.warn("Running git diff")
54-
val diffResult = project.procRunFailLog("git", "diff", "--name-only", dir = repoHomeDir)
55-
56-
val skipCheck = project.skipGitHumReleaseSpmChecks
57-
if (!skipCheck) {
58-
// We *usually* expect one file in the diff, which is the Package.swift file. However, if the repo does
59-
// not already have a local-dev Package.swift file being tracked, git diff doesn't see the new file.
60-
// To be extra safe, at some point we should check that the Package.swift file was actually written,
61-
// but this should at least help pinpoint issues from GitHub Actions logs.
62-
val expectedResult = diffResult.size == 1 && diffResult.first().contains("Package.swift")
63-
if (!expectedResult) {
64-
project.logger.warn("Normally we'd expect a single Package.swift in the git diff. If you do not have Package.swift in your main branch, ignore this warning.")
65-
66-
if (diffResult.size > 1) {
67-
project.logger.error("Failing spm check. To disable this check add SKIP_GITHUB_RELEASE_SPM_CHECKS=true to your Gradle properties or pass the Gradle property in on the command line.")
68-
throw GradleException(
69-
"git diff should be one file. Multiple found: ${
70-
diffResult.joinToString(
71-
"\n"
72-
) { " --|$it" }
73-
}"
74-
)
75-
}
76-
}
77-
}
78-
79-
val tempBranch = UUID.randomUUID().toString()
80-
81-
// Get the tag created by the GitHub release
82-
project.logger.warn("Running git fetch")
83-
project.procRunFailLog("git", "fetch", "--tags", dir = repoHomeDir)
84-
85-
86-
// Create a local branch. We don't need to delete is as we just need the commit ref.
87-
project.logger.warn("Running git checkout new branch")
88-
project.procRunFailLog("git", "checkout", "-b", tempBranch, dir = repoHomeDir)
89-
90-
// Add and commit
91-
project.logger.warn("Running git add")
92-
project.procRunFailLog("git", "add", ".", dir = repoHomeDir)
93-
94-
project.logger.warn("Running git commit")
95-
project.procRunFailLog("git", "commit", "-m", "KMP SPM package release for $version", dir = repoHomeDir)
96-
97-
// Force-update the tag created by the GitHub release
98-
project.logger.warn("Running git tag")
99-
project.procRunFailLog(
100-
"git",
101-
"tag",
102-
"-fa",
103-
version,
104-
"-m",
105-
"KMP release version $version", dir = repoHomeDir
106-
)
107-
108-
// Force-push the tag reference. This will push the tag and commit.
109-
project.logger.warn("Running git push")
110-
project.procRunFailLog(
111-
"git",
112-
"push",
113-
"origin",
114-
"-f",
115-
"refs/tags/${version}", dir = repoHomeDir
116-
)
117-
}
118-
}
11934
}
12035

12136
private fun artifactName(project: Project, versionString: String, useExistingRelease: Boolean): String {

kmmbridge/src/main/kotlin/co/touchlab/faktory/artifactmanager/MavenPublishArtifactManager.kt

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class MavenPublishArtifactManager(
2222
private val publicationName: String?,
2323
artifactSuffix: String?,
2424
private val repositoryName: String?,
25-
) : ArtifactManager {
25+
) : ArtifactManager {
2626
private val group: String = project.group.toString().replace(".", "/")
2727
private val kmmbridgeArtifactId = "${project.name}-${artifactSuffix ?: KMMBRIDGE_ARTIFACT_SUFFIX}"
2828

@@ -32,7 +32,10 @@ class MavenPublishArtifactManager(
3232
uploadTask: TaskProvider<Task>,
3333
kmmPublishTask: TaskProvider<Task>
3434
) {
35-
project.publishingExtension.publications.create(publicationName ?: FRAMEWORK_PUBLICATION_NAME, MavenPublication::class.java) {
35+
project.publishingExtension.publications.create(
36+
publicationName ?: FRAMEWORK_PUBLICATION_NAME,
37+
MavenPublication::class.java
38+
) {
3639
this.version = version
3740
val archiveProvider = project.tasks.named("zipXCFramework", Zip::class.java).flatMap {
3841
it.archiveFile
@@ -54,8 +57,7 @@ class MavenPublishArtifactManager(
5457
dependsOn(kmmPublishTask)
5558
}
5659
}
57-
}
58-
catch(_: UnknownTaskException) {
60+
} catch (_: UnknownTaskException) {
5961
project.logger.warn("Gradle publish task not found")
6062
}
6163
}
@@ -98,18 +100,20 @@ class MavenPublishArtifactManager(
98100
repositoryName?.let {
99101
publishingExtension.repositories.findByName(it) as MavenArtifactRepository
100102
} ?: publishingExtension.repositories.filterIsInstance<MavenArtifactRepository>().firstOrNull()
101-
?: throw GradleException("Artifact repository not found, please, specify maven repository\n" +
102-
"publishing {\n" +
103-
" repositories {\n" +
104-
" maven {\n" +
105-
" url = uri(\"https://someservice/path/to/repo\")\n" +
106-
" credentials {\n" +
107-
" username = publishUsername\n" +
108-
" password = publishPassword\n" +
109-
" }\n" +
110-
" }\n" +
111-
" }\n" +
112-
"}")
103+
?: throw GradleException(
104+
"Artifact repository not found, please, specify maven repository\n" +
105+
"publishing {\n" +
106+
" repositories {\n" +
107+
" maven {\n" +
108+
" url = uri(\"https://someservice/path/to/repo\")\n" +
109+
" credentials {\n" +
110+
" username = publishUsername\n" +
111+
" password = publishPassword\n" +
112+
" }\n" +
113+
" }\n" +
114+
" }\n" +
115+
"}"
116+
)
113117

114118
private fun artifactPath(url: String, version: String) =
115119
"$url/$group/$kmmbridgeArtifactId/$version/$kmmbridgeArtifactId-$version.zip"

kmmbridge/src/main/kotlin/co/touchlab/faktory/dependencymanager/CocoapodsDependencyManager.kt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@
1313

1414
package co.touchlab.faktory.dependencymanager
1515

16-
import co.touchlab.faktory.*
16+
import co.touchlab.faktory.TASK_GROUP_NAME
17+
import co.touchlab.faktory.cocoapods
1718
import co.touchlab.faktory.internal.procRunFailLog
19+
import co.touchlab.faktory.kmmBridgeExtension
1820
import co.touchlab.faktory.kotlin
21+
import co.touchlab.faktory.layoutBuildDir
22+
import co.touchlab.faktory.urlFile
1923
import org.gradle.api.Action
2024
import org.gradle.api.Project
2125
import org.gradle.api.Task
@@ -58,7 +62,7 @@ class CocoapodsDependencyManager(
5862
dependsOn(generatePodspecTask)
5963

6064
@Suppress("ObjectLiteralToLambda")
61-
doLast(object : Action<Task>{
65+
doLast(object : Action<Task> {
6266
override fun execute(t: Task) {
6367
val extras = mutableListOf<String>()
6468

@@ -73,8 +77,16 @@ class CocoapodsDependencyManager(
7377
when (val specRepo = specRepoDeferred()) {
7478
is SpecRepo.Trunk ->
7579
project.procRunFailLog("pod", "trunk", "push", podSpecFile, *extras.toTypedArray())
80+
7681
is SpecRepo.Private ->
77-
project.procRunFailLog("pod", "repo", "push", specRepo.url, podSpecFile, *extras.toTypedArray())
82+
project.procRunFailLog(
83+
"pod",
84+
"repo",
85+
"push",
86+
specRepo.url,
87+
podSpecFile,
88+
*extras.toTypedArray()
89+
)
7890
}
7991
}
8092
})

kmmbridge/src/main/kotlin/co/touchlab/faktory/dependencymanager/SpmDependencyManager.kt

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
3737
import java.io.ByteArrayOutputStream
3838
import java.io.File
3939
import java.nio.charset.Charset
40-
import java.util.Locale
40+
import java.util.*
4141

4242
class SpmDependencyManager(
4343
/**
@@ -139,7 +139,8 @@ class SpmDependencyManager(
139139
platforms: String
140140
) {
141141
val swiftPackageFile = file(swiftPackageFilePath())
142-
val packageText = makePackageFileText(packageName, url, checksum, perModuleVariablesBlock, swiftToolVersion, platforms)
142+
val packageText =
143+
makePackageFileText(packageName, url, checksum, perModuleVariablesBlock, swiftToolVersion, platforms)
143144
swiftPackageFile.parentFile.mkdirs()
144145
swiftPackageFile.writeText(packageText)
145146
}
@@ -189,7 +190,7 @@ class SpmDependencyManager(
189190
doLast(object : Action<Task> {
190191
override fun execute(t: Task) {
191192
val swiftToolVersion = SwiftToolVersion.of(_swiftToolVersion)
192-
?: throw IllegalArgumentException("Parameter swiftToolVersion should be not blank!")
193+
?: throw IllegalArgumentException("Parameter swiftToolVersion should be not blank!")
193194

194195
val targetPlatforms = TargetPlatformDsl().apply(_targetPlatforms)
195196
.targetPlatforms
@@ -213,17 +214,18 @@ class SpmDependencyManager(
213214
}
214215
}
215216

216-
private fun platforms(project: Project, targetPlatforms: List<TargetPlatform>): String = targetPlatforms.flatMap { platform ->
217-
project.kotlin.targets
218-
.withType<KotlinNativeTarget>()
219-
.asSequence()
220-
.filter { it.konanTarget.family.isAppleFamily }
221-
.filter { appleTarget -> platform.targets.firstOrNull { it.konanTarget == appleTarget.konanTarget } != null }
222-
.mapNotNull { it.konanTarget.family.swiftPackagePlatformName }
223-
.distinct()
224-
.map { platformName -> ".$platformName(.v${platform.version.name})" }
225-
.toList()
226-
}.joinToString(separator = ",\n")
217+
private fun platforms(project: Project, targetPlatforms: List<TargetPlatform>): String =
218+
targetPlatforms.flatMap { platform ->
219+
project.kotlin.targets
220+
.withType<KotlinNativeTarget>()
221+
.asSequence()
222+
.filter { it.konanTarget.family.isAppleFamily }
223+
.filter { appleTarget -> platform.targets.firstOrNull { it.konanTarget == appleTarget.konanTarget } != null }
224+
.mapNotNull { it.konanTarget.family.swiftPackagePlatformName }
225+
.distinct()
226+
.map { platformName -> ".$platformName(.v${platform.version.name})" }
227+
.toList()
228+
}.joinToString(separator = ",\n")
227229
}
228230

229231
internal fun stripEndSlash(path: String): String {

kmmbridge/src/main/kotlin/co/touchlab/faktory/internal/GithubCalls.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ object GithubCalls {
4545
return gson.fromJson(okHttpClient.newCall(createRequest).execute().body!!.string(), IdReply::class.java).id
4646
}
4747

48-
fun uploadZipFile(project: Project, zipFilePath: File, repo:String, releaseId: Int, fileName: String):String{
48+
fun uploadZipFile(project: Project, zipFilePath: File, repo: String, releaseId: Int, fileName: String): String {
4949
val gson = Gson()
5050
val token = project.githubPublishToken
5151
val body: RequestBody = zipFilePath.asRequestBody("application/zip".toMediaTypeOrNull())
@@ -67,9 +67,11 @@ object GithubCalls {
6767
return gson.fromJson(uploadResponseString, UploadReply::class.java).url
6868
}
6969

70-
fun findReleaseId(project: Project,
71-
repoName: String,
72-
artifactReleaseTag: String): Int?{
70+
fun findReleaseId(
71+
project: Project,
72+
repoName: String,
73+
artifactReleaseTag: String
74+
): Int? {
7375
val token = project.githubPublishToken
7476
val request: Request =
7577
Request.Builder().url("https://api.github.com/repos/${repoName}/releases/tags/${artifactReleaseTag}").get()

0 commit comments

Comments
 (0)