Skip to content

Commit 9b6ebca

Browse files
committed
Add CLI version to the OR changelogs
1 parent 40516d8 commit 9b6ebca

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ dependencies {
5353
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.15.2")
5454
implementation("io.github.java-diff-utils:java-diff-utils:4.11")
5555
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0")
56+
implementation("com.squareup.okhttp3:okhttp:4.12.0")
5657
runtimeOnly("org.slf4j:slf4j-simple:1.7.30")
5758

5859
testImplementation("org.junit.jupiter:junit-jupiter:5.+")

src/main/kotlin/org/openrewrite/RecipeMarkdownGenerator.kt

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import kotlinx.coroutines.Dispatchers
1111
import kotlinx.coroutines.async
1212
import kotlinx.coroutines.awaitAll
1313
import kotlinx.coroutines.runBlocking
14+
import okhttp3.OkHttpClient
15+
import okhttp3.Request
1416
import org.openrewrite.config.CategoryDescriptor
1517
import org.openrewrite.config.DeclarativeRecipe
1618
import org.openrewrite.config.Environment
@@ -681,6 +683,59 @@ class RecipeMarkdownGenerator : Runnable {
681683
return changedRecipes
682684
}
683685

686+
private fun getLatestStableVersion(): String? {
687+
val client = OkHttpClient()
688+
val request = Request.Builder()
689+
.url("https://api.github.com/repos/moderneinc/moderne-cli-releases/releases/latest")
690+
.build()
691+
692+
return try {
693+
client.newCall(request).execute().use { response ->
694+
if (response.isSuccessful) {
695+
val responseBody = response.body?.string() ?: return null
696+
val mapper = ObjectMapper()
697+
val json = mapper.readTree(responseBody)
698+
json.get("tag_name")?.asText()
699+
} else {
700+
System.err.println("Failed to get latest version from GitHub: ${response.code}")
701+
null
702+
}
703+
}
704+
} catch (e: Exception) {
705+
System.err.println("Failed to get latest version from GitHub: ${e.message}")
706+
null
707+
}
708+
}
709+
710+
private fun getLatestStagingVersion(): String? {
711+
val client = OkHttpClient()
712+
val request = Request.Builder()
713+
.url("https://api.github.com/repos/moderneinc/moderne-cli-releases/releases")
714+
.build()
715+
716+
return try {
717+
client.newCall(request).execute().use { response ->
718+
if (response.isSuccessful) {
719+
val responseBody = response.body?.string() ?: return null
720+
val mapper = ObjectMapper()
721+
val releases = mapper.readTree(responseBody)
722+
// These are in order from newest to oldest
723+
if (releases.isArray && releases.size() > 0) {
724+
releases[0].get("tag_name")?.asText()
725+
} else {
726+
null
727+
}
728+
} else {
729+
System.err.println("Failed to fetch latest staging version: ${response.code}")
730+
null
731+
}
732+
}
733+
} catch (e: Exception) {
734+
System.err.println("Failed to fetch latest staging version: ${e.message}")
735+
null
736+
}
737+
}
738+
684739
private fun buildChangelog(
685740
newArtifacts: TreeSet<String>,
686741
removedArtifacts: TreeSet<String>,
@@ -693,6 +748,10 @@ class RecipeMarkdownGenerator : Runnable {
693748
// Get the date to label the changelog
694749
val formatted = getDateFormattedYYYYMMDD()
695750

751+
// Get the latest staging and stable versions of the CLI
752+
val stagingVersion = getLatestStagingVersion()
753+
val stableVersion = getLatestStableVersion()
754+
696755
val changelog: File = if (deployType == "release") {
697756
File("src/main/resources/${rewriteBomVersion.replace('.', '-')}-Release.md")
698757
} else {
@@ -724,6 +783,16 @@ class RecipeMarkdownGenerator : Runnable {
724783
changelog.appendText("\n\n:::info")
725784
changelog.appendText("\nThis changelog only shows what recipes have been added, removed, or changed. OpenRewrite may do releases that do not include these types of changes. To see these changes, please go to the [releases page](https://github.com/openrewrite/rewrite/releases).")
726785
changelog.appendText("\n:::\n\n")
786+
787+
changelog.appendText("## Corresponding CLI version\n\n")
788+
789+
if (stableVersion != null) {
790+
changelog.appendText("* Stable CLI version `${stableVersion}`\n")
791+
}
792+
793+
if (stagingVersion != null) {
794+
changelog.appendText("* Staging CLI version: `${stagingVersion}`\n\n")
795+
}
727796
}
728797

729798
// An example of what the changelog could look like after the below statements can be found here:

0 commit comments

Comments
 (0)