Skip to content

Commit edcc041

Browse files
Kpg/split GitHub (#265)
* Start work on configuration cache * Updated config cache stuff * Reformat code * Version 1.1.0 prep * Save everything compiling * Major cleanup * Update gradle.properties * Renamed faktory to kmmbridge * Remove old website and minor refactoring * Minor refactor * Move GitHub to a separate plugin and module * Extract GitLab integration * Remove website deploy workflow --------- Co-authored-by: Kevin Schildhorn <kevin.schildhorn@gmail.com>
1 parent fd8ad5b commit edcc041

File tree

170 files changed

+732
-31374
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

170 files changed

+732
-31374
lines changed

.github/workflows/websitedeploy.yml

Lines changed: 0 additions & 79 deletions
This file was deleted.

RELEASING.md

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,3 @@
11
# Releasing
22

3-
Notes for releasing KMMBridge versions. There are some integration tests that we only run on releases, as they're
4-
rather long-running. Also, we need to make sure to review and update any supported samples.
53

6-
Review when introducing **usage changes**:
7-
8-
* [KMMBridgeKickStart](https://github.com/touchlab/KMMBridgeKickStart) - Kick Start
9-
* [KMMBridgeSampleKotlin](https://github.com/touchlab/KMMBridgeSampleKotlin) - Shared Kotlin code
10-
* [KMMBridgeSampleSpm](https://github.com/touchlab/KMMBridgeSampleSpm) - Xcode example with SPM
11-
* [KMMBridgeSampleCocoaPods](https://github.com/touchlab/KMMBridgeSampleCocoaPods) - Xcode example with CocoaPods
12-
* [PublicPodspecs](https://github.com/touchlab/PublicPodspecs) - Public CocoaPods podspec repo
13-
* [1 hour tutorial](https://touchlab.co/quick-start-with-kmmbridge-1-hour-tutorial/) - Tutorial for using KMMBridge
14-
- [Samples of using blog post](https://touchlab.co/samples-of-using-kmmbridge/) - Blog post describing KMMBridge usage in Samples
15-
- [Introducing KMMBRidge blog post](https://touchlab.co/introducing-kmmbridge-teams/) - Introduction of KMMBridge blog post
16-
- [KMMBridge readme](README.md) - readme of this project
17-
- [KMMBridge website](website/docs/index.md) - KMMBridge documentation
18-
19-
Update when releasing **new version number**:
20-
21-
* `libs.versions.toml` in [KMMBridgeKickStart](https://github.com/touchlab/KMMBridgeKickStart) - Kick Start
22-
* `build.gradle.kts` in `shared` module in [KMMBridgeSampleKotlin](https://github.com/touchlab/KMMBridgeSampleKotlin) - Shared Kotlin code

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.1
21+
VERSION_NAME=1.1.0-SNAPSHOT
2222
VERSION_NAME_3x=0.3.7
2323

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

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[versions]
2-
kotlin = "1.9.22"
2+
kotlin = "2.0.20"
33
mavenPublish = "0.29.0"
44

55
[libraries]

kmmbridge-github/build.gradle.kts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
@file:Suppress("PropertyName")
2+
3+
/*
4+
* Copyright (c) 2024 Touchlab.
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
6+
* in compliance with the License. You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software distributed under the License
11+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12+
* or implied. See the License for the specific language governing permissions and limitations under
13+
* the License.
14+
*/
15+
16+
plugins {
17+
`kotlin-dsl`
18+
kotlin("jvm")
19+
id("org.jetbrains.kotlin.plugin.allopen")
20+
id("java-gradle-plugin")
21+
id("com.vanniktech.maven.publish.base")
22+
id("com.gradle.plugin-publish") version "1.0.0"
23+
}
24+
25+
repositories {
26+
gradlePluginPortal()
27+
mavenCentral()
28+
}
29+
30+
@Suppress("UnstableApiUsage")
31+
gradlePlugin {
32+
website = "https://github.com/touchlab/KMMBridge"
33+
vcsUrl = "https://github.com/touchlab/KMMBridge.git"
34+
description =
35+
"KMMBridge is a set of Gradle tooling that facilitates publishing and consuming pre-built KMM (Kotlin Multiplatform Mobile) Xcode Framework binaries."
36+
plugins {
37+
register("kmmbridge-github-plugin") {
38+
id = "co.touchlab.kmmbridge.github"
39+
implementationClass = "co.touchlab.kmmbridge.KMMBridgePlugin"
40+
displayName = "KMMBridge/GitHub for Teams"
41+
tags = listOf(
42+
"kmm",
43+
"kotlin",
44+
"multiplatform",
45+
"mobile",
46+
"ios",
47+
"xcode",
48+
"framework",
49+
"binary",
50+
"publish",
51+
"consume"
52+
)
53+
}
54+
}
55+
}
56+
57+
dependencies {
58+
implementation(kotlin("stdlib"))
59+
implementation(libs.okhttp)
60+
implementation(libs.gson)
61+
api(project(":kmmbridge"))
62+
63+
testImplementation(kotlin("test"))
64+
}
65+
66+
kotlin {
67+
jvmToolchain(11)
68+
}
69+
70+
val GROUP: String by project
71+
val VERSION_NAME: String by project
72+
73+
group = GROUP
74+
version = VERSION_NAME
75+
76+
mavenPublishing {
77+
publishToMavenCentral()
78+
val releaseSigningEnabled =
79+
project.properties["RELEASE_SIGNING_ENABLED"]?.toString()?.equals("false", ignoreCase = true) != true
80+
if (releaseSigningEnabled) signAllPublications()
81+
@Suppress("UnstableApiUsage")
82+
pomFromGradleProperties()
83+
configureBasedOnAppliedPlugins()
84+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import co.touchlab.kmmbridge.KmmBridgeExtension
2+
import co.touchlab.kmmbridge.github.GithubReleaseArtifactManager
3+
import co.touchlab.kmmbridge.github.internal.githubPublishTokenOrNull
4+
import co.touchlab.kmmbridge.github.internal.githubPublishUser
5+
import co.touchlab.kmmbridge.github.internal.githubRepoOrNull
6+
import co.touchlab.kmmbridge.github.kmmBridgeExtension
7+
import co.touchlab.kmmbridge.publishingExtension
8+
import org.gradle.api.Project
9+
import java.net.URI
10+
11+
@Suppress("unused")
12+
fun Project.gitHubReleaseArtifacts(
13+
repository: String? = null,
14+
releasString: String? = null,
15+
useExistingRelease: Boolean = false
16+
) {
17+
kmmBridgeExtension.setupGitHubReleaseArtifacts(
18+
GithubReleaseArtifactManager(
19+
repository,
20+
releasString,
21+
useExistingRelease
22+
)
23+
)
24+
}
25+
26+
private fun KmmBridgeExtension.setupGitHubReleaseArtifacts(
27+
githubReleaseArtifactManager: GithubReleaseArtifactManager
28+
) {
29+
artifactManager.setAndFinalize(githubReleaseArtifactManager)
30+
}
31+
32+
/**
33+
* Helper function to support GitHub Packages publishing. Use with https://github.com/touchlab/KMMBridgeGithubWorkflow
34+
* or pass in a valid GitHub token with GITHUB_PUBLISH_TOKEN. Defaults user to "cirunner", which can be overridden with
35+
* GITHUB_PUBLISH_USER.
36+
*
37+
* Generally, just add the following in the Gradle build file.
38+
*
39+
* addGithubPackagesRepository()
40+
*/
41+
@Suppress("unused")
42+
fun Project.addGithubPackagesRepository() {
43+
publishingExtension.apply {
44+
val githubPublishUser = project.githubPublishUser ?: "cirunner"
45+
val githubRepo = project.githubRepoOrNull ?: return
46+
val githubPublishToken = project.githubPublishTokenOrNull ?: return
47+
repositories.maven {
48+
name = "GitHubPackages"
49+
url = URI.create("https://maven.pkg.github.com/$githubRepo")
50+
credentials {
51+
username = githubPublishUser
52+
password = githubPublishToken
53+
}
54+
}
55+
}
56+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package co.touchlab.kmmbridge.github
2+
3+
import co.touchlab.kmmbridge.KmmBridgeExtension
4+
import co.touchlab.kmmbridge.artifactmanager.ArtifactManager
5+
import co.touchlab.kmmbridge.github.internal.GithubCalls
6+
import co.touchlab.kmmbridge.github.internal.githubPublishToken
7+
import co.touchlab.kmmbridge.github.internal.githubRepo
8+
import org.gradle.api.GradleException
9+
import org.gradle.api.Project
10+
import org.gradle.api.Task
11+
import org.gradle.api.tasks.Input
12+
import org.gradle.api.tasks.TaskProvider
13+
import org.gradle.kotlin.dsl.getByType
14+
import java.io.File
15+
16+
class GithubReleaseArtifactManager(
17+
private val repository: String?, private val releaseString: String?, private val useExistingRelease: Boolean
18+
) : ArtifactManager {
19+
20+
@get:Input
21+
lateinit var releaseVersion: String
22+
23+
@get:Input
24+
lateinit var repoName: String
25+
26+
@get:Input
27+
lateinit var frameworkName: String
28+
29+
// TODO: This value is stored in the config cache. It is encrypted, but this still feels insecure. Review alternatives.
30+
// https://docs.gradle.org/current/userguide/configuration_cache.html#config_cache:secrets
31+
lateinit var githubPublishToken: String
32+
33+
override fun configure(
34+
project: Project,
35+
version: String,
36+
uploadTask: TaskProvider<Task>,
37+
kmmPublishTask: TaskProvider<Task>
38+
) {
39+
this.releaseVersion = releaseString ?: project.version.toString()
40+
this.repoName = this.repository ?: project.githubRepo
41+
this.githubPublishToken = project.githubPublishToken
42+
this.frameworkName = project.kmmBridgeExtension.frameworkName.get()
43+
}
44+
45+
override fun deployArtifact(task: Task, zipFilePath: File, version: String): String {
46+
val existingReleaseId = GithubCalls.findReleaseId(
47+
githubPublishToken, repoName, releaseVersion
48+
)
49+
50+
task.logger.info("existingReleaseId: $existingReleaseId")
51+
52+
if (existingReleaseId != null && !useExistingRelease) {
53+
throw GradleException("Release for '$releaseVersion' exists. Set 'useExistingRelease = true' to update existing releases.")
54+
}
55+
56+
val idReply: Int = existingReleaseId ?: GithubCalls.createRelease(
57+
githubPublishToken, repoName, releaseVersion, null
58+
)
59+
60+
task.logger.info("GitHub Release created with id: $idReply")
61+
62+
val fileName = artifactName(version, useExistingRelease)
63+
64+
val uploadUrl = GithubCalls.uploadZipFile(githubPublishToken, zipFilePath, repoName, idReply, fileName)
65+
return "${uploadUrl}.zip"
66+
}
67+
68+
private fun artifactName(versionString: String, useExistingRelease: Boolean): String {
69+
return if (useExistingRelease) {
70+
"$frameworkName-${versionString}-${(System.currentTimeMillis() / 1000)}.xcframework.zip"
71+
} else {
72+
"$frameworkName.xcframework.zip"
73+
}
74+
}
75+
}
76+
77+
internal val Project.kmmBridgeExtension get() = extensions.getByType<KmmBridgeExtension>()

kmmbridge/src/main/kotlin/co/touchlab/faktory/internal/GithubApi.kt renamed to kmmbridge-github/src/main/kotlin/co/touchlab/kmmbridge/github/internal/GithubApi.kt

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

14-
package co.touchlab.faktory.internal
14+
package co.touchlab.kmmbridge.github.internal
1515

16-
import co.touchlab.faktory.findStringProperty
16+
import co.touchlab.kmmbridge.findStringProperty
1717
import org.gradle.api.Project
1818

1919
internal val Project.githubPublishTokenOrNull: String?
@@ -42,6 +42,6 @@ internal val Project.githubPublishToken
4242
get() = (project.property("GITHUB_PUBLISH_TOKEN")
4343
?: throw IllegalArgumentException("KMMBridge Github operations need property GITHUB_PUBLISH_TOKEN")) as String
4444

45-
internal val Project.githubRepo
46-
get() = (project.findStringProperty("GITHUB_REPO")
47-
?: throw IllegalArgumentException("KMMBridge Github operations need a repo param or property GITHUB_REPO"))
45+
internal val Project.githubRepo: String
46+
get() = githubRepoOrNull
47+
?: throw IllegalArgumentException("KMMBridge Github operations need a repo param or property GITHUB_REPO")

0 commit comments

Comments
 (0)