Skip to content

Commit

Permalink
Review feedback v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Vampire committed Jun 9, 2023
1 parent 4ae5422 commit a2e391d
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 29 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
4 changes: 2 additions & 2 deletions .github/workflows/branches-and-prs.main.kts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ workflow(
uses(
name = "Set up JDKs",
action = SetupBuildEnv(
additionalJavaVersion = expr(Matrix.java)
additionalJavaVersion = expr(Matrix.javaVersion)
)
)
uses(
Expand All @@ -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
Expand Down
56 changes: 36 additions & 20 deletions .github/workflows/common.main.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,27 @@ data class Matrix(
val operatingSystems: List<String>? = null,
val variants: List<String>? = null,
val javaVersions: List<String>? = null,
val excludes: List<Map<String, String>>? = null,
val includes: List<Map<String, String>>? = null
val exclude: (Element.() -> Boolean)? = null,
val includes: List<Element>? = 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()
)

Expand All @@ -73,10 +84,24 @@ data class Matrix(
val variants: List<String>
)

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"
}
}

Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/release.main.kts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ workflow(
uses(
name = "Set up JDKs",
action = SetupBuildEnv(
additionalJavaVersion = expr(Matrix.java)
additionalJavaVersion = expr(Matrix.javaVersion)
)
)
uses(
Expand All @@ -76,7 +76,7 @@ workflow(
"--stacktrace",
"ghActionsBuild",
""""-Dvariant=${expr(Matrix.variant)}"""",
""""-DjavaVersion=${expr(Matrix.java)}"""",
""""-DjavaVersion=${expr(Matrix.javaVersion)}"""",
"-Dscan.tag.main-build"
).joinToString(" ")
),
Expand Down Expand Up @@ -111,7 +111,7 @@ workflow(
uses(
name = "Set up JDKs",
action = SetupBuildEnv(
additionalJavaVersion = expr(Matrix.java)
additionalJavaVersion = expr(Matrix.javaVersion)
)
)
uses(
Expand All @@ -122,7 +122,7 @@ workflow(
"--stacktrace",
"ghActionsPublish",
""""-Dvariant=${expr(Matrix.variant)}"""",
""""-DjavaVersion=${expr(Matrix.java)}"""",
""""-DjavaVersion=${expr(Matrix.javaVersion)}"""",
"-Dscan.tag.main-publish"
).joinToString(" ")
),
Expand Down Expand Up @@ -154,7 +154,7 @@ workflow(
uses(
name = "Set up JDKs",
action = SetupBuildEnv(
additionalJavaVersion = expr(Matrix.java)
additionalJavaVersion = expr(Matrix.javaVersion)
)
)
run(
Expand All @@ -169,7 +169,7 @@ workflow(
"--stacktrace",
"ghActionsDocs",
""""-Dvariant=${expr(Matrix.variant)}"""",
""""-DjavaVersion=${expr(Matrix.java)}"""",
""""-DjavaVersion=${expr(Matrix.javaVersion)}"""",
"-Dscan.tag.main-docs"
).joinToString(" ")
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ class PreprocessWorkflowsPlugin implements Plugin<Project> {
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)
Expand Down

0 comments on commit a2e391d

Please sign in to comment.