-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
- Loading branch information
1 parent
41ff64b
commit b833550
Showing
49 changed files
with
1,466 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: Build and Test | ||
on: | ||
pull_request: | ||
push: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
runs-on: macos-latest | ||
steps: | ||
- name: Checkout the repo | ||
uses: actions/checkout@v2 | ||
|
||
- uses: actions/setup-java@v2 | ||
with: | ||
distribution: "adopt" | ||
java-version: "17" | ||
|
||
- name: Validate Gradle Wrapper | ||
uses: gradle/wrapper-validation-action@v1 | ||
|
||
- name: Write Faktory Server Code | ||
run: echo ${{ secrets.TOUCHLAB_TEST_ARTIFACT_CODE }} > kmmbridge/TOUCHLAB_TEST_ARTIFACT_CODE | ||
|
||
- name: Read Faktory Server Code | ||
run: cat kmmbridge/TOUCHLAB_TEST_ARTIFACT_CODE | ||
|
||
- name: Local Publish For Tests | ||
run: ./gradlew publishToMavenLocal --no-daemon --stacktrace --build-cache -PRELEASE_SIGNING_ENABLED=false -PVERSION_NAME=9.9.9 | ||
|
||
- name: Build | ||
run: ./gradlew build --no-daemon --stacktrace --build-cache | ||
|
||
env: | ||
GRADLE_OPTS: -Dkotlin.incremental=false -Dorg.gradle.jvmargs="-Xmx4g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -XX:MaxMetaspaceSize=512m" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,5 @@ build | |
*.xcbkptlist | ||
!/.idea/codeStyles/* | ||
!/.idea/inspectionProfiles/* | ||
.kotlin | ||
TOUCHLAB_TEST_ARTIFACT_CODE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# KMMBridge Project Tests | ||
|
||
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. | ||
|
||
To do that, we need to locally publish KMMBridge, then point tests projects at that new version. For each test: | ||
|
||
* A temp folder is constructed | ||
* A sample app project is copied to that folder | ||
* A command line process is run, generally running Gradle to perform whatever task we intend to test | ||
|
||
## Publishing KMMBridge locally | ||
|
||
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: | ||
|
||
```shell | ||
./gradlew publishToMavenLocal -PVERSION_NAME=9.9.9 | ||
``` | ||
|
||
## Editing the test project | ||
|
||
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. | ||
|
||
## Tests | ||
|
||
See class `co.touchlab.kmmbridge.SimplePluginTest`. `fun setup()` copies the test project an initializes the test project. | ||
|
||
Here is a sample test: | ||
|
||
```kotlin | ||
@Test | ||
fun runSpmDevBuild() { | ||
val result = ProcessHelper.runSh("./gradlew spmDevBuild --stacktrace", workingDir = testProjectDir) | ||
logExecResult(result) | ||
assertEquals(0, result.status) | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
kmmbridge-github/src/main/kotlin/co/touchlab/kmmbridge/github/KMMBridgeGitHubPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package co.touchlab.kmmbridge.github | ||
|
||
import co.touchlab.kmmbridge.BaseKMMBridgePlugin | ||
import co.touchlab.kmmbridge.TASK_GROUP_NAME | ||
import co.touchlab.kmmbridge.findStringProperty | ||
import co.touchlab.kmmbridge.github.internal.procRunFailLog | ||
import org.gradle.api.Action | ||
import org.gradle.api.Project | ||
import org.gradle.api.Task | ||
import java.io.File | ||
import java.nio.file.Files | ||
|
||
@Suppress("unused") | ||
class KMMBridgeGitHubPlugin : BaseKMMBridgePlugin() { | ||
override fun apply(project: Project) { | ||
super.apply(project) | ||
val githubDeploySourceRepo = project.findStringProperty("githubDeploySourceRepo") | ||
val githubDeployTargetRepo = project.findStringProperty("githubDeployTargetRepo") | ||
if (githubDeploySourceRepo != null && githubDeployTargetRepo != null) { | ||
project.tasks.register("setupDeployKeys") { | ||
group = TASK_GROUP_NAME | ||
description = "Helper task to setup GitHub deploy keys" | ||
outputs.upToDateWhen { false } // This should always run | ||
|
||
@Suppress("ObjectLiteralToLambda") | ||
doLast(object : Action<Task> { | ||
override fun execute(t: Task) { | ||
val githubDeployKeyPrefix = project.findStringProperty("githubDeployKeyPrefix") ?: "KMMBridge" | ||
|
||
val keyname = "$githubDeployKeyPrefix Key" | ||
|
||
val tempDir = Files.createTempDirectory("kmmbridge") | ||
println("Generated temp dir: $tempDir") | ||
val deployKeyName = "deploykey" | ||
val deployKeyPrivateFilePath = File(tempDir.toFile(), deployKeyName) | ||
val deployKeyPublicFilePath = File(tempDir.toFile(), "${deployKeyName}.pub") | ||
|
||
try { | ||
project.procRunFailLog( | ||
"ssh-keygen", | ||
"-t", | ||
"ed25519", | ||
"-f", | ||
deployKeyPrivateFilePath.toString(), | ||
"-C", | ||
"[email protected]:$githubDeployTargetRepo", | ||
"-P", | ||
"" | ||
) | ||
|
||
project.procRunFailLog( | ||
"gh", | ||
"repo", | ||
"deploy-key", | ||
"add", | ||
deployKeyPublicFilePath.toString(), | ||
"-w", | ||
"-R", | ||
githubDeployTargetRepo, | ||
"-t", | ||
keyname | ||
) | ||
|
||
project.procRunFailLog( | ||
"gh", | ||
"secret", | ||
"set", | ||
"${githubDeployKeyPrefix}_SSH_KEY", | ||
"--body", | ||
deployKeyPrivateFilePath.readText(), | ||
"-R", | ||
githubDeploySourceRepo | ||
) | ||
} finally { | ||
deployKeyPrivateFilePath.delete() | ||
deployKeyPublicFilePath.delete() | ||
Files.deleteIfExists(tempDir) | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
kmmbridge-github/src/main/kotlin/co/touchlab/kmmbridge/github/internal/ProcessHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package co.touchlab.kmmbridge.github.internal | ||
|
||
import org.gradle.api.GradleException | ||
import org.gradle.api.Project | ||
import java.io.BufferedReader | ||
import java.io.File | ||
import java.io.InputStreamReader | ||
|
||
internal fun procRun(vararg params: String, dir: File?, processLines: (String, Int) -> Unit) { | ||
val processBuilder = ProcessBuilder(*params) | ||
.redirectErrorStream(true) | ||
if (dir != null) { | ||
println("*** Running proc in ${dir.path}") | ||
processBuilder.directory(dir) | ||
} | ||
|
||
val process = processBuilder | ||
.start() | ||
|
||
val streamReader = InputStreamReader(process.inputStream) | ||
val bufferedReader = BufferedReader(streamReader) | ||
var lineCount = 1 | ||
|
||
bufferedReader.forEachLine { line -> | ||
processLines(line, lineCount) | ||
lineCount++ | ||
} | ||
|
||
bufferedReader.close() | ||
val returnValue = process.waitFor() | ||
if (returnValue != 0) | ||
throw GradleException("Process failed: ${params.joinToString(" ")}") | ||
} | ||
|
||
internal fun Project.procRunFailLog(vararg params: String, dir: File? = null): List<String> { | ||
val output = mutableListOf<String>() | ||
try { | ||
logger.info("Project.procRunFailLog: ${params.joinToString(" ")}") | ||
procRun(*params, dir = dir) { line, _ -> output.add(line) } | ||
} catch (e: Exception) { | ||
output.forEach { logger.error("error: $it") } | ||
throw e | ||
} | ||
return output | ||
} |
Oops, something went wrong.