File tree Expand file tree Collapse file tree
main/kotlin/it/krzeminski/githubactions/dsl/expressions/contexts
test/kotlin/it/krzeminski/githubactions/dsl/expressions Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package it.krzeminski.githubactions.dsl.expressions.contexts
2+
3+ import it.krzeminski.githubactions.dsl.expressions.expr
4+ import kotlin.reflect.KProperty
5+
6+
7+ public open class StrategyMatrix (
8+ private val map : MutableMap <String , List <String >> = mutableMapOf()
9+ ): Map<String, List<String>> by map {
10+
11+ public fun iterate (vararg value : String ): Property {
12+ return Property (value.toList())
13+ }
14+
15+ public inner class Property (public val values : List <String >) {
16+ public operator fun getValue (strategyMatrixContext : StrategyMatrix , property : KProperty <* >): String {
17+ map[property.name] = values
18+ return expr(" matrix.${property.name} " )
19+ }
20+ }
21+ }
Original file line number Diff line number Diff line change 1+ package it.krzeminski.githubactions.dsl.expressions
2+
3+ import it.krzeminski.githubactions.actions.actions.SetupNodeV3
4+ import it.krzeminski.githubactions.domain.RunnerType
5+ import it.krzeminski.githubactions.domain.triggers.Push
6+ import it.krzeminski.githubactions.dsl.expressions.contexts.StrategyMatrix
7+ import it.krzeminski.githubactions.dsl.workflow
8+ import it.krzeminski.githubactions.yaml.toYaml
9+ import java.nio.file.Path
10+
11+ fun main () {
12+ println (expectedWorkflow.toYaml())
13+ }
14+
15+ val expectedWorkflow = workflow(
16+ name = " Test matrix" ,
17+ on = listOf (Push ()),
18+ sourceFile = Path .of(" /tmp/some_workflow.main.kts" ),
19+ ) {
20+ val strategyMatrix = object : StrategyMatrix () {
21+ val os by iterate(" ubuntu-latest" , " windows-latest" )
22+ val node by iterate(" 14" , " 16" )
23+ }
24+ job(
25+ id = " test_job" ,
26+ name = " Test Job" ,
27+ strategyMatrix = strategyMatrix,
28+ runsOn = RunnerType .Custom (strategyMatrix.os),
29+ ) {
30+ uses(SetupNodeV3 (
31+ nodeVersion = strategyMatrix.node
32+ ))
33+ }
34+ }
35+
36+ val expectedMatrixYaml = """
37+ name: Test matrix
38+ on: push
39+
40+ jobs:
41+ build:
42+ runs-on: ${expr(" matrix.os" )}
43+ strategy:
44+ matrix:
45+ os: [ubuntu-latest, windows-latest]
46+ node: [14, 16]
47+ steps:
48+ - uses: actions/setup-node@v3
49+ with:
50+ node-version: ${expr(" matrix.node" )}
51+ """ .trimIndent()
You can’t perform that action at this time.
0 commit comments