Skip to content

Commit c6fd9bf

Browse files
committed
Last adjust?
1 parent 4f9b5e3 commit c6fd9bf

2 files changed

Lines changed: 68 additions & 56 deletions

File tree

.github/workflows/bindings-server.main.kts

Lines changed: 35 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ import io.github.typesafegithub.workflows.annotations.ExperimentalKotlinLogicSte
1414
import io.github.typesafegithub.workflows.domain.Environment
1515
import io.github.typesafegithub.workflows.domain.JobOutputs
1616
import io.github.typesafegithub.workflows.domain.RunnerType.UbuntuLatest
17+
import io.github.typesafegithub.workflows.domain.Shell
1718
import io.github.typesafegithub.workflows.domain.triggers.*
18-
import io.github.typesafegithub.workflows.domain.contexts.Contexts as RunContexts
1919
import io.github.typesafegithub.workflows.dsl.JobBuilder
2020
import io.github.typesafegithub.workflows.dsl.expressions.Contexts
2121
import io.github.typesafegithub.workflows.dsl.expressions.expr
22-
import java.io.File
2322
import io.github.typesafegithub.workflows.dsl.workflow
2423
import io.github.typesafegithub.workflows.yaml.CheckoutActionVersionSource
2524
import 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)
220210
fun 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

.github/workflows/bindings-server.yaml

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,31 +82,52 @@ jobs:
8282
mv .github/workflows/test-served-bindings-depend-on-library.main.do-not-compile.kts .github/workflows/test-served-bindings-depend-on-library.main.kts
8383
.github/workflows/test-served-bindings-depend-on-library.main.kts
8484
- id: 'step-8'
85-
name: 'Install Kotlin 2.1.0'
85+
name: 'Install Kotlin 2.0.0'
8686
uses: 'fwilhe2/setup-kotlin@v1'
8787
with:
88-
version: '2.1.0'
88+
version: '2.0.0'
8989
- id: 'step-9'
9090
name: 'Clean Maven Local to fetch required POMs again'
9191
run: 'rm -rf ~/.m2/repository/'
9292
- id: 'step-10'
93-
name: 'Execute the script using the bindings from the server, using older Kotlin (2.1.0) as consumer'
94-
env:
95-
GHWKT_GITHUB_CONTEXT_JSON: '${{ toJSON(github) }}'
96-
run: 'GHWKT_RUN_STEP=''bindings-server.yaml:end-to-end-test:step-10'' ''.github/workflows/bindings-server.main.kts'''
93+
name: 'Execute the script using the bindings from the server, using older Kotlin (2.0.0) as consumer'
94+
shell: 'kotlin {0}'
95+
run: |-
96+
val src = java.io.File(".github/workflows/test-script-consuming-jit-bindings.main.kts")
97+
val dest = java.io.File(".github/workflows/test-script-consuming-jit-bindings-too-old-kotlin.main.kts")
98+
src.copyTo(dest, overwrite = true).setExecutable(true)
99+
val process = ProcessBuilder("kotlin", dest.path).redirectErrorStream(true).start()
100+
val output = process.inputStream.bufferedReader().readText()
101+
val exitCode = process.waitFor()
102+
if (exitCode == 0) {
103+
System.err.println("Expected the script to fail but it succeeded")
104+
System.exit(1)
105+
}
106+
if (!output.contains("was compiled with an incompatible version of Kotlin")) {
107+
System.err.println("Expected error message not found. Output:")
108+
System.err.println(output)
109+
System.exit(1)
110+
}
97111
- id: 'step-11'
98-
name: 'Install Kotlin 2.2.0'
112+
name: 'Install Kotlin 2.1.0'
99113
uses: 'fwilhe2/setup-kotlin@v1'
100114
with:
101-
version: '2.2.0'
115+
version: '2.1.0'
102116
- id: 'step-12'
103117
name: 'Clean Maven Local to fetch required POMs again'
104118
run: 'rm -rf ~/.m2/repository/'
105119
- id: 'step-13'
106-
name: 'Execute the script using the bindings from the server, using older Kotlin (2.2.0) as consumer'
107-
env:
108-
GHWKT_GITHUB_CONTEXT_JSON: '${{ toJSON(github) }}'
109-
run: 'GHWKT_RUN_STEP=''bindings-server.yaml:end-to-end-test:step-13'' ''.github/workflows/bindings-server.main.kts'''
120+
name: 'Execute the script using the bindings from the server, using older Kotlin (2.1.0) as consumer'
121+
shell: 'kotlin {0}'
122+
run: |-
123+
val src = java.io.File(".github/workflows/test-script-consuming-jit-bindings.main.kts")
124+
val dest = java.io.File(".github/workflows/test-script-consuming-jit-bindings-older-kotlin.main.kts")
125+
src.copyTo(dest, overwrite = true).setExecutable(true)
126+
val exitCode = ProcessBuilder("kotlin", dest.path).inheritIO().start().waitFor()
127+
if (exitCode != 0) {
128+
System.err.println("Script failed with exit code " + exitCode)
129+
System.exit(exitCode)
130+
}
110131
- id: 'step-14'
111132
name: 'Compile a Gradle project using the bindings from the server'
112133
run: |-

0 commit comments

Comments
 (0)