@@ -14,12 +14,11 @@ import io.github.typesafegithub.workflows.annotations.ExperimentalKotlinLogicSte
1414import io.github.typesafegithub.workflows.domain.Environment
1515import io.github.typesafegithub.workflows.domain.JobOutputs
1616import io.github.typesafegithub.workflows.domain.RunnerType.UbuntuLatest
17+ import io.github.typesafegithub.workflows.domain.Shell
1718import io.github.typesafegithub.workflows.domain.triggers.*
18- import io.github.typesafegithub.workflows.domain.contexts.Contexts as RunContexts
1919import io.github.typesafegithub.workflows.dsl.JobBuilder
2020import io.github.typesafegithub.workflows.dsl.expressions.Contexts
2121import io.github.typesafegithub.workflows.dsl.expressions.expr
22- import java.io.File
2322import io.github.typesafegithub.workflows.dsl.workflow
2423import io.github.typesafegithub.workflows.yaml.CheckoutActionVersionSource
2524import io.github.typesafegithub.workflows.yaml.DEFAULT_CONSISTENCY_CHECK_JOB_CONFIG
@@ -119,41 +118,42 @@ workflow(
119118
120119 // There should be a difference of one (mostly minor) version between these two,
121120 // to be able to see the newest non-working and oldest working version.
122- val newestNotCompatibleVersion = " 2.1 .0"
123- val oldestCompatibleVersion = " 2.2 .0"
121+ val newestNotCompatibleVersion = " 2.0 .0"
122+ val oldestCompatibleVersion = " 2.1 .0"
124123
125124 runWithSpecificKotlinVersion(
126125 kotlinVersion = newestNotCompatibleVersion,
127- ) {
128- // This test depicts the current behavior that the served bindings aren't
129- // compatible with some older Kotlin version. We may want to address it one day.
130- // For more info, see https://github.com/typesafegithub/github-workflows-kt/issues/1756
131- File ( " .github/workflows/test-script-consuming-jit-bindings.main.kts " ).copyTo(
132- File ( " .github/workflows/test-script-consuming-jit-bindings-too-old-kotlin.main.kts " ),
133- overwrite = true ,
134- ).setExecutable( true )
135- val result = runScriptAndReturnOutput(
136- " .github/workflows/test-script-consuming-jit-bindings-too-old-kotlin.main.kts "
137- )
138- if (result.exitCode == 0 ) {
139- error (" Expected the script to fail but it succeeded " )
140- }
141- if ( ! result.output.contains( " was compiled with an incompatible version of Kotlin " )) {
142- error( " Expected error message not found. Output: \n ${result.output} " )
143- }
144- }
126+ command = """
127+ val src = java.io.File(".github/workflows/test-script-consuming-jit- bindings.main.kts")
128+ val dest = java.io.File(".github/workflows/test-script-consuming-jit-bindings-too-old-kotlin.main.kts")
129+ src.copyTo(dest, overwrite = true).setExecutable(true)
130+ val process = ProcessBuilder("kotlin", dest.path).redirectErrorStream(true).start()
131+ val output = process.inputStream.bufferedReader().readText()
132+ val exitCode = process.waitFor()
133+ if (exitCode == 0) {
134+ System.err.println("Expected the script to fail but it succeeded")
135+ System.exit(1)
136+ }
137+ if (!output.contains("was compiled with an incompatible version of Kotlin") ) {
138+ System.err.println ("Expected error message not found. Output: ")
139+ System.err.println(output)
140+ System.exit(1)
141+ }
142+ """ .trimIndent(),
143+ )
145144 runWithSpecificKotlinVersion(
146145 kotlinVersion = oldestCompatibleVersion,
147- ) {
148- File (" .github/workflows/test-script-consuming-jit-bindings.main.kts" ).copyTo(
149- File (" .github/workflows/test-script-consuming-jit-bindings-older-kotlin.main.kts" ),
150- overwrite = true ,
151- ).setExecutable(true )
152- val result = runScriptAndReturnOutput(
153- " .github/workflows/test-script-consuming-jit-bindings-older-kotlin.main.kts"
154- )
155- check(result.exitCode == 0 ) { " Script failed with exit code ${result.exitCode} " }
156- }
146+ command = """
147+ val src = java.io.File(".github/workflows/test-script-consuming-jit-bindings.main.kts")
148+ val dest = java.io.File(".github/workflows/test-script-consuming-jit-bindings-older-kotlin.main.kts")
149+ src.copyTo(dest, overwrite = true).setExecutable(true)
150+ val exitCode = ProcessBuilder("kotlin", dest.path).inheritIO().start().waitFor()
151+ if (exitCode != 0) {
152+ System.err.println("Script failed with exit code " + exitCode)
153+ System.exit(exitCode)
154+ }
155+ """ .trimIndent(),
156+ )
157157
158158 run (
159159 name = " Compile a Gradle project using the bindings from the server" ,
@@ -207,19 +207,9 @@ fun JobBuilder<JobOutputs.EMPTY>.cleanMavenLocal() {
207207 )
208208}
209209
210- data class ScriptInvocationResult (val output : String , val exitCode : Int )
211-
212- fun runScriptAndReturnOutput (scriptPath : String ): ScriptInvocationResult {
213- val process = ProcessBuilder (scriptPath).redirectErrorStream(true ).start()
214- val output = process.inputStream.bufferedReader().readText()
215- val exitCode = process.waitFor()
216- return ScriptInvocationResult (output, exitCode)
217- }
218-
219- @OptIn(ExperimentalKotlinLogicStep ::class )
220210fun JobBuilder<JobOutputs.EMPTY>.runWithSpecificKotlinVersion (
221211 kotlinVersion : String ,
222- logic : RunContexts .() -> Unit ,
212+ command : String ,
223213) {
224214 uses(
225215 name = " Install Kotlin $kotlinVersion " ,
@@ -230,7 +220,8 @@ fun JobBuilder<JobOutputs.EMPTY>.runWithSpecificKotlinVersion(
230220 cleanMavenLocal()
231221 run (
232222 name = " Execute the script using the bindings from the server, using older Kotlin ($kotlinVersion ) as consumer" ,
233- logic = logic,
223+ shell = Shell .Custom (" kotlin {0}" ),
224+ command = command,
234225 )
235226}
236227
0 commit comments