Skip to content

Commit

Permalink
test(server): add test for using older Kotlin compiler (#1757)
Browse files Browse the repository at this point in the history
Part of #1756.

The goal here is to both depict the current behavior, but also save us
from unintentionally having Renovate auto-merge PRs that bump Kotlin
version, which results in having incompatibility in Kotlin Metadata. The
details of the problem are described in #1756.
  • Loading branch information
krzema12 authored Jan 1, 2025
1 parent f202506 commit e5b9528
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 4 deletions.
54 changes: 53 additions & 1 deletion .github/workflows/bindings-server.main.kts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,31 @@ workflow(
""".trimIndent(),
)

cleanMavenLocal()
// There should be a difference of one (mostly minor) version between these two,
// to be able to see the newest non-working and oldest working version.
val newestNotCompatibleVersion = "1.9.0"
val oldestCompatibleVersion = "2.0.0"

runWithSpecificKotlinVersion(
kotlinVersion = newestNotCompatibleVersion,
command = """
cp .github/workflows/test-script-consuming-jit-bindings.main.kts .github/workflows/test-script-consuming-jit-bindings-too-old-kotlin.main.kts
${failsWithPhraseInLogs(
command = ".github/workflows/test-script-consuming-jit-bindings-too-old-kotlin.main.kts",
// This test depicts the current behavior that the served bindings aren't
// compatible with some older Kotlin version. We may want to address it one day.
// For more info, see https://github.com/typesafegithub/github-workflows-kt/issues/1756
phrase = "was compiled with an incompatible version of Kotlin",
)}
""".trimIndent(),
)
runWithSpecificKotlinVersion(
kotlinVersion = oldestCompatibleVersion,
command = """
cp .github/workflows/test-script-consuming-jit-bindings.main.kts .github/workflows/test-script-consuming-jit-bindings-older-kotlin.main.kts
.github/workflows/test-script-consuming-jit-bindings-older-kotlin.main.kts
""".trimIndent(),
)

run(
name = "Compile a Gradle project using the bindings from the server",
Expand Down Expand Up @@ -150,3 +174,31 @@ fun JobBuilder<JobOutputs.EMPTY>.cleanMavenLocal() {
command = "rm -rf ~/.m2/repository/"
)
}

fun JobBuilder<JobOutputs.EMPTY>.runWithSpecificKotlinVersion(kotlinVersion: String, command: String) {
run(
name = "Download older Kotlin compiler ($kotlinVersion)",
command = "curl -Lo kotlin-compiler-$kotlinVersion.zip https://github.com/JetBrains/kotlin/releases/download/v$kotlinVersion/kotlin-compiler-$kotlinVersion.zip",
)
run(
name = "Unzip and add to PATH",
command = "unzip kotlin-compiler-$kotlinVersion.zip -d kotlin-compiler-$kotlinVersion",
)
cleanMavenLocal()
run(
name = "Execute the script using the bindings from the server, using older Kotlin ($kotlinVersion) as consumer",
command = """
PATH=${'$'}(pwd)/kotlin-compiler-$kotlinVersion/kotlinc/bin:${'$'}PATH
$command
""".trimIndent(),
)
}

fun failsWithPhraseInLogs(
command: String,
phrase: String,
): String =
"""
($command || true) >> output.txt 2>&1
grep "$phrase" output.txt
""".trimIndent()
34 changes: 31 additions & 3 deletions .github/workflows/bindings-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,45 @@ jobs:
mv .github/workflows/test-served-bindings-depend-on-library.main.do-not-compile.kts .github/workflows/test-served-bindings-depend-on-library.main.kts
.github/workflows/test-served-bindings-depend-on-library.main.kts
- id: 'step-8'
name: 'Download older Kotlin compiler (1.9.0)'
run: 'curl -Lo kotlin-compiler-1.9.0.zip https://github.com/JetBrains/kotlin/releases/download/v1.9.0/kotlin-compiler-1.9.0.zip'
- id: 'step-9'
name: 'Unzip and add to PATH'
run: 'unzip kotlin-compiler-1.9.0.zip -d kotlin-compiler-1.9.0'
- id: 'step-10'
name: 'Clean Maven Local to fetch required POMs again'
run: 'rm -rf ~/.m2/repository/'
- id: 'step-9'
- id: 'step-11'
name: 'Execute the script using the bindings from the server, using older Kotlin (1.9.0) as consumer'
run: |2-
PATH=$(pwd)/kotlin-compiler-1.9.0/kotlinc/bin:$PATH
cp .github/workflows/test-script-consuming-jit-bindings.main.kts .github/workflows/test-script-consuming-jit-bindings-too-old-kotlin.main.kts
(.github/workflows/test-script-consuming-jit-bindings-too-old-kotlin.main.kts || true) >> output.txt 2>&1
grep "was compiled with an incompatible version of Kotlin" output.txt
- id: 'step-12'
name: 'Download older Kotlin compiler (2.0.0)'
run: 'curl -Lo kotlin-compiler-2.0.0.zip https://github.com/JetBrains/kotlin/releases/download/v2.0.0/kotlin-compiler-2.0.0.zip'
- id: 'step-13'
name: 'Unzip and add to PATH'
run: 'unzip kotlin-compiler-2.0.0.zip -d kotlin-compiler-2.0.0'
- id: 'step-14'
name: 'Clean Maven Local to fetch required POMs again'
run: 'rm -rf ~/.m2/repository/'
- id: 'step-15'
name: 'Execute the script using the bindings from the server, using older Kotlin (2.0.0) as consumer'
run: |2-
PATH=$(pwd)/kotlin-compiler-2.0.0/kotlinc/bin:$PATH
cp .github/workflows/test-script-consuming-jit-bindings.main.kts .github/workflows/test-script-consuming-jit-bindings-older-kotlin.main.kts
.github/workflows/test-script-consuming-jit-bindings-older-kotlin.main.kts
- id: 'step-16'
name: 'Compile a Gradle project using the bindings from the server'
run: |-
cd .github/workflows/test-gradle-project-using-bindings-server
./gradlew build
- id: 'step-10'
- id: 'step-17'
name: 'Fetch maven-metadata.xml for top-level action'
run: 'curl --fail http://localhost:8080/actions/checkout/maven-metadata.xml | grep ''<version>v4</version>'''
- id: 'step-11'
- id: 'step-18'
name: 'Fetch maven-metadata.xml for nested action'
run: 'curl --fail http://localhost:8080/actions/cache__save/maven-metadata.xml | grep ''<version>v4</version>'''
deploy:
Expand Down

0 comments on commit e5b9528

Please sign in to comment.