From a2e391d563c2df316d49426b420d7e6df267e2cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Kautler?= Date: Fri, 9 Jun 2023 21:23:10 +0200 Subject: [PATCH] Review feedback v2 --- .github/workflows/README.adoc | 9 ++- .github/workflows/branches-and-prs.main.kts | 4 +- .github/workflows/common.main.kts | 56 ++++++++++++------- .github/workflows/release.main.kts | 12 ++-- .../gradle/PreprocessWorkflowsPlugin.groovy | 3 + 5 files changed, 55 insertions(+), 29 deletions(-) diff --git a/.github/workflows/README.adoc b/.github/workflows/README.adoc index e3ad8dffc6..0e9514a6a2 100644 --- a/.github/workflows/README.adoc +++ b/.github/workflows/README.adoc @@ -18,7 +18,8 @@ the consistency of all the YAML files as not all are run for pull requests. == Ways to generate the YAML workflow files -There are multiple ways to generate the YAML files and all of them are fine: +There are multiple ways to generate the YAML files and all of them are fine, +but be aware of the last one of the caveats below if you are not using the Gradle method: * If you are in a `sh` derivate like e.g. `bash` and Kotlin is installed and available in the `PATH`, you can just call the `*.main.kts` script like any @@ -89,3 +90,9 @@ you either need to also change the importing file, or to properly execute the sc you need to delete the stale entry from the compilation cache which can be found at for example `~/.cache/main.kts.compiled.cache/` on Linux and `%LOCALAPPDATA%\main.kts.compiled.cache\` on Windows. Alternatively, you can also delete the whole cache directory. ++ +Another option is to disable the compilation cache for the execution by setting the +environment variable `KOTLIN_MAIN_KTS_COMPILED_SCRIPTS_CACHE_DIR` or the system property +`kotlin.main.kts.compiled.scripts.cache.dir` to an empty value, depending on the run +method you chose. The Gradle tasks already do that, so when using the Gradle tasks you +do not have this problem and it just works. diff --git a/.github/workflows/branches-and-prs.main.kts b/.github/workflows/branches-and-prs.main.kts index d33ed5efa8..f7e6480b6d 100755 --- a/.github/workflows/branches-and-prs.main.kts +++ b/.github/workflows/branches-and-prs.main.kts @@ -85,7 +85,7 @@ workflow( uses( name = "Set up JDKs", action = SetupBuildEnv( - additionalJavaVersion = expr(Matrix.java) + additionalJavaVersion = expr(Matrix.javaVersion) ) ) uses( @@ -96,7 +96,7 @@ workflow( "--stacktrace", "ghActionsBuild", """"-Dvariant=${expr(Matrix.variant)}"""", - """"-DjavaVersion=${expr(Matrix.java)}"""" + """"-DjavaVersion=${expr(Matrix.javaVersion)}"""" ).joinToString(" ") ), // secrets are not injected for pull requests diff --git a/.github/workflows/common.main.kts b/.github/workflows/common.main.kts index eefc0020ea..1742863719 100755 --- a/.github/workflows/common.main.kts +++ b/.github/workflows/common.main.kts @@ -55,16 +55,27 @@ data class Matrix( val operatingSystems: List? = null, val variants: List? = null, val javaVersions: List? = null, - val excludes: List>? = null, - val includes: List>? = null + val exclude: (Element.() -> Boolean)? = null, + val includes: List? = null ) { + private val originalElements by lazy { + (operatingSystems ?: listOf(null)) + .map { Element(operatingSystem = it) } + .flatMap { element -> (variants ?: listOf(null)).map { element.copy(variant = it) } } + .flatMap { element -> (javaVersions ?: listOf(null)).map { element.copy(javaVersion = it) } } + } + fun toCustomArguments() = mapOf( *listOfNotNull( operatingSystems?.let { "os" to operatingSystems }, variants?.let { "variant" to variants }, javaVersions?.let { "java" to javaVersions }, - excludes?.let { "exclude" to excludes }, - includes?.let { "include" to includes } + exclude?.let { + "exclude" to originalElements + .filter(exclude) + .map { it.toCustomArguments() } + }, + includes?.let { "include" to includes.map { it.toCustomArguments() } } ).toTypedArray() ) @@ -73,10 +84,24 @@ data class Matrix( val variants: List ) + data class Element( + val operatingSystem: String? = null, + val variant: String? = null, + val javaVersion: String? = null + ) { + fun toCustomArguments() = mapOf( + *listOfNotNull( + operatingSystem?.let { "os" to operatingSystem }, + variant?.let { "variant" to variant }, + javaVersion?.let { "java" to javaVersion } + ).toTypedArray() + ) + } + companion object { val operatingSystem = "matrix.os" val variant = "matrix.variant" - val java = "matrix.java" + val javaVersion = "matrix.java" } } @@ -109,24 +134,15 @@ val Matrix.Companion.full operatingSystems = listOf("ubuntu-latest"), variants = axes.variants, javaVersions = axes.javaVersions, - excludes = axes.javaVersions - .filter { it.toInt() >= 17 } - .map { javaVersion -> - mapOf( - "os" to "ubuntu-latest", - "variant" to "2.5", - "java" to javaVersion - ) - }, + exclude = { (variant == "2.5") && (javaVersion!!.toInt() >= 17) }, includes = listOf("windows-latest", "macos-latest") - .flatMap { os -> axes.variants.map { os to it } } - .map { (os, variant) -> - mapOf( - "os" to os, - "variant" to variant, - "java" to axes.javaVersions.first() + .map { + Matrix.Element( + operatingSystem = it, + javaVersion = axes.javaVersions.first() ) } + .flatMap { element -> axes.variants.map { element.copy(variant = it) } } ) val Matrix.Companion.axes by lazy { diff --git a/.github/workflows/release.main.kts b/.github/workflows/release.main.kts index 00cc2b74bd..37aceddd4c 100755 --- a/.github/workflows/release.main.kts +++ b/.github/workflows/release.main.kts @@ -65,7 +65,7 @@ workflow( uses( name = "Set up JDKs", action = SetupBuildEnv( - additionalJavaVersion = expr(Matrix.java) + additionalJavaVersion = expr(Matrix.javaVersion) ) ) uses( @@ -76,7 +76,7 @@ workflow( "--stacktrace", "ghActionsBuild", """"-Dvariant=${expr(Matrix.variant)}"""", - """"-DjavaVersion=${expr(Matrix.java)}"""", + """"-DjavaVersion=${expr(Matrix.javaVersion)}"""", "-Dscan.tag.main-build" ).joinToString(" ") ), @@ -111,7 +111,7 @@ workflow( uses( name = "Set up JDKs", action = SetupBuildEnv( - additionalJavaVersion = expr(Matrix.java) + additionalJavaVersion = expr(Matrix.javaVersion) ) ) uses( @@ -122,7 +122,7 @@ workflow( "--stacktrace", "ghActionsPublish", """"-Dvariant=${expr(Matrix.variant)}"""", - """"-DjavaVersion=${expr(Matrix.java)}"""", + """"-DjavaVersion=${expr(Matrix.javaVersion)}"""", "-Dscan.tag.main-publish" ).joinToString(" ") ), @@ -154,7 +154,7 @@ workflow( uses( name = "Set up JDKs", action = SetupBuildEnv( - additionalJavaVersion = expr(Matrix.java) + additionalJavaVersion = expr(Matrix.javaVersion) ) ) run( @@ -169,7 +169,7 @@ workflow( "--stacktrace", "ghActionsDocs", """"-Dvariant=${expr(Matrix.variant)}"""", - """"-DjavaVersion=${expr(Matrix.java)}"""", + """"-DjavaVersion=${expr(Matrix.javaVersion)}"""", "-Dscan.tag.main-docs" ).joinToString(" ") ), diff --git a/build-logic/preprocess-workflows/src/main/groovy/org/spockframework/gradle/PreprocessWorkflowsPlugin.groovy b/build-logic/preprocess-workflows/src/main/groovy/org/spockframework/gradle/PreprocessWorkflowsPlugin.groovy index 07a7b270ea..666399da5e 100644 --- a/build-logic/preprocess-workflows/src/main/groovy/org/spockframework/gradle/PreprocessWorkflowsPlugin.groovy +++ b/build-logic/preprocess-workflows/src/main/groovy/org/spockframework/gradle/PreprocessWorkflowsPlugin.groovy @@ -75,6 +75,9 @@ class PreprocessWorkflowsPlugin implements Plugin { it.args('-no-stdlib', '-no-reflect') it.args('-classpath', kotlinScriptClasspath.asPath) it.args('-script', workflowScript.absolutePath) + + // work-around for https://youtrack.jetbrains.com/issue/KT-42101 + it.systemProperty('kotlin.main.kts.compiled.scripts.cache.dir', '') } preprocessWorkflows.configure { it.dependsOn(preprocessWorkflow)