Skip to content

Commit d018d99

Browse files
authored
Kotlin nightlies: filter on 2.0.20, and trigger workflow (#6003)
* Get the latest 2.0.20 dev version * Run workflow
1 parent a6b2c77 commit d018d99

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

.github/workflows/bump-kotlin-nightlies.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,10 @@ jobs:
1818
git add .
1919
git commit -m "Bump Kotlin version"
2020
git push --force origin kotlin-nightlies
21+
# Trigger a workflow manually because actions cannot trigger workflows to avoid endless loops
22+
# https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#triggering-further-workflow-runs
23+
- name: Trigger pr workflow
24+
run: |
25+
gh workflow run pr --ref kotlin-nightlies
26+
env:
27+
GH_TOKEN: ${{ github.token }}

.github/workflows/pr.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ on:
55
paths-ignore:
66
- 'docs/**'
77
- '*.md'
8+
workflow_dispatch:
9+
810
env:
911
DEVELOCITY_ACCESS_KEY: ${{ secrets.DEVELOCITY_ACCESS_KEY }}
1012

scripts/bump-kotlin-nightlies.main.kts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import javax.xml.parsers.DocumentBuilderFactory
66

77
fun main() {
88
// Update versions in libraries.toml
9-
val kotlinVersion = getLatestVersion("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev/org/jetbrains/kotlin/kotlin-stdlib/maven-metadata.xml")
9+
val kotlinVersion = getLatestVersion("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev/org/jetbrains/kotlin/kotlin-stdlib/maven-metadata.xml", prefix = "2.0.20")
1010
val kspVersion = getLatestVersion("https://oss.sonatype.org/content/repositories/snapshots/com/google/devtools/ksp/com.google.devtools.ksp.gradle.plugin/maven-metadata.xml")
1111
File("gradle/libraries.toml").let { file ->
1212
file.writeText(
@@ -41,17 +41,29 @@ fun String.replaceVersion(key: String, version: String): String {
4141
return replace(Regex("""$key = ".*""""), """$key = "$version"""")
4242
}
4343

44-
fun getLatestVersion(url: String): String {
45-
return URL(url)
44+
fun getLatestVersion(url: String, prefix: String? = null): String {
45+
val document = URL(url)
4646
.openConnection()
4747
.getInputStream().use { inputStream ->
4848
DocumentBuilderFactory.newInstance()
4949
.newDocumentBuilder()
5050
.parse(inputStream)
5151
}
52-
.getElementsByTagName("latest")
53-
.item(0)
54-
.textContent
52+
return if (prefix != null) {
53+
document
54+
.getElementsByTagName("version")
55+
.let {
56+
(0 until it.length)
57+
.map { i -> it.item(i).textContent }
58+
.filter { it.startsWith(prefix) }
59+
.first() // Assumes they are sorted by most recent first, which is true on Kotlin's repo, false on Sonatype
60+
}
61+
} else {
62+
document
63+
.getElementsByTagName("latest")
64+
.item(0)
65+
.textContent
66+
}
5567
}
5668

5769
main()

0 commit comments

Comments
 (0)