-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I can't run the project for now because of a timeout
- Loading branch information
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
...ary/src/main/kotlin/it/krzeminski/githubactions/dsl/expressions/contexts/MatrixContext.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package it.krzeminski.githubactions.dsl.expressions.contexts | ||
|
||
import it.krzeminski.githubactions.dsl.expressions.expr | ||
import kotlin.reflect.KProperty | ||
|
||
|
||
public open class StrategyMatrix( | ||
private val map: MutableMap<String, List<String>> = mutableMapOf() | ||
): Map<String, List<String>> by map { | ||
|
||
public fun iterate(vararg value: String): Property { | ||
return Property(value.toList()) | ||
} | ||
|
||
public inner class Property(public val values: List<String>) { | ||
public operator fun getValue(strategyMatrixContext: StrategyMatrix, property: KProperty<*>): String { | ||
map[property.name] = values | ||
return expr("matrix.${property.name}") | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
library/src/test/kotlin/it/krzeminski/githubactions/dsl/expressions/MatrixExample.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package it.krzeminski.githubactions.dsl.expressions | ||
|
||
import it.krzeminski.githubactions.actions.actions.SetupNodeV3 | ||
import it.krzeminski.githubactions.domain.RunnerType | ||
import it.krzeminski.githubactions.domain.triggers.Push | ||
import it.krzeminski.githubactions.dsl.expressions.contexts.StrategyMatrix | ||
import it.krzeminski.githubactions.dsl.workflow | ||
import it.krzeminski.githubactions.yaml.toYaml | ||
import java.nio.file.Path | ||
|
||
fun main() { | ||
println(expectedWorkflow.toYaml()) | ||
} | ||
|
||
val expectedWorkflow = workflow( | ||
name = "Test matrix", | ||
on = listOf(Push()), | ||
sourceFile = Path.of("/tmp/some_workflow.main.kts"), | ||
) { | ||
val strategyMatrix = object : StrategyMatrix() { | ||
val os by iterate("ubuntu-latest", "windows-latest") | ||
val node by iterate("14", "16") | ||
} | ||
job( | ||
id = "test_job", | ||
name = "Test Job", | ||
strategyMatrix = strategyMatrix, | ||
runsOn = RunnerType.Custom(strategyMatrix.os), | ||
) { | ||
uses(SetupNodeV3( | ||
nodeVersion = strategyMatrix.node | ||
)) | ||
} | ||
} | ||
|
||
val expectedMatrixYaml = """ | ||
name: Test matrix | ||
on: push | ||
jobs: | ||
build: | ||
runs-on: ${expr("matrix.os")} | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, windows-latest] | ||
node: [14, 16] | ||
steps: | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${expr("matrix.node")} | ||
""".trimIndent() |