Skip to content

Commit

Permalink
GitHub workflows tests + test & compilation improvements (#49)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
aSemy committed Nov 9, 2022
1 parent 266afee commit 5d81bee
Show file tree
Hide file tree
Showing 18 changed files with 193 additions and 58 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/gradle_task.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Gradle Task
run-name: "Gradle Task ${{ inputs.gradle-task }} @ ${{ inputs.runs-on }}"

# Reusable Workflow for running a Gradle task

on:
workflow_dispatch:

workflow_call:
inputs:
gradle-task:
description: "The Gradle task to run, including any flags"
required: true
type: string
runs-on:
description: "OSes to run the task on"
required: true
type: string


concurrency:
# note: the Workflow inputs are also included in the concurrency group
group: "${{ github.workflow }} ${{ join(inputs.*) }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}"
cancel-in-progress: true


permissions:
contents: read


jobs:

run-task:
runs-on: ${{ inputs.runs-on }}
name: "./gradlew ${{ inputs.gradle-task}} @ ${{ inputs.runs-on }}"
timeout-minutes: 60
steps:
- name: Checkout the repo
uses: actions/checkout@v3

- name: Setup JDK
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 11

- uses: gradle/gradle-build-action@v2
with:
gradle-home-cache-cleanup: true

- name: Run ${{ inputs.gradle-task }}
run: >-
./gradlew ${{ inputs.gradle-task }}
- name: Upload build reports
if: failure()
uses: actions/upload-artifact@v3
with:
name: build-report-${{ runner.os }}-${{ github.action }}
path: "**/build/reports/"
if-no-files-found: ignore
30 changes: 30 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Tests

on:
pull_request:
workflow_dispatch:
workflow_call:

concurrency:
group: "${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}"
cancel-in-progress: true


permissions:
contents: read


jobs:

gradle-check:
name: "./gradlew ${{ matrix.target }} @ ${{ matrix.os }}"
strategy:
matrix:
os: [ ubuntu-latest, macos-11, windows-latest ]
tsCompileTests: [ true, false ]
fail-fast: false
uses: ./.github/workflows/gradle_task.yml
with:
runs-on: ${{ matrix.os }}
gradle-task: >-
check -Pkxstsgen_enableTsCompileTests=${{ matrix.tsCompileTests }} --info --stacktrace
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ gitVersioning.apply {


tasks.wrapper {
gradleVersion = "7.4.2"
gradleVersion = "7.5.1"
distributionType = Wrapper.DistributionType.ALL
}

Expand Down
2 changes: 1 addition & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
idea
`kotlin-dsl`
kotlin("jvm") version "1.6.21"
kotlin("jvm") version embeddedKotlinVersion
}


Expand Down
2 changes: 2 additions & 0 deletions buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
rootProject.name = "buildSrc"

apply(from = "./repositories.settings.gradle.kts")

dependencyResolutionManagement {
Expand Down
18 changes: 18 additions & 0 deletions buildSrc/src/main/kotlin/buildsrc/config/KxsTsGenBuildSettings.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package buildsrc.config

import org.gradle.api.provider.Provider
import org.gradle.api.provider.ProviderFactory

abstract class KxsTsGenBuildSettings(
private val providers: ProviderFactory
) {
val enableTsCompileTests: Provider<Boolean> =
providers
.gradleProperty("kxstsgen_enableTsCompileTests")
.map { it.toBoolean() }
.orElse(false)

companion object {
const val NAME = "kxsTsGenSettings"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ java {
withSourcesJar()
}

tasks.withType<KotlinCompile> {
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = "1.8"
apiVersion = "1.6"
languageVersion = "1.6"
jvmTarget = "11"
apiVersion = "1.7"
languageVersion = "1.7"
}

kotlinOptions.freeCompilerArgs += listOf(
Expand Down
30 changes: 24 additions & 6 deletions buildSrc/src/main/kotlin/buildsrc/convention/kotlin-mpp.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,24 +1,42 @@
package buildsrc.convention

import buildsrc.config.relocateKotlinJsStore
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmCompilation
import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget


plugins {
id("buildsrc.convention.subproject")
kotlin("multiplatform")
`java-library`
}


relocateKotlinJsStore()


kotlin {
targets.all {
compilations.all {
//kotlin {
extensions.configure<KotlinMultiplatformExtension> {
targets.configureEach {
compilations.configureEach {
kotlinOptions {
languageVersion = "1.6"
apiVersion = "1.6"
languageVersion = "1.7"
apiVersion = "1.7"
}
if (this is KotlinJvmCompilation) {
}
}
}

targets.withType<KotlinJvmTarget> {
compilations.configureEach {
kotlinOptions {
jvmTarget = "11"
}
}
testRuns.configureEach {
executionTask.configure {
useJUnitPlatform()
}
}
}
Expand Down
9 changes: 0 additions & 9 deletions buildSrc/src/main/kotlin/buildsrc/convention/node.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,3 @@ node {
npmWorkDir.set(rootGradleDir.dir("npm"))
yarnWorkDir.set(rootGradleDir.dir("yarn"))
}

tasks.withType<Test> {
val npmInstallDir = tasks.npmSetup.map { it.npmDir.get().asFile.canonicalPath }
inputs.dir(npmInstallDir)

doFirst {
environment("NPM_INSTALL_DIR", npmInstallDir.get())
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package buildsrc.convention

import org.gradle.kotlin.dsl.base
import buildsrc.config.KxsTsGenBuildSettings

plugins {
base
Expand All @@ -10,3 +10,6 @@ if (project != rootProject) {
project.group = rootProject.group
project.version = rootProject.version
}


extensions.create<KxsTsGenBuildSettings>(KxsTsGenBuildSettings.NAME)
37 changes: 23 additions & 14 deletions docs/code/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,44 @@ plugins {
buildsrc.convention.node
kotlin("plugin.serialization")
id("org.jetbrains.kotlinx.knit")
`java-test-fixtures`
}

dependencies {
implementation(platform(projects.modules.versionsPlatform))

implementation(projects.modules.kxsTsGenCore)

implementation(libs.kotlinx.serialization.core)
implementation(libs.kotlinx.serialization.json)

implementation(libs.kotlinx.coroutines.core)

implementation(libs.kotlinx.knit)

implementation(kotlin("reflect"))

testImplementation(kotlin("test"))

testImplementation(libs.kotlinx.knit.test)
testImplementation(libs.kotlinProcess)

testFixturesImplementation(platform(projects.modules.versionsPlatform))
testFixturesImplementation(libs.kotlinProcess)
testFixturesImplementation(libs.kotest.frameworkEngine)
testFixturesImplementation(libs.kotest.assertionsCore)
}

tasks.withType<KotlinCompile> {
tasks.withType<KotlinCompile>().configureEach {
mustRunAfter(tasks.knit)
kotlinOptions.freeCompilerArgs += listOf(
"-opt-in=kotlinx.serialization.ExperimentalSerializationApi",
)
}

sourceSets.main {
java.srcDirs("example")
}

sourceSets.test {
java.srcDirs(
"example",
"test",
"util",
)
java.srcDirs("test")
}

sourceSets.testFixtures {
java.srcDirs("util")
}

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

tasks.test {
// TSCompile tests are slow, they don't need to run every time
systemProperty("kotest.tags", "!TSCompile")
if (kxsTsGenSettings.enableTsCompileTests.get()) {
val npmInstallDir = tasks.npmSetup.map { it.npmDir.get().asFile.canonicalPath }
inputs.dir(npmInstallDir)
environment("NPM_INSTALL_DIR", npmInstallDir.get())
} else {
systemProperty("kotest.tags", "!TSCompile")
}
}
9 changes: 6 additions & 3 deletions docs/code/util/dev/adamko/kxstsgen/util/processMatchers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,13 @@ suspend fun String?.shouldTypeScriptCompile(
file.writeText(src)

val (process, output) = typescriptCompile(file)
output.joinToString("\n").asClue { log ->

val outputPretty = output.joinToString("\n").prependIndent(" > ")

outputPretty.asClue { log ->
withClue("exit code should be 0") { process shouldBeExactly 0 }
log.shouldNotBeEmpty()
log shouldContainIgnoringCase "npx: installed"
withClue("log should not be empty") { log.shouldNotBeEmpty() }
// log shouldContainIgnoringCase "npx: installed"
log shouldNotContain "error TS"
}

Expand Down
8 changes: 5 additions & 3 deletions docs/code/util/dev/adamko/kxstsgen/util/typescriptCompile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@ private val npxCmd: String by lazy {
// this is untested on non-Windows
val hostOS = System.getProperty("os.name").lowercase()
val cmd = when {
"windows" in hostOS -> "npx.cmd"
else -> "npx"
"win" in hostOS -> "npx.cmd"
else -> "bin/npx"
}
npmInstallDir.resolve(cmd).invariantSeparatorsPathString
}


// must be set by Gradle
private val npmInstallDir: Path by lazy {
Path.of(System.getenv("NPM_INSTALL_DIR"))
Path.of(
System.getenv()["NPM_INSTALL_DIR"] ?: error("NPM_INSTALL_DIR is not set")
)
}
8 changes: 7 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
org.gradle.jvmargs=-Dfile.encoding=UTF-8 -Xmx2g

org.gradle.parallel=true
org.gradle.caching=true
org.gradle.unsafe.configuration-cache=true
org.gradle.unsafe.configuration-cache-problems=warn

# https://github.com/gradle/gradle/issues/20416
# cache accessors - defaults to 'true' in Gradle 8.0 https://github.com/gradle/gradle/issues/20416
org.gradle.kotlin.dsl.precompiled.accessors.strict=true

kotlin.mpp.stability.nowarn=true

kxstsgen_enableTsCompileTests=false
8 changes: 4 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@
jvmTarget = "11"
kotlinTarget = "1.7"

kotlin = "1.7.20" # https://github.com/JetBrains/kotlin/releases
kotlin = "1.7.21" # https://github.com/JetBrains/kotlin/releases

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

kotlinx-serialization = "1.4.0" # https://github.com/Kotlin/kotlinx.serialization/releases/
kotlinx-knit = "0.4.0" # https://github.com/Kotlin/kotlinx-knit/releases
kotlinx-coroutines = "1.6.4" # https://github.com/Kotlin/kotlinx.coroutines/releases
kotlinx-kover = "0.5.1" # https://github.com/Kotlin/kotlinx-kover/releases
kotlinx-kover = "0.6.1" # https://github.com/Kotlin/kotlinx-kover/releases

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

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

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

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

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

[libraries]

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
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-7.4.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Empty file modified gradlew
100644 → 100755
Empty file.

0 comments on commit 5d81bee

Please sign in to comment.