Skip to content

Commit b833550

Browse files
authored
Kpg/testing (#266)
* Start testing. Fix spm git folder query when there is no git repo. * Refactor build config and cleanup * Fix workflow * Set artificial version for local test publish * Use newer xcode version * Fix tests * Revert mac to latest * Updates * Split tests into different test classes * Add .kotlin to .gitignore * Clean up API visibility * Added deploy key helper * Updated testing * Verify value * Fix value read * Plugin class in jar * Prep 1.1.0-a2
1 parent 41ff64b commit b833550

Some content is hidden

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

49 files changed

+1466
-184
lines changed

.github/workflows/build_mac.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Build and Test
2+
on:
3+
pull_request:
4+
push:
5+
workflow_dispatch:
6+
7+
jobs:
8+
build:
9+
runs-on: macos-latest
10+
steps:
11+
- name: Checkout the repo
12+
uses: actions/checkout@v2
13+
14+
- uses: actions/setup-java@v2
15+
with:
16+
distribution: "adopt"
17+
java-version: "17"
18+
19+
- name: Validate Gradle Wrapper
20+
uses: gradle/wrapper-validation-action@v1
21+
22+
- name: Write Faktory Server Code
23+
run: echo ${{ secrets.TOUCHLAB_TEST_ARTIFACT_CODE }} > kmmbridge/TOUCHLAB_TEST_ARTIFACT_CODE
24+
25+
- name: Read Faktory Server Code
26+
run: cat kmmbridge/TOUCHLAB_TEST_ARTIFACT_CODE
27+
28+
- name: Local Publish For Tests
29+
run: ./gradlew publishToMavenLocal --no-daemon --stacktrace --build-cache -PRELEASE_SIGNING_ENABLED=false -PVERSION_NAME=9.9.9
30+
31+
- name: Build
32+
run: ./gradlew build --no-daemon --stacktrace --build-cache
33+
34+
env:
35+
GRADLE_OPTS: -Dkotlin.incremental=false -Dorg.gradle.jvmargs="-Xmx4g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -XX:MaxMetaspaceSize=512m"

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ build
1212
*.xcbkptlist
1313
!/.idea/codeStyles/*
1414
!/.idea/inspectionProfiles/*
15+
.kotlin
16+
TOUCHLAB_TEST_ARTIFACT_CODE

TESTING.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# KMMBridge Project Tests
2+
3+
Gradle guidance suggests using include builds to test Gradle plugins. However, after a significant effort to avoid JVM classpath and other related issues, we decided to run tests by starting external Gradle builds.
4+
5+
To do that, we need to locally publish KMMBridge, then point tests projects at that new version. For each test:
6+
7+
* A temp folder is constructed
8+
* A sample app project is copied to that folder
9+
* A command line process is run, generally running Gradle to perform whatever task we intend to test
10+
11+
## Publishing KMMBridge locally
12+
13+
We want to publish KMMBridge as version `9.9.9`. This is a fake local version, just for testing. To do that, run the following on the root folder of KMMBridge:
14+
15+
```shell
16+
./gradlew publishToMavenLocal -PVERSION_NAME=9.9.9
17+
```
18+
19+
## Editing the test project
20+
21+
Our simple test project lives at `test-projects/basic`. It points at KMMBridge version `9.9.9`. You should be able to open it directly with IJ or AS.
22+
23+
## Tests
24+
25+
See class `co.touchlab.kmmbridge.SimplePluginTest`. `fun setup()` copies the test project an initializes the test project.
26+
27+
Here is a sample test:
28+
29+
```kotlin
30+
@Test
31+
fun runSpmDevBuild() {
32+
val result = ProcessHelper.runSh("./gradlew spmDevBuild --stacktrace", workingDir = testProjectDir)
33+
logExecResult(result)
34+
assertEquals(0, result.status)
35+
}
36+
```

build.gradle.kts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,37 @@ plugins {
1414
alias(libs.plugins.kotlin) apply false
1515
id("org.jetbrains.kotlin.plugin.allopen") version "1.9.0" apply false
1616
alias(libs.plugins.maven.publish) apply false
17+
}
18+
19+
subprojects {
20+
repositories {
21+
gradlePluginPortal()
22+
mavenCentral()
23+
}
24+
25+
extensions.findByType<org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension>()?.apply {
26+
jvmToolchain(17)
27+
}
28+
29+
val GROUP: String by project
30+
val VERSION_NAME: String by project
31+
32+
group = GROUP
33+
version = VERSION_NAME
34+
35+
extensions.findByType<com.vanniktech.maven.publish.MavenPublishBaseExtension>()?.apply {
36+
publishToMavenCentral()
37+
val releaseSigningEnabled =
38+
project.properties["RELEASE_SIGNING_ENABLED"]?.toString()?.equals("false", ignoreCase = true) != true
39+
if (releaseSigningEnabled) signAllPublications()
40+
@Suppress("UnstableApiUsage")
41+
pomFromGradleProperties()
42+
configureBasedOnAppliedPlugins()
43+
}
44+
45+
afterEvaluate {
46+
tasks.getByName<Test>("test") {
47+
useJUnitPlatform()
48+
}
49+
}
1750
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ org.gradle.jvmargs=-Xmx4g
1717
RELEASE_SIGNING_ENABLED=true
1818

1919
GROUP=co.touchlab.kmmbridge
20-
VERSION_NAME=1.1.0-a1
20+
VERSION_NAME=1.1.0-a2
2121
VERSION_NAME_3x=0.3.7
2222

2323
POM_URL=https://github.com/touchlab/KMMBridge
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

kmmbridge-github/build.gradle.kts

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,13 @@
1515

1616
plugins {
1717
`kotlin-dsl`
18-
kotlin("jvm")
18+
alias(libs.plugins.kotlin)
1919
id("org.jetbrains.kotlin.plugin.allopen")
2020
id("java-gradle-plugin")
21-
id("com.vanniktech.maven.publish.base")
21+
alias(libs.plugins.maven.publish)
2222
id("com.gradle.plugin-publish") version "1.0.0"
2323
}
2424

25-
repositories {
26-
gradlePluginPortal()
27-
mavenCentral()
28-
}
29-
3025
@Suppress("UnstableApiUsage")
3126
gradlePlugin {
3227
website = "https://github.com/touchlab/KMMBridge"
@@ -36,8 +31,8 @@ gradlePlugin {
3631
plugins {
3732
register("kmmbridge-github-plugin") {
3833
id = "co.touchlab.kmmbridge.github"
39-
implementationClass = "co.touchlab.kmmbridge.KMMBridgePlugin"
40-
displayName = "KMMBridge/GitHub for Teams"
34+
implementationClass = "co.touchlab.kmmbridge.github.KMMBridgeGitHubPlugin"
35+
displayName = "KMMBridge/GitHub"
4136
tags = listOf(
4237
"kmm",
4338
"kotlin",
@@ -62,23 +57,3 @@ dependencies {
6257

6358
testImplementation(kotlin("test"))
6459
}
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-
}

kmmbridge-github/src/main/kotlin/co/touchlab/kmmbridge/github/GithubReleaseArtifactManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import org.gradle.api.tasks.TaskProvider
1313
import org.gradle.kotlin.dsl.getByType
1414
import java.io.File
1515

16-
class GithubReleaseArtifactManager(
16+
internal class GithubReleaseArtifactManager(
1717
private val repository: String?, private val releaseString: String?, private val useExistingRelease: Boolean
1818
) : ArtifactManager {
1919

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package co.touchlab.kmmbridge.github
2+
3+
import co.touchlab.kmmbridge.BaseKMMBridgePlugin
4+
import co.touchlab.kmmbridge.TASK_GROUP_NAME
5+
import co.touchlab.kmmbridge.findStringProperty
6+
import co.touchlab.kmmbridge.github.internal.procRunFailLog
7+
import org.gradle.api.Action
8+
import org.gradle.api.Project
9+
import org.gradle.api.Task
10+
import java.io.File
11+
import java.nio.file.Files
12+
13+
@Suppress("unused")
14+
class KMMBridgeGitHubPlugin : BaseKMMBridgePlugin() {
15+
override fun apply(project: Project) {
16+
super.apply(project)
17+
val githubDeploySourceRepo = project.findStringProperty("githubDeploySourceRepo")
18+
val githubDeployTargetRepo = project.findStringProperty("githubDeployTargetRepo")
19+
if (githubDeploySourceRepo != null && githubDeployTargetRepo != null) {
20+
project.tasks.register("setupDeployKeys") {
21+
group = TASK_GROUP_NAME
22+
description = "Helper task to setup GitHub deploy keys"
23+
outputs.upToDateWhen { false } // This should always run
24+
25+
@Suppress("ObjectLiteralToLambda")
26+
doLast(object : Action<Task> {
27+
override fun execute(t: Task) {
28+
val githubDeployKeyPrefix = project.findStringProperty("githubDeployKeyPrefix") ?: "KMMBridge"
29+
30+
val keyname = "$githubDeployKeyPrefix Key"
31+
32+
val tempDir = Files.createTempDirectory("kmmbridge")
33+
println("Generated temp dir: $tempDir")
34+
val deployKeyName = "deploykey"
35+
val deployKeyPrivateFilePath = File(tempDir.toFile(), deployKeyName)
36+
val deployKeyPublicFilePath = File(tempDir.toFile(), "${deployKeyName}.pub")
37+
38+
try {
39+
project.procRunFailLog(
40+
"ssh-keygen",
41+
"-t",
42+
"ed25519",
43+
"-f",
44+
deployKeyPrivateFilePath.toString(),
45+
"-C",
46+
"[email protected]:$githubDeployTargetRepo",
47+
"-P",
48+
""
49+
)
50+
51+
project.procRunFailLog(
52+
"gh",
53+
"repo",
54+
"deploy-key",
55+
"add",
56+
deployKeyPublicFilePath.toString(),
57+
"-w",
58+
"-R",
59+
githubDeployTargetRepo,
60+
"-t",
61+
keyname
62+
)
63+
64+
project.procRunFailLog(
65+
"gh",
66+
"secret",
67+
"set",
68+
"${githubDeployKeyPrefix}_SSH_KEY",
69+
"--body",
70+
deployKeyPrivateFilePath.readText(),
71+
"-R",
72+
githubDeploySourceRepo
73+
)
74+
} finally {
75+
deployKeyPrivateFilePath.delete()
76+
deployKeyPublicFilePath.delete()
77+
Files.deleteIfExists(tempDir)
78+
}
79+
}
80+
})
81+
}
82+
}
83+
}
84+
}

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ internal val Project.githubPublishTokenOrNull: String?
2222
internal val Project.githubPublishUser: String?
2323
get() = project.findStringProperty("GITHUB_PUBLISH_USER")
2424

25-
internal val Project.skipGitHumReleaseSpmChecks: Boolean
26-
get() = project.findStringProperty("SKIP_GITHUB_RELEASE_SPM_CHECKS") == "true"
27-
2825
internal val Project.githubRepoOrNull: String?
2926
get() {
3027
val repo = project.findStringProperty("GITHUB_REPO") ?: return null

0 commit comments

Comments
 (0)