Skip to content

Commit 5d81bee

Browse files
authored
GitHub workflows tests + test & compilation improvements (#49)
* bump Gradle 7.5.1 * create KxsTsGenBuildSettings, so TSCompile tests can be enabled/disabled with a flag * create github workflows * kotlin.mpp.stability.nowarn=true * bump kotlinx-kover * bump kotlin 1.7.21 * bump gradle-git-versioning-plugin * tweak gradle props * update property name kxstsgen_enableTsCompileTests * increase logging, disable fail-fast * binaries.executable() -> browser() * add rootProject.name to buildSrc Gradle settings * bump Kotlin language level to 1.7, standardise Jvm target to 11 * rm java-library from kotlin-mpp * setup java-test-fixtures, change 'example' to be in 'main' source set * only enable NPM setup when TSCompile is enabled * update kotlin-process * disable kotest plugin kotest/kotest#3141 * use embeddedKotlinVersion shortcut * improve ts compile testing * combine TS compile tests in matrix
1 parent 266afee commit 5d81bee

18 files changed

+193
-58
lines changed

.github/workflows/gradle_task.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Gradle Task
2+
run-name: "Gradle Task ${{ inputs.gradle-task }} @ ${{ inputs.runs-on }}"
3+
4+
# Reusable Workflow for running a Gradle task
5+
6+
on:
7+
workflow_dispatch:
8+
9+
workflow_call:
10+
inputs:
11+
gradle-task:
12+
description: "The Gradle task to run, including any flags"
13+
required: true
14+
type: string
15+
runs-on:
16+
description: "OSes to run the task on"
17+
required: true
18+
type: string
19+
20+
21+
concurrency:
22+
# note: the Workflow inputs are also included in the concurrency group
23+
group: "${{ github.workflow }} ${{ join(inputs.*) }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}"
24+
cancel-in-progress: true
25+
26+
27+
permissions:
28+
contents: read
29+
30+
31+
jobs:
32+
33+
run-task:
34+
runs-on: ${{ inputs.runs-on }}
35+
name: "./gradlew ${{ inputs.gradle-task}} @ ${{ inputs.runs-on }}"
36+
timeout-minutes: 60
37+
steps:
38+
- name: Checkout the repo
39+
uses: actions/checkout@v3
40+
41+
- name: Setup JDK
42+
uses: actions/setup-java@v3
43+
with:
44+
distribution: temurin
45+
java-version: 11
46+
47+
- uses: gradle/gradle-build-action@v2
48+
with:
49+
gradle-home-cache-cleanup: true
50+
51+
- name: Run ${{ inputs.gradle-task }}
52+
run: >-
53+
./gradlew ${{ inputs.gradle-task }}
54+
55+
- name: Upload build reports
56+
if: failure()
57+
uses: actions/upload-artifact@v3
58+
with:
59+
name: build-report-${{ runner.os }}-${{ github.action }}
60+
path: "**/build/reports/"
61+
if-no-files-found: ignore

.github/workflows/tests.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Tests
2+
3+
on:
4+
pull_request:
5+
workflow_dispatch:
6+
workflow_call:
7+
8+
concurrency:
9+
group: "${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}"
10+
cancel-in-progress: true
11+
12+
13+
permissions:
14+
contents: read
15+
16+
17+
jobs:
18+
19+
gradle-check:
20+
name: "./gradlew ${{ matrix.target }} @ ${{ matrix.os }}"
21+
strategy:
22+
matrix:
23+
os: [ ubuntu-latest, macos-11, windows-latest ]
24+
tsCompileTests: [ true, false ]
25+
fail-fast: false
26+
uses: ./.github/workflows/gradle_task.yml
27+
with:
28+
runs-on: ${{ matrix.os }}
29+
gradle-task: >-
30+
check -Pkxstsgen_enableTsCompileTests=${{ matrix.tsCompileTests }} --info --stacktrace

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ gitVersioning.apply {
2222

2323

2424
tasks.wrapper {
25-
gradleVersion = "7.4.2"
25+
gradleVersion = "7.5.1"
2626
distributionType = Wrapper.DistributionType.ALL
2727
}
2828

buildSrc/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
33
plugins {
44
idea
55
`kotlin-dsl`
6-
kotlin("jvm") version "1.6.21"
6+
kotlin("jvm") version embeddedKotlinVersion
77
}
88

99

buildSrc/settings.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
rootProject.name = "buildSrc"
2+
13
apply(from = "./repositories.settings.gradle.kts")
24

35
dependencyResolutionManagement {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package buildsrc.config
2+
3+
import org.gradle.api.provider.Provider
4+
import org.gradle.api.provider.ProviderFactory
5+
6+
abstract class KxsTsGenBuildSettings(
7+
private val providers: ProviderFactory
8+
) {
9+
val enableTsCompileTests: Provider<Boolean> =
10+
providers
11+
.gradleProperty("kxstsgen_enableTsCompileTests")
12+
.map { it.toBoolean() }
13+
.orElse(false)
14+
15+
companion object {
16+
const val NAME = "kxsTsGenSettings"
17+
}
18+
}

buildSrc/src/main/kotlin/buildsrc/convention/kotlin-jvm.gradle.kts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ java {
3131
withSourcesJar()
3232
}
3333

34-
tasks.withType<KotlinCompile> {
34+
tasks.withType<KotlinCompile>().configureEach {
3535
kotlinOptions {
36-
jvmTarget = "1.8"
37-
apiVersion = "1.6"
38-
languageVersion = "1.6"
36+
jvmTarget = "11"
37+
apiVersion = "1.7"
38+
languageVersion = "1.7"
3939
}
4040

4141
kotlinOptions.freeCompilerArgs += listOf(

buildSrc/src/main/kotlin/buildsrc/convention/kotlin-mpp.gradle.kts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,42 @@
11
package buildsrc.convention
22

33
import buildsrc.config.relocateKotlinJsStore
4+
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
5+
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmCompilation
6+
import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget
47

58

69
plugins {
710
id("buildsrc.convention.subproject")
811
kotlin("multiplatform")
9-
`java-library`
1012
}
1113

1214

1315
relocateKotlinJsStore()
1416

1517

16-
kotlin {
17-
targets.all {
18-
compilations.all {
18+
//kotlin {
19+
extensions.configure<KotlinMultiplatformExtension> {
20+
targets.configureEach {
21+
compilations.configureEach {
1922
kotlinOptions {
20-
languageVersion = "1.6"
21-
apiVersion = "1.6"
23+
languageVersion = "1.7"
24+
apiVersion = "1.7"
25+
}
26+
if (this is KotlinJvmCompilation) {
27+
}
28+
}
29+
}
30+
31+
targets.withType<KotlinJvmTarget> {
32+
compilations.configureEach {
33+
kotlinOptions {
34+
jvmTarget = "11"
35+
}
36+
}
37+
testRuns.configureEach {
38+
executionTask.configure {
39+
useJUnitPlatform()
2240
}
2341
}
2442
}

buildSrc/src/main/kotlin/buildsrc/convention/node.gradle.kts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,3 @@ node {
1818
npmWorkDir.set(rootGradleDir.dir("npm"))
1919
yarnWorkDir.set(rootGradleDir.dir("yarn"))
2020
}
21-
22-
tasks.withType<Test> {
23-
val npmInstallDir = tasks.npmSetup.map { it.npmDir.get().asFile.canonicalPath }
24-
inputs.dir(npmInstallDir)
25-
26-
doFirst {
27-
environment("NPM_INSTALL_DIR", npmInstallDir.get())
28-
}
29-
}

buildSrc/src/main/kotlin/buildsrc/convention/subproject.gradle.kts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package buildsrc.convention
22

3-
import org.gradle.kotlin.dsl.base
3+
import buildsrc.config.KxsTsGenBuildSettings
44

55
plugins {
66
base
@@ -10,3 +10,6 @@ if (project != rootProject) {
1010
project.group = rootProject.group
1111
project.version = rootProject.version
1212
}
13+
14+
15+
extensions.create<KxsTsGenBuildSettings>(KxsTsGenBuildSettings.NAME)

docs/code/build.gradle.kts

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,44 @@ plugins {
55
buildsrc.convention.node
66
kotlin("plugin.serialization")
77
id("org.jetbrains.kotlinx.knit")
8+
`java-test-fixtures`
89
}
910

1011
dependencies {
1112
implementation(platform(projects.modules.versionsPlatform))
12-
1313
implementation(projects.modules.kxsTsGenCore)
14-
1514
implementation(libs.kotlinx.serialization.core)
1615
implementation(libs.kotlinx.serialization.json)
17-
1816
implementation(libs.kotlinx.coroutines.core)
19-
2017
implementation(libs.kotlinx.knit)
21-
2218
implementation(kotlin("reflect"))
2319

2420
testImplementation(kotlin("test"))
25-
2621
testImplementation(libs.kotlinx.knit.test)
27-
testImplementation(libs.kotlinProcess)
22+
23+
testFixturesImplementation(platform(projects.modules.versionsPlatform))
24+
testFixturesImplementation(libs.kotlinProcess)
25+
testFixturesImplementation(libs.kotest.frameworkEngine)
26+
testFixturesImplementation(libs.kotest.assertionsCore)
2827
}
2928

30-
tasks.withType<KotlinCompile> {
29+
tasks.withType<KotlinCompile>().configureEach {
3130
mustRunAfter(tasks.knit)
3231
kotlinOptions.freeCompilerArgs += listOf(
3332
"-opt-in=kotlinx.serialization.ExperimentalSerializationApi",
3433
)
3534
}
3635

36+
sourceSets.main {
37+
java.srcDirs("example")
38+
}
39+
3740
sourceSets.test {
38-
java.srcDirs(
39-
"example",
40-
"test",
41-
"util",
42-
)
41+
java.srcDirs("test")
42+
}
43+
44+
sourceSets.testFixtures {
45+
java.srcDirs("util")
4346
}
4447

4548
knit {
@@ -54,5 +57,11 @@ tasks.withType<Test>().configureEach { dependsOn(tasks.knit) }
5457

5558
tasks.test {
5659
// TSCompile tests are slow, they don't need to run every time
57-
systemProperty("kotest.tags", "!TSCompile")
60+
if (kxsTsGenSettings.enableTsCompileTests.get()) {
61+
val npmInstallDir = tasks.npmSetup.map { it.npmDir.get().asFile.canonicalPath }
62+
inputs.dir(npmInstallDir)
63+
environment("NPM_INSTALL_DIR", npmInstallDir.get())
64+
} else {
65+
systemProperty("kotest.tags", "!TSCompile")
66+
}
5867
}

docs/code/util/dev/adamko/kxstsgen/util/processMatchers.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,13 @@ suspend fun String?.shouldTypeScriptCompile(
4747
file.writeText(src)
4848

4949
val (process, output) = typescriptCompile(file)
50-
output.joinToString("\n").asClue { log ->
50+
51+
val outputPretty = output.joinToString("\n").prependIndent(" > ")
52+
53+
outputPretty.asClue { log ->
5154
withClue("exit code should be 0") { process shouldBeExactly 0 }
52-
log.shouldNotBeEmpty()
53-
log shouldContainIgnoringCase "npx: installed"
55+
withClue("log should not be empty") { log.shouldNotBeEmpty() }
56+
// log shouldContainIgnoringCase "npx: installed"
5457
log shouldNotContain "error TS"
5558
}
5659

docs/code/util/dev/adamko/kxstsgen/util/typescriptCompile.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,16 @@ private val npxCmd: String by lazy {
3333
// this is untested on non-Windows
3434
val hostOS = System.getProperty("os.name").lowercase()
3535
val cmd = when {
36-
"windows" in hostOS -> "npx.cmd"
37-
else -> "npx"
36+
"win" in hostOS -> "npx.cmd"
37+
else -> "bin/npx"
3838
}
3939
npmInstallDir.resolve(cmd).invariantSeparatorsPathString
4040
}
4141

4242

4343
// must be set by Gradle
4444
private val npmInstallDir: Path by lazy {
45-
Path.of(System.getenv("NPM_INSTALL_DIR"))
45+
Path.of(
46+
System.getenv()["NPM_INSTALL_DIR"] ?: error("NPM_INSTALL_DIR is not set")
47+
)
4648
}

gradle.properties

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
org.gradle.jvmargs=-Dfile.encoding=UTF-8 -Xmx2g
2+
13
org.gradle.parallel=true
24
org.gradle.caching=true
35
org.gradle.unsafe.configuration-cache=true
46
org.gradle.unsafe.configuration-cache-problems=warn
57

6-
# https://github.com/gradle/gradle/issues/20416
8+
# cache accessors - defaults to 'true' in Gradle 8.0 https://github.com/gradle/gradle/issues/20416
79
org.gradle.kotlin.dsl.precompiled.accessors.strict=true
10+
11+
kotlin.mpp.stability.nowarn=true
12+
13+
kxstsgen_enableTsCompileTests=false

gradle/libs.versions.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,26 @@
33
jvmTarget = "11"
44
kotlinTarget = "1.7"
55

6-
kotlin = "1.7.20" # https://github.com/JetBrains/kotlin/releases
6+
kotlin = "1.7.21" # https://github.com/JetBrains/kotlin/releases
77

88
kotlinSymbolProcessing = "1.7.20-1.0.8" # https://github.com/google/ksp/releases
99
kotlinCompileTesting = "1.4.8" # https://github.com/tschuchortdev/kotlin-compile-testing/releases
1010

1111
kotlinx-serialization = "1.4.0" # https://github.com/Kotlin/kotlinx.serialization/releases/
1212
kotlinx-knit = "0.4.0" # https://github.com/Kotlin/kotlinx-knit/releases
1313
kotlinx-coroutines = "1.6.4" # https://github.com/Kotlin/kotlinx.coroutines/releases
14-
kotlinx-kover = "0.5.1" # https://github.com/Kotlin/kotlinx-kover/releases
14+
kotlinx-kover = "0.6.1" # https://github.com/Kotlin/kotlinx-kover/releases
1515

1616
okio = "3.2.0" # https://search.maven.org/artifact/com.squareup.okio/okio
1717

1818
kotest = "5.5.4" # https://github.com/kotest/kotest/releases
1919

20-
kotlinProcess = "1.3.1" # https://github.com/pgreze/kotlin-process/releases
20+
kotlinProcess = "1.4" # https://github.com/pgreze/kotlin-process/releases
2121

2222
classgraph = "4.8.147" # https://github.com/classgraph/classgraph/releases
2323

2424
gradleNodePlugin = "3.5.0" # https://github.com/node-gradle/gradle-node-plugin/releases
25-
gitVersioningPlugin = "6.3.4" # https://github.com/qoomon/gradle-git-versioning-plugin/releases
25+
gitVersioningPlugin = "6.3.6" # https://github.com/qoomon/gradle-git-versioning-plugin/releases
2626

2727
[libraries]
2828

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-7.4.2-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

gradlew

100644100755
File mode changed.

0 commit comments

Comments
 (0)