diff --git a/.github/workflows/gradle_task.yml b/.github/workflows/gradle_task.yml new file mode 100644 index 00000000..64e72100 --- /dev/null +++ b/.github/workflows/gradle_task.yml @@ -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 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..c5550c7d --- /dev/null +++ b/.github/workflows/tests.yml @@ -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 diff --git a/build.gradle.kts b/build.gradle.kts index d5b1326e..a3126359 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -22,7 +22,7 @@ gitVersioning.apply { tasks.wrapper { - gradleVersion = "7.4.2" + gradleVersion = "7.5.1" distributionType = Wrapper.DistributionType.ALL } diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 1858ddc4..01f1aad6 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -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 } diff --git a/buildSrc/settings.gradle.kts b/buildSrc/settings.gradle.kts index eb552c75..be9ce4fc 100644 --- a/buildSrc/settings.gradle.kts +++ b/buildSrc/settings.gradle.kts @@ -1,3 +1,5 @@ +rootProject.name = "buildSrc" + apply(from = "./repositories.settings.gradle.kts") dependencyResolutionManagement { diff --git a/buildSrc/src/main/kotlin/buildsrc/config/KxsTsGenBuildSettings.kt b/buildSrc/src/main/kotlin/buildsrc/config/KxsTsGenBuildSettings.kt new file mode 100644 index 00000000..417ee6e4 --- /dev/null +++ b/buildSrc/src/main/kotlin/buildsrc/config/KxsTsGenBuildSettings.kt @@ -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 = + providers + .gradleProperty("kxstsgen_enableTsCompileTests") + .map { it.toBoolean() } + .orElse(false) + + companion object { + const val NAME = "kxsTsGenSettings" + } +} diff --git a/buildSrc/src/main/kotlin/buildsrc/convention/kotlin-jvm.gradle.kts b/buildSrc/src/main/kotlin/buildsrc/convention/kotlin-jvm.gradle.kts index d58f6526..102fb78a 100644 --- a/buildSrc/src/main/kotlin/buildsrc/convention/kotlin-jvm.gradle.kts +++ b/buildSrc/src/main/kotlin/buildsrc/convention/kotlin-jvm.gradle.kts @@ -31,11 +31,11 @@ java { withSourcesJar() } -tasks.withType { +tasks.withType().configureEach { kotlinOptions { - jvmTarget = "1.8" - apiVersion = "1.6" - languageVersion = "1.6" + jvmTarget = "11" + apiVersion = "1.7" + languageVersion = "1.7" } kotlinOptions.freeCompilerArgs += listOf( diff --git a/buildSrc/src/main/kotlin/buildsrc/convention/kotlin-mpp.gradle.kts b/buildSrc/src/main/kotlin/buildsrc/convention/kotlin-mpp.gradle.kts index aa900d74..d3f0581c 100644 --- a/buildSrc/src/main/kotlin/buildsrc/convention/kotlin-mpp.gradle.kts +++ b/buildSrc/src/main/kotlin/buildsrc/convention/kotlin-mpp.gradle.kts @@ -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 { + targets.configureEach { + compilations.configureEach { kotlinOptions { - languageVersion = "1.6" - apiVersion = "1.6" + languageVersion = "1.7" + apiVersion = "1.7" + } + if (this is KotlinJvmCompilation) { + } + } + } + + targets.withType { + compilations.configureEach { + kotlinOptions { + jvmTarget = "11" + } + } + testRuns.configureEach { + executionTask.configure { + useJUnitPlatform() } } } diff --git a/buildSrc/src/main/kotlin/buildsrc/convention/node.gradle.kts b/buildSrc/src/main/kotlin/buildsrc/convention/node.gradle.kts index 8b8af429..6a9a1f09 100644 --- a/buildSrc/src/main/kotlin/buildsrc/convention/node.gradle.kts +++ b/buildSrc/src/main/kotlin/buildsrc/convention/node.gradle.kts @@ -18,12 +18,3 @@ node { npmWorkDir.set(rootGradleDir.dir("npm")) yarnWorkDir.set(rootGradleDir.dir("yarn")) } - -tasks.withType { - val npmInstallDir = tasks.npmSetup.map { it.npmDir.get().asFile.canonicalPath } - inputs.dir(npmInstallDir) - - doFirst { - environment("NPM_INSTALL_DIR", npmInstallDir.get()) - } -} diff --git a/buildSrc/src/main/kotlin/buildsrc/convention/subproject.gradle.kts b/buildSrc/src/main/kotlin/buildsrc/convention/subproject.gradle.kts index 2da6eb10..bb5c270a 100644 --- a/buildSrc/src/main/kotlin/buildsrc/convention/subproject.gradle.kts +++ b/buildSrc/src/main/kotlin/buildsrc/convention/subproject.gradle.kts @@ -1,6 +1,6 @@ package buildsrc.convention -import org.gradle.kotlin.dsl.base +import buildsrc.config.KxsTsGenBuildSettings plugins { base @@ -10,3 +10,6 @@ if (project != rootProject) { project.group = rootProject.group project.version = rootProject.version } + + +extensions.create(KxsTsGenBuildSettings.NAME) diff --git a/docs/code/build.gradle.kts b/docs/code/build.gradle.kts index 1b8b74c7..da2b402c 100644 --- a/docs/code/build.gradle.kts +++ b/docs/code/build.gradle.kts @@ -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 { +tasks.withType().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 { @@ -54,5 +57,11 @@ tasks.withType().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") + } } diff --git a/docs/code/util/dev/adamko/kxstsgen/util/processMatchers.kt b/docs/code/util/dev/adamko/kxstsgen/util/processMatchers.kt index 5cacf484..f47800fd 100644 --- a/docs/code/util/dev/adamko/kxstsgen/util/processMatchers.kt +++ b/docs/code/util/dev/adamko/kxstsgen/util/processMatchers.kt @@ -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" } diff --git a/docs/code/util/dev/adamko/kxstsgen/util/typescriptCompile.kt b/docs/code/util/dev/adamko/kxstsgen/util/typescriptCompile.kt index ef2c9880..659961db 100644 --- a/docs/code/util/dev/adamko/kxstsgen/util/typescriptCompile.kt +++ b/docs/code/util/dev/adamko/kxstsgen/util/typescriptCompile.kt @@ -33,8 +33,8 @@ 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 } @@ -42,5 +42,7 @@ private val npxCmd: String by lazy { // 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") + ) } diff --git a/gradle.properties b/gradle.properties index 5df20500..6ba3ec07 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index cb695474..f2ddda9f 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,7 +3,7 @@ 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 @@ -11,18 +11,18 @@ kotlinCompileTesting = "1.4.8" # https://github.com/tschuchortdev/kotl 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] diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 92f06b50..8fad3f5a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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 diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/modules/kxs-ts-gen-core/build.gradle.kts b/modules/kxs-ts-gen-core/build.gradle.kts index 797157cd..17bd6a2a 100644 --- a/modules/kxs-ts-gen-core/build.gradle.kts +++ b/modules/kxs-ts-gen-core/build.gradle.kts @@ -2,26 +2,18 @@ plugins { buildsrc.convention.`kotlin-mpp` buildsrc.convention.`maven-publish` kotlin("plugin.serialization") - id("io.kotest.multiplatform") + // id("io.kotest.multiplatform") // Kotest does not support nested JS tests https://github.com/kotest/kotest/issues/3141 } kotlin { js(IR) { - binaries.executable() + browser() nodejs() } jvm { - compilations.all { - kotlinOptions { - jvmTarget = "1.8" - } - } withJava() - testRuns["test"].executionTask.configure { - useJUnitPlatform() - } } // publishing {