From a89d2f6c72dde1d7a187ca4f8cda778c99a8fc3a Mon Sep 17 00:00:00 2001 From: DominicGBauer Date: Mon, 19 Aug 2024 10:17:55 +0200 Subject: [PATCH 01/10] chore: add maven central deployment --- PowerSync/build.gradle.kts | 61 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/PowerSync/build.gradle.kts b/PowerSync/build.gradle.kts index db85e4bb..8169c7a4 100644 --- a/PowerSync/build.gradle.kts +++ b/PowerSync/build.gradle.kts @@ -7,6 +7,7 @@ plugins { alias(libs.plugins.kmmbridge) alias(libs.plugins.skie) alias(libs.plugins.mavenPublishPlugin) + signing } kotlin { @@ -46,6 +47,66 @@ skie { } } +group = "com.powersync" +description = "PowerSync KMM Bridge" + +publishing { + publications { + register("maven") { + groupId = project.group.toString() + artifactId = project.name + + pom { + name.set(project.name) + description.set(project.description) + url.set("https://github.com/powersync-ja/powersync-kotlin") + + developers { + developer { + id.set("journeyapps") + name.set("Journey Mobile, Inc.") + email.set("info@journeyapps.com") + } + } + + licenses { + license { + name.set("Apache License, Version 2.0") + url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") + } + } + + scm { + connection.set("scm:git:github.com/powersync-ja/powersync-kotlin.git") + developerConnection.set("scm:git:ssh://github.com/powersync-ja/powersync-kotlin.git") + url.set("https://github.com/powersync-ja/powersync-kotlin") + } + } + } + } + + val publishUsername= System.getenv("SONATYPE_USERNAME") + val publishPassword= System.getenv("SONATYPE_PASSWORD") + + repositories { + maven { + name = "sonatype" + url = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/") + credentials { + username = publishUsername + password = publishPassword + } + } + } +} + +signing { + val signingKey = System.getenv("SIGNING_KEY") + val signingPassword = System.getenv("SIGNING_PASSWORD") + useInMemoryPgpKeys(signingKey, signingPassword) + sign(publishing.publications) +} + kmmbridge { mavenPublishArtifacts() spm() From 56c4724029a1fe174a71c296ab9f518eb05f6b75 Mon Sep 17 00:00:00 2001 From: DominicGBauer Date: Tue, 20 Aug 2024 14:41:59 +0200 Subject: [PATCH 02/10] chore: sonaetype plugin --- PowerSync/build.gradle.kts | 62 +------------------------------------- 1 file changed, 1 insertion(+), 61 deletions(-) diff --git a/PowerSync/build.gradle.kts b/PowerSync/build.gradle.kts index 8169c7a4..d83d8a80 100644 --- a/PowerSync/build.gradle.kts +++ b/PowerSync/build.gradle.kts @@ -7,7 +7,7 @@ plugins { alias(libs.plugins.kmmbridge) alias(libs.plugins.skie) alias(libs.plugins.mavenPublishPlugin) - signing + id("com.powersync.plugins.sonatype") } kotlin { @@ -47,66 +47,6 @@ skie { } } -group = "com.powersync" -description = "PowerSync KMM Bridge" - -publishing { - publications { - register("maven") { - groupId = project.group.toString() - artifactId = project.name - - pom { - name.set(project.name) - description.set(project.description) - url.set("https://github.com/powersync-ja/powersync-kotlin") - - developers { - developer { - id.set("journeyapps") - name.set("Journey Mobile, Inc.") - email.set("info@journeyapps.com") - } - } - - licenses { - license { - name.set("Apache License, Version 2.0") - url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") - } - } - - scm { - connection.set("scm:git:github.com/powersync-ja/powersync-kotlin.git") - developerConnection.set("scm:git:ssh://github.com/powersync-ja/powersync-kotlin.git") - url.set("https://github.com/powersync-ja/powersync-kotlin") - } - } - } - } - - val publishUsername= System.getenv("SONATYPE_USERNAME") - val publishPassword= System.getenv("SONATYPE_PASSWORD") - - repositories { - maven { - name = "sonatype" - url = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/") - credentials { - username = publishUsername - password = publishPassword - } - } - } -} - -signing { - val signingKey = System.getenv("SIGNING_KEY") - val signingPassword = System.getenv("SIGNING_PASSWORD") - useInMemoryPgpKeys(signingKey, signingPassword) - sign(publishing.publications) -} - kmmbridge { mavenPublishArtifacts() spm() From 1bc0258aebe26e7941a228b198b80691826a8306 Mon Sep 17 00:00:00 2001 From: Manrich121 Date: Wed, 21 Aug 2024 11:38:29 +0200 Subject: [PATCH 03/10] wip: publish kmmbridget to sonatype portal --- PowerSync/build.gradle.kts | 77 +++++++++++++++++++++++++++++++++++++- gradle.properties | 2 +- gradle/libs.versions.toml | 2 +- 3 files changed, 77 insertions(+), 4 deletions(-) diff --git a/PowerSync/build.gradle.kts b/PowerSync/build.gradle.kts index d83d8a80..d1ccc068 100644 --- a/PowerSync/build.gradle.kts +++ b/PowerSync/build.gradle.kts @@ -1,3 +1,5 @@ +import co.touchlab.faktory.artifactmanager.ArtifactManager +import co.touchlab.faktory.capitalized import co.touchlab.faktory.versionmanager.TimestampVersionManager import co.touchlab.skie.configuration.SuspendInterop import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget @@ -48,12 +50,83 @@ skie { } kmmbridge { - mavenPublishArtifacts() + artifactManager.set(SonatypePortalPublishArtifactManager(project, null, null, null)) + artifactManager.finalizeValue() spm() - versionManager.set(TimestampVersionManager) } if (System.getenv().containsKey("CI")) { // Setup github publishing based on GitHub action variables addGithubPackagesRepository() +} + +class SonatypePortalPublishArtifactManager( + val project: Project, + private val publicationName: String?, + artifactSuffix: String?, + private val repositoryName: String?, +) : ArtifactManager { + private val FRAMEWORK_PUBLICATION_NAME = "KMMBridgeFramework" + private val KMMBRIDGE_ARTIFACT_SUFFIX = "kmmbridge" + private val group: String = project.group.toString().replace(".", "/") + private val kmmbridgeArtifactId = + "${project.name}-${artifactSuffix ?: KMMBRIDGE_ARTIFACT_SUFFIX}" + + override fun deployArtifact(project: Project, zipFilePath: File, version: String): String { + return "FOOBAR_URL" + } + + override fun configure( + project: Project, + version: String, + uploadTask: TaskProvider, + kmmPublishTask: TaskProvider + ) { + project.extensions.getByType().publications.create( + publicationName ?: FRAMEWORK_PUBLICATION_NAME, MavenPublication::class.java + ) { + this.version = version + val archiveProvider = project.tasks.named("zipXCFramework", Zip::class.java).flatMap { + it.archiveFile + } + artifact(archiveProvider) { + extension = "zip" + } + artifactId = kmmbridgeArtifactId + } + + publishingTasks().forEach { + uploadTask.configure { + dependsOn(it) + } + } + try { + project.tasks.named("publish").also { task -> + task.configure { + dependsOn(kmmPublishTask) + } + } + } catch (_: UnknownTaskException) { + project.logger.warn("Gradle publish task not found") + } + } + + private fun publishingTasks(): List> { + val publishingExtension = project.extensions.getByType() + + // Either the user has supplied a correct name, or we use the default. If neither is found, fail. + val publicationNameCap = + publishingExtension.publications.getByName( + publicationName ?: FRAMEWORK_PUBLICATION_NAME + ).name.capitalized() + + return publishingExtension.repositories.filterIsInstance() + .map { repo -> + val repositoryName = repo.name.capitalized() + val publishTaskName = + "publish${publicationNameCap}PublicationTo${repositoryName}Repository" + // Verify that the "publish" task exists before collecting + project.tasks.named(publishTaskName) + } + } } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 9ce10485..87f73095 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,7 +17,7 @@ development=true RELEASE_SIGNING_ENABLED=true # Library config GROUP=com.powersync -LIBRARY_VERSION=0.0.1-ALPHA15 +LIBRARY_VERSION=0.0.1-ALPHA16 GITHUB_REPO=https://github.com/powersync-ja/powersync-kotlin.git # POM POM_URL=https://github.com/powersync-ja/powersync-kotlin/ diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 422ce836..a293fa11 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -29,7 +29,7 @@ compose-compiler = "1.5.14" # plugins android-gradle-plugin = "8.5.1" -kmmBridge = "0.5.1" +kmmBridge = "0.5.7" skie = "0.8.2" maven-publish = "0.27.0" download-plugin = "5.5.0" From b9d652c6a2954557478281cc18b8280f130e81e5 Mon Sep 17 00:00:00 2001 From: Manrich121 Date: Wed, 21 Aug 2024 12:15:39 +0200 Subject: [PATCH 04/10] wip: publish kmmbridge add pom description, add xcodeproj to gitignore --- .gitignore | 1 + PowerSync/gradle.properties | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 2938a749..b65e157d 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ local.properties captures .externalNativeBuild **/.cxx +**/*.xcodeproj/* *.xcodeproj/* **/.swiftpm !*.xcodeproj/project.pbxproj diff --git a/PowerSync/gradle.properties b/PowerSync/gradle.properties index 4f78c2ff..47314b6b 100644 --- a/PowerSync/gradle.properties +++ b/PowerSync/gradle.properties @@ -1,3 +1,4 @@ # This needs to be lowercase otherwise there will be a 422 when publishing POM_ARTIFACT_ID=powersync -POM_NAME=PowerSync Swift Framework \ No newline at end of file +POM_NAME=PowerSync Swift Framework +POM_DESCRIPTION=A PowerSync Kotlin Multiplatform to iOS Swift Bridge. \ No newline at end of file From 00d17049cf1d9efcae5b9dc34a1af53cbaa5d54c Mon Sep 17 00:00:00 2001 From: DominicGBauer Date: Wed, 21 Aug 2024 14:24:44 +0200 Subject: [PATCH 05/10] chore: improvements --- compose/gradle.properties | 3 ++- .../powersync/plugins/sonatype/PublishToCentralPortalTask.kt | 5 +++-- .../powersync/plugins/sonatype/SonatypeCentralExtension.kt | 3 --- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/compose/gradle.properties b/compose/gradle.properties index b28deecd..fea7ee9e 100644 --- a/compose/gradle.properties +++ b/compose/gradle.properties @@ -1,2 +1,3 @@ POM_ARTIFACT_ID=compose -POM_NAME=PowerSync Compose Multiplatform factory \ No newline at end of file +POM_NAME=PowerSync Compose Multiplatform factory +POM_DESCRIPTION=A PowerSync Kotlin Multiplatform Compose Library for Android and iOS \ No newline at end of file diff --git a/plugins/sonatype/src/main/kotlin/com/powersync/plugins/sonatype/PublishToCentralPortalTask.kt b/plugins/sonatype/src/main/kotlin/com/powersync/plugins/sonatype/PublishToCentralPortalTask.kt index ac336bb4..32057658 100644 --- a/plugins/sonatype/src/main/kotlin/com/powersync/plugins/sonatype/PublishToCentralPortalTask.kt +++ b/plugins/sonatype/src/main/kotlin/com/powersync/plugins/sonatype/PublishToCentralPortalTask.kt @@ -16,6 +16,7 @@ import java.net.URISyntaxException import java.net.URLEncoder import java.nio.charset.StandardCharsets import java.util.Base64 + internal abstract class PublishToCentralPortalTask : DefaultTask() { @get:Input @get:Optional @@ -52,7 +53,7 @@ internal abstract class PublishToCentralPortalTask : DefaultTask() { "Missing PublishToCentralPortal's `password` and `${SonatypeCentralExtension.SONATYPE_PASSWORD_KEY}` value and `${SonatypeCentralExtension.SONATYPE_PASSWORD_KEY}` property" ) - val outputFile = this.outputFile(); + val outputFile = this.outputFile() val name = URLEncoder.encode( (project.group @@ -78,7 +79,7 @@ internal abstract class PublishToCentralPortalTask : DefaultTask() { out.write("\r\nContent-Type: application/octet-stream".toByteArray()) out.write("\r\n\r\n".toByteArray()) FileInputStream(outputFile).use { inputStream -> - val buffer: ByteArray = ByteArray(1024) + val buffer = ByteArray(1024) var available: Long = outputFile.length() while (available > 0) { val read: Int = inputStream.read( diff --git a/plugins/sonatype/src/main/kotlin/com/powersync/plugins/sonatype/SonatypeCentralExtension.kt b/plugins/sonatype/src/main/kotlin/com/powersync/plugins/sonatype/SonatypeCentralExtension.kt index ff47461a..8ed3eb24 100644 --- a/plugins/sonatype/src/main/kotlin/com/powersync/plugins/sonatype/SonatypeCentralExtension.kt +++ b/plugins/sonatype/src/main/kotlin/com/powersync/plugins/sonatype/SonatypeCentralExtension.kt @@ -1,9 +1,6 @@ package com.powersync.plugins.sonatype -import org.gradle.api.Action import org.gradle.api.Project -import org.gradle.api.artifacts.repositories.MavenArtifactRepository -import org.gradle.api.artifacts.repositories.PasswordCredentials import org.gradle.api.provider.Property import org.gradle.api.tasks.Optional import org.gradle.api.tasks.bundling.Zip From 750719494c330977386232316e975f389d9a572a Mon Sep 17 00:00:00 2001 From: DominicGBauer Date: Wed, 21 Aug 2024 16:00:56 +0200 Subject: [PATCH 06/10] chore: improvements --- .github/workflows/deploy.yml | 13 +++++++++++++ .github/workflows/publish-swift.yml | 1 + .gitignore | 3 +-- PowerSync/build.gradle.kts | 12 ++++++++++-- .../plugins/sonatype/SonatypeCentralExtension.kt | 2 +- 5 files changed, 26 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 04522322..fab47937 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -53,4 +53,17 @@ jobs: -PsigningInMemoryKeyPassword="${{ secrets.SIGNING_PASSWORD }}" \ -PcentralPortal.username="${{secrets.SONATYPE_USERNAME}}" \ -PcentralPortal.password="${{secrets.SONATYPE_PASSWORD}}" + # This will change Package.swift in Github packages to direct to new maven central KMMBridge zip file + call-kmmbridge-publish: + needs: deploy + permissions: + contents: write + packages: write + uses: touchlab/KMMBridgeGithubWorkflow/.github/workflows/faktorybuildautoversion.yml@v1.1 + with: + jvmVersion: 17 + versionBaseProperty: LIBRARY_VERSION + publishTask: kmmBridgePublish + secrets: + gradle_params: -PsigningInMemoryKey="${{ secrets.SIGNING_KEY }}" -PsigningInMemoryKeyId="${{ secrets.SIGNING_KEY_ID }}" -PsigningInMemoryKeyPassword="${{ secrets.SIGNING_PASSWORD }}" diff --git a/.github/workflows/publish-swift.yml b/.github/workflows/publish-swift.yml index 04900d13..d71db605 100644 --- a/.github/workflows/publish-swift.yml +++ b/.github/workflows/publish-swift.yml @@ -1,3 +1,4 @@ +# This can be deleted once we have verified that KMMBridge is successfully available to public name: Publish iOS Swift on: workflow_dispatch: diff --git a/.gitignore b/.gitignore index b65e157d..6a03e995 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,5 @@ captures !*.xcworkspace/contents.xcworkspacedata **/xcshareddata/WorkspaceSettings.xcsettings Pods/ -plugins/sonatype dialect/bin -.build \ No newline at end of file +.build diff --git a/PowerSync/build.gradle.kts b/PowerSync/build.gradle.kts index d1ccc068..e2a038d8 100644 --- a/PowerSync/build.gradle.kts +++ b/PowerSync/build.gradle.kts @@ -1,6 +1,5 @@ import co.touchlab.faktory.artifactmanager.ArtifactManager import co.touchlab.faktory.capitalized -import co.touchlab.faktory.versionmanager.TimestampVersionManager import co.touchlab.skie.configuration.SuspendInterop import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget @@ -55,11 +54,16 @@ kmmbridge { spm() } +// We need this so that when a user includes the package in XCode they are able to +// import the package using Github if (System.getenv().containsKey("CI")) { // Setup github publishing based on GitHub action variables addGithubPackagesRepository() } +// This is required for KMMBridge zip to be uploaded to Sonatype (Maven Central) +// and needs to be in this file as it requires access to import co.touchlab.faktory +// which is only available here class SonatypePortalPublishArtifactManager( val project: Project, private val publicationName: String?, @@ -71,9 +75,13 @@ class SonatypePortalPublishArtifactManager( private val group: String = project.group.toString().replace(".", "/") private val kmmbridgeArtifactId = "${project.name}-${artifactSuffix ?: KMMBRIDGE_ARTIFACT_SUFFIX}" + private val LIBRARY_VERSION: String by project + // This is the URL that will be added to Package.swift in Github package so that + // KMMBridge is downloaded when a user includes the package in XCode + private val MAVEN_CENTRAL_PACKAGE_ZIP_URL = "https://repo1.maven.org/maven2/com/powersync/${kmmbridgeArtifactId.lowercase()}/${LIBRARY_VERSION}/${kmmbridgeArtifactId.lowercase()}-${LIBRARY_VERSION}.zip" override fun deployArtifact(project: Project, zipFilePath: File, version: String): String { - return "FOOBAR_URL" + return MAVEN_CENTRAL_PACKAGE_ZIP_URL } override fun configure( diff --git a/plugins/sonatype/src/main/kotlin/com/powersync/plugins/sonatype/SonatypeCentralExtension.kt b/plugins/sonatype/src/main/kotlin/com/powersync/plugins/sonatype/SonatypeCentralExtension.kt index 8ed3eb24..ff14bcfe 100644 --- a/plugins/sonatype/src/main/kotlin/com/powersync/plugins/sonatype/SonatypeCentralExtension.kt +++ b/plugins/sonatype/src/main/kotlin/com/powersync/plugins/sonatype/SonatypeCentralExtension.kt @@ -24,6 +24,7 @@ public abstract class SonatypeCentralExtension( public const val PUBLISH_LOCAL_TASK_NAME: String = "publishAllPublicationsToSonatypeLocalRepository" public const val COMPONENT_BUNDLE_TASK_NAME: String = "generateSonatypeComponentBundle" + // This should be stored in your ~/.gradle/gradle.properties public const val SONATYPE_USERNAME_KEY: String = "centralPortal.username" public const val SONATYPE_PASSWORD_KEY: String = "centralPortal.password" } @@ -61,4 +62,3 @@ public abstract class SonatypeCentralExtension( } } } - From 903512910eb75628765f17d2a9da04962015e557 Mon Sep 17 00:00:00 2001 From: DominicGBauer Date: Mon, 26 Aug 2024 10:33:55 +0200 Subject: [PATCH 07/10] chore: update version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 87f73095..821fec64 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,7 +17,7 @@ development=true RELEASE_SIGNING_ENABLED=true # Library config GROUP=com.powersync -LIBRARY_VERSION=0.0.1-ALPHA16 +LIBRARY_VERSION=0.0.1-ALPHA17 GITHUB_REPO=https://github.com/powersync-ja/powersync-kotlin.git # POM POM_URL=https://github.com/powersync-ja/powersync-kotlin/ From 5f6bf63a3d39c4186231f24f4bfc3b911c45850e Mon Sep 17 00:00:00 2001 From: DominicGBauer Date: Mon, 26 Aug 2024 15:25:49 +0200 Subject: [PATCH 08/10] chore: test adding new task --- PowerSync/build.gradle.kts | 76 +++++++++++++++++++++++++++++++++----- 1 file changed, 67 insertions(+), 9 deletions(-) diff --git a/PowerSync/build.gradle.kts b/PowerSync/build.gradle.kts index e2a038d8..ff91b224 100644 --- a/PowerSync/build.gradle.kts +++ b/PowerSync/build.gradle.kts @@ -2,6 +2,8 @@ import co.touchlab.faktory.artifactmanager.ArtifactManager import co.touchlab.faktory.capitalized import co.touchlab.skie.configuration.SuspendInterop import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget +import java.net.URL +import java.security.MessageDigest plugins { alias(libs.plugins.kotlinMultiplatform) @@ -49,7 +51,7 @@ skie { } kmmbridge { - artifactManager.set(SonatypePortalPublishArtifactManager(project, null, null, null)) + artifactManager.set(SonatypePortalPublishArtifactManager(project, repositoryName = null)) artifactManager.finalizeValue() spm() } @@ -66,15 +68,13 @@ if (System.getenv().containsKey("CI")) { // which is only available here class SonatypePortalPublishArtifactManager( val project: Project, - private val publicationName: String?, - artifactSuffix: String?, + private val publicationName: String = "KMMBridgeFramework", + artifactSuffix: String = "kmmbridge", private val repositoryName: String?, ) : ArtifactManager { - private val FRAMEWORK_PUBLICATION_NAME = "KMMBridgeFramework" - private val KMMBRIDGE_ARTIFACT_SUFFIX = "kmmbridge" private val group: String = project.group.toString().replace(".", "/") private val kmmbridgeArtifactId = - "${project.name}-${artifactSuffix ?: KMMBRIDGE_ARTIFACT_SUFFIX}" + "${project.name}-${artifactSuffix}" private val LIBRARY_VERSION: String by project // This is the URL that will be added to Package.swift in Github package so that // KMMBridge is downloaded when a user includes the package in XCode @@ -91,7 +91,7 @@ class SonatypePortalPublishArtifactManager( kmmPublishTask: TaskProvider ) { project.extensions.getByType().publications.create( - publicationName ?: FRAMEWORK_PUBLICATION_NAME, MavenPublication::class.java + publicationName, MavenPublication::class.java ) { this.version = version val archiveProvider = project.tasks.named("zipXCFramework", Zip::class.java).flatMap { @@ -103,6 +103,18 @@ class SonatypePortalPublishArtifactManager( artifactId = kmmbridgeArtifactId } + // Register the task + project.tasks.register("updatePackageSwiftChecksum") { + artifactId.set(kmmbridgeArtifactId) + zipUrl.set(MAVEN_CENTRAL_PACKAGE_ZIP_URL) + dependsOn("updatePackageSwift") + } + + // Make sure this task runs after updatePackageSwift + project.tasks.named("kmmBridgePublish") { + dependsOn("updatePackageSwiftChecksum") + } + publishingTasks().forEach { uploadTask.configure { dependsOn(it) @@ -125,7 +137,7 @@ class SonatypePortalPublishArtifactManager( // Either the user has supplied a correct name, or we use the default. If neither is found, fail. val publicationNameCap = publishingExtension.publications.getByName( - publicationName ?: FRAMEWORK_PUBLICATION_NAME + publicationName ).name.capitalized() return publishingExtension.repositories.filterIsInstance() @@ -137,4 +149,50 @@ class SonatypePortalPublishArtifactManager( project.tasks.named(publishTaskName) } } -} \ No newline at end of file +} + +abstract class UpdatePackageSwiftChecksumTask : DefaultTask() { + @get:Input + abstract val artifactId: Property + + @get:Input + abstract val zipUrl: Property + + @TaskAction + fun updateChecksum() { + val LIBRARY_VERSION: String by project + + val zipFile = project.file("${project.buildDir}/tmp/${artifactId.get().lowercase()}-$LIBRARY_VERSION.zip") + + // Download the zip file + zipFile.parentFile.mkdirs() + URL(zipUrl.get()).openStream().use { input -> + zipFile.outputStream().use { output -> + input.copyTo(output) + } + } + + // Compute the checksum + val checksum = zipFile.inputStream().use { input -> + val digest = MessageDigest.getInstance("SHA-256") + val buffer = ByteArray(8192) + var bytes = input.read(buffer) + while (bytes >= 0) { + digest.update(buffer, 0, bytes) + bytes = input.read(buffer) + } + digest.digest().joinToString("") { "%02x".format(it) } + } + + // Update Package.swift + val packageSwiftFile = project.rootProject.file("Package.swift") + val updatedContent = packageSwiftFile.readText().replace( + Regex("let remoteKotlinChecksum = \"[a-f0-9]+\""), + "let remoteKotlinChecksum = \"$checksum\"" + ) + packageSwiftFile.writeText(updatedContent) + + println("Updated Package.swift with new checksum: $checksum") + } +} + From 00c17e10332536132669e6877fd6bfa37a11c2f1 Mon Sep 17 00:00:00 2001 From: DominicGBauer Date: Tue, 27 Aug 2024 10:57:59 +0200 Subject: [PATCH 09/10] chore: update comments --- PowerSync/build.gradle.kts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/PowerSync/build.gradle.kts b/PowerSync/build.gradle.kts index ff91b224..a43bfad3 100644 --- a/PowerSync/build.gradle.kts +++ b/PowerSync/build.gradle.kts @@ -64,8 +64,8 @@ if (System.getenv().containsKey("CI")) { } // This is required for KMMBridge zip to be uploaded to Sonatype (Maven Central) -// and needs to be in this file as it requires access to import co.touchlab.faktory -// which is only available here +// Since this will only ever be used in this build file it does not make sense to make a +// plugin to use this. class SonatypePortalPublishArtifactManager( val project: Project, private val publicationName: String = "KMMBridgeFramework", @@ -151,6 +151,8 @@ class SonatypePortalPublishArtifactManager( } } +// This task is used to update Package.swift with the checksum of the zip file +// located on maven central. abstract class UpdatePackageSwiftChecksumTask : DefaultTask() { @get:Input abstract val artifactId: Property @@ -162,7 +164,7 @@ abstract class UpdatePackageSwiftChecksumTask : DefaultTask() { fun updateChecksum() { val LIBRARY_VERSION: String by project - val zipFile = project.file("${project.buildDir}/tmp/${artifactId.get().lowercase()}-$LIBRARY_VERSION.zip") + val zipFile = project.file("${project.layout.buildDirectory.get()}/tmp/${artifactId.get().lowercase()}-$LIBRARY_VERSION.zip") // Download the zip file zipFile.parentFile.mkdirs() From 6b612aba2a56b7b04366f075cdbcb696227039c4 Mon Sep 17 00:00:00 2001 From: DominicGBauer Date: Tue, 27 Aug 2024 11:01:33 +0200 Subject: [PATCH 10/10] chore: delete action --- .github/workflows/publish-swift.yml | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 .github/workflows/publish-swift.yml diff --git a/.github/workflows/publish-swift.yml b/.github/workflows/publish-swift.yml deleted file mode 100644 index d71db605..00000000 --- a/.github/workflows/publish-swift.yml +++ /dev/null @@ -1,22 +0,0 @@ -# This can be deleted once we have verified that KMMBridge is successfully available to public -name: Publish iOS Swift -on: - workflow_dispatch: -# TODO: Uncomment this if we want to publish on merge to main -# push: -# branches: -# - "main" - -jobs: - call-kmmbridge-publish: - permissions: - contents: write - packages: write - uses: touchlab/KMMBridgeGithubWorkflow/.github/workflows/faktorybuildautoversion.yml@v1.1 - with: - jvmVersion: 17 - versionBaseProperty: LIBRARY_VERSION - publishTask: kmmBridgePublish - secrets: - gradle_params: -PsigningInMemoryKey="${{ secrets.SIGNING_KEY }}" -PsigningInMemoryKeyId="${{ secrets.SIGNING_KEY_ID }}" -PsigningInMemoryKeyPassword="${{ secrets.SIGNING_PASSWORD }}" -# PODSPEC_SSH_KEY: ${{ secrets.PODSPEC_SSH_KEY }}