Skip to content

Commit e5b9528

Browse files
authored
test(server): add test for using older Kotlin compiler (#1757)
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.
1 parent f202506 commit e5b9528

File tree

2 files changed

+84
-4
lines changed

2 files changed

+84
-4
lines changed

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

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,31 @@ workflow(
9999
""".trimIndent(),
100100
)
101101

102-
cleanMavenLocal()
102+
// There should be a difference of one (mostly minor) version between these two,
103+
// to be able to see the newest non-working and oldest working version.
104+
val newestNotCompatibleVersion = "1.9.0"
105+
val oldestCompatibleVersion = "2.0.0"
106+
107+
runWithSpecificKotlinVersion(
108+
kotlinVersion = newestNotCompatibleVersion,
109+
command = """
110+
cp .github/workflows/test-script-consuming-jit-bindings.main.kts .github/workflows/test-script-consuming-jit-bindings-too-old-kotlin.main.kts
111+
${failsWithPhraseInLogs(
112+
command = ".github/workflows/test-script-consuming-jit-bindings-too-old-kotlin.main.kts",
113+
// This test depicts the current behavior that the served bindings aren't
114+
// compatible with some older Kotlin version. We may want to address it one day.
115+
// For more info, see https://github.com/typesafegithub/github-workflows-kt/issues/1756
116+
phrase = "was compiled with an incompatible version of Kotlin",
117+
)}
118+
""".trimIndent(),
119+
)
120+
runWithSpecificKotlinVersion(
121+
kotlinVersion = oldestCompatibleVersion,
122+
command = """
123+
cp .github/workflows/test-script-consuming-jit-bindings.main.kts .github/workflows/test-script-consuming-jit-bindings-older-kotlin.main.kts
124+
.github/workflows/test-script-consuming-jit-bindings-older-kotlin.main.kts
125+
""".trimIndent(),
126+
)
103127

104128
run(
105129
name = "Compile a Gradle project using the bindings from the server",
@@ -150,3 +174,31 @@ fun JobBuilder<JobOutputs.EMPTY>.cleanMavenLocal() {
150174
command = "rm -rf ~/.m2/repository/"
151175
)
152176
}
177+
178+
fun JobBuilder<JobOutputs.EMPTY>.runWithSpecificKotlinVersion(kotlinVersion: String, command: String) {
179+
run(
180+
name = "Download older Kotlin compiler ($kotlinVersion)",
181+
command = "curl -Lo kotlin-compiler-$kotlinVersion.zip https://github.com/JetBrains/kotlin/releases/download/v$kotlinVersion/kotlin-compiler-$kotlinVersion.zip",
182+
)
183+
run(
184+
name = "Unzip and add to PATH",
185+
command = "unzip kotlin-compiler-$kotlinVersion.zip -d kotlin-compiler-$kotlinVersion",
186+
)
187+
cleanMavenLocal()
188+
run(
189+
name = "Execute the script using the bindings from the server, using older Kotlin ($kotlinVersion) as consumer",
190+
command = """
191+
PATH=${'$'}(pwd)/kotlin-compiler-$kotlinVersion/kotlinc/bin:${'$'}PATH
192+
$command
193+
""".trimIndent(),
194+
)
195+
}
196+
197+
fun failsWithPhraseInLogs(
198+
command: String,
199+
phrase: String,
200+
): String =
201+
"""
202+
($command || true) >> output.txt 2>&1
203+
grep "$phrase" output.txt
204+
""".trimIndent()

.github/workflows/bindings-server.yaml

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,45 @@ jobs:
6262
mv .github/workflows/test-served-bindings-depend-on-library.main.do-not-compile.kts .github/workflows/test-served-bindings-depend-on-library.main.kts
6363
.github/workflows/test-served-bindings-depend-on-library.main.kts
6464
- id: 'step-8'
65+
name: 'Download older Kotlin compiler (1.9.0)'
66+
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'
67+
- id: 'step-9'
68+
name: 'Unzip and add to PATH'
69+
run: 'unzip kotlin-compiler-1.9.0.zip -d kotlin-compiler-1.9.0'
70+
- id: 'step-10'
6571
name: 'Clean Maven Local to fetch required POMs again'
6672
run: 'rm -rf ~/.m2/repository/'
67-
- id: 'step-9'
73+
- id: 'step-11'
74+
name: 'Execute the script using the bindings from the server, using older Kotlin (1.9.0) as consumer'
75+
run: |2-
76+
PATH=$(pwd)/kotlin-compiler-1.9.0/kotlinc/bin:$PATH
77+
cp .github/workflows/test-script-consuming-jit-bindings.main.kts .github/workflows/test-script-consuming-jit-bindings-too-old-kotlin.main.kts
78+
(.github/workflows/test-script-consuming-jit-bindings-too-old-kotlin.main.kts || true) >> output.txt 2>&1
79+
grep "was compiled with an incompatible version of Kotlin" output.txt
80+
- id: 'step-12'
81+
name: 'Download older Kotlin compiler (2.0.0)'
82+
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'
83+
- id: 'step-13'
84+
name: 'Unzip and add to PATH'
85+
run: 'unzip kotlin-compiler-2.0.0.zip -d kotlin-compiler-2.0.0'
86+
- id: 'step-14'
87+
name: 'Clean Maven Local to fetch required POMs again'
88+
run: 'rm -rf ~/.m2/repository/'
89+
- id: 'step-15'
90+
name: 'Execute the script using the bindings from the server, using older Kotlin (2.0.0) as consumer'
91+
run: |2-
92+
PATH=$(pwd)/kotlin-compiler-2.0.0/kotlinc/bin:$PATH
93+
cp .github/workflows/test-script-consuming-jit-bindings.main.kts .github/workflows/test-script-consuming-jit-bindings-older-kotlin.main.kts
94+
.github/workflows/test-script-consuming-jit-bindings-older-kotlin.main.kts
95+
- id: 'step-16'
6896
name: 'Compile a Gradle project using the bindings from the server'
6997
run: |-
7098
cd .github/workflows/test-gradle-project-using-bindings-server
7199
./gradlew build
72-
- id: 'step-10'
100+
- id: 'step-17'
73101
name: 'Fetch maven-metadata.xml for top-level action'
74102
run: 'curl --fail http://localhost:8080/actions/checkout/maven-metadata.xml | grep ''<version>v4</version>'''
75-
- id: 'step-11'
103+
- id: 'step-18'
76104
name: 'Fetch maven-metadata.xml for nested action'
77105
run: 'curl --fail http://localhost:8080/actions/cache__save/maven-metadata.xml | grep ''<version>v4</version>'''
78106
deploy:

0 commit comments

Comments
 (0)