Skip to content

Commit 352b027

Browse files
authored
test(jit): add end-to-end test (#1348)
Part of #1318.
1 parent 5af6cee commit 352b027

File tree

4 files changed

+148
-0
lines changed

4 files changed

+148
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/usr/bin/env kotlin
2+
@file:DependsOn("io.github.typesafegithub:github-workflows-kt:1.13.0")
3+
4+
import io.github.typesafegithub.workflows.actions.actions.CheckoutV4
5+
import io.github.typesafegithub.workflows.actions.actions.SetupJavaV4
6+
import io.github.typesafegithub.workflows.actions.gradle.ActionsSetupGradleV3
7+
import io.github.typesafegithub.workflows.annotations.ExperimentalKotlinLogicStep
8+
import io.github.typesafegithub.workflows.domain.RunnerType.UbuntuLatest
9+
import io.github.typesafegithub.workflows.domain.triggers.PullRequest
10+
import io.github.typesafegithub.workflows.domain.triggers.Push
11+
import io.github.typesafegithub.workflows.dsl.expressions.Contexts
12+
import io.github.typesafegithub.workflows.dsl.workflow
13+
import io.github.typesafegithub.workflows.yaml.writeToFile
14+
import java.net.URI
15+
import java.net.ConnectException
16+
import java.net.http.HttpClient
17+
import java.net.http.HttpRequest
18+
import java.net.http.HttpResponse.BodyHandlers
19+
import kotlin.time.Duration.Companion.minutes
20+
import kotlin.time.TimeSource
21+
22+
val GRADLE_ENCRYPTION_KEY by Contexts.secrets
23+
24+
@OptIn(ExperimentalKotlinLogicStep::class)
25+
workflow(
26+
name = "End-to-end tests",
27+
on = listOf(
28+
Push(branches = listOf("main")),
29+
PullRequest(),
30+
),
31+
sourceFile = __FILE__.toPath(),
32+
) {
33+
job(
34+
id = "test-jit-server",
35+
name = "Test Just-In-Time bindings server",
36+
runsOn = UbuntuLatest,
37+
) {
38+
// Using bundled bindings to avoid generating them here.
39+
uses(action = CheckoutV4())
40+
uses(
41+
name = "Set up JDK",
42+
action = SetupJavaV4(
43+
javaVersion = "11",
44+
distribution = SetupJavaV4.Distribution.Zulu,
45+
)
46+
)
47+
uses(action = ActionsSetupGradleV3())
48+
49+
run(
50+
name = "Start the server",
51+
command = "./gradlew :jit-binding-server:run &",
52+
)
53+
54+
run(name = "Wait for the server to respond") {
55+
val timeSource = TimeSource.Monotonic
56+
val waitStart = timeSource.markNow()
57+
val timeout = 1.minutes
58+
59+
while (timeSource.markNow() - waitStart < timeout) {
60+
try {
61+
HttpClient.newHttpClient().send(
62+
HttpRequest
63+
.newBuilder(URI("http://0.0.0.0:8080/status"))
64+
.GET()
65+
.build(), BodyHandlers.ofString()
66+
)
67+
println("The server is alive!")
68+
break
69+
} catch (_: ConnectException) {
70+
Thread.sleep(5000)
71+
println("The server is still starting...")
72+
}
73+
}
74+
}
75+
76+
run(
77+
name = "Execute the script using the bindings from the server",
78+
command = """
79+
mv .github/workflows/test-script-consuming-jit-bindings.main.do-not-compile.kts .github/workflows/test-script-consuming-jit-bindings.main.kts
80+
.github/workflows/test-script-consuming-jit-bindings.main.kts
81+
""".trimIndent(),
82+
)
83+
}
84+
}.writeToFile()
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# This file was generated using Kotlin DSL (.github/workflows/end-to-end-tests.main.kts).
2+
# If you want to modify the workflow, please change the Kotlin file and regenerate this YAML file.
3+
# Generated with https://github.com/typesafegithub/github-workflows-kt
4+
5+
name: 'End-to-end tests'
6+
on:
7+
push:
8+
branches:
9+
- 'main'
10+
pull_request: {}
11+
jobs:
12+
check_yaml_consistency:
13+
name: 'Check YAML consistency'
14+
runs-on: 'ubuntu-latest'
15+
steps:
16+
- id: 'step-0'
17+
name: 'Check out'
18+
uses: 'actions/checkout@v4'
19+
- id: 'step-1'
20+
name: 'Execute script'
21+
run: 'rm ''.github/workflows/end-to-end-tests.yaml'' && ''.github/workflows/end-to-end-tests.main.kts'''
22+
- id: 'step-2'
23+
name: 'Consistency check'
24+
run: 'git diff --exit-code ''.github/workflows/end-to-end-tests.yaml'''
25+
test-jit-server:
26+
name: 'Test Just-In-Time bindings server'
27+
runs-on: 'ubuntu-latest'
28+
needs:
29+
- 'check_yaml_consistency'
30+
steps:
31+
- id: 'step-0'
32+
uses: 'actions/checkout@v4'
33+
- id: 'step-1'
34+
name: 'Set up JDK'
35+
uses: 'actions/setup-java@v4'
36+
with:
37+
java-version: '11'
38+
distribution: 'zulu'
39+
- id: 'step-2'
40+
uses: 'gradle/actions/setup-gradle@v3'
41+
- id: 'step-3'
42+
name: 'Start the server'
43+
run: './gradlew :jit-binding-server:run &'
44+
- id: 'step-4'
45+
name: 'Wait for the server to respond'
46+
run: 'GHWKT_RUN_STEP=''test-jit-server:step-4'' ''.github/workflows/end-to-end-tests.main.kts'''
47+
- id: 'step-5'
48+
name: 'Execute the script using the bindings from the server'
49+
run: |-
50+
mv .github/workflows/test-script-consuming-jit-bindings.main.do-not-compile.kts .github/workflows/test-script-consuming-jit-bindings.main.kts
51+
.github/workflows/test-script-consuming-jit-bindings.main.kts
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env kotlin
2+
@file:Repository("https://repo1.maven.org/maven2/")
3+
@file:DependsOn("io.github.typesafegithub:github-workflows-kt:1.13.0")
4+
5+
@file:Repository("http://localhost:8080/binding/")
6+
@file:DependsOn("actions:checkout:v4")
7+
8+
import io.github.typesafegithub.workflows.actions.actions.Checkout
9+
println(Checkout())

jit-binding-server/src/main/kotlin/io/github/typesafegithub/workflows/jitbindingserver/Main.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ fun main() {
4747
else -> call.respondText(text = "Not found", status = HttpStatusCode.NotFound)
4848
}
4949
}
50+
51+
get("/status") {
52+
call.respondText("OK")
53+
}
5054
}
5155
}.start(wait = true)
5256
}

0 commit comments

Comments
 (0)