Skip to content

Commit

Permalink
feat: Add gradle task to update idofront versions
Browse files Browse the repository at this point in the history
  • Loading branch information
0ffz committed Oct 12, 2024
1 parent a5fc171 commit 41dd656
Showing 1 changed file with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import java.net.URL
import java.util.*

fun getNextVersion(): String {
val releaseVersion: String? = System.getenv("RELEASE_VERSION")
val branchVersion: String? = System.getenv("BRANCH_VERSION")
Expand Down Expand Up @@ -27,3 +30,32 @@ version = getNextVersion()
subprojects {
version = rootProject.version
}

tasks.register("updateIdofrontVersion") {
doLast {
val githubApiUrl = "https://api.github.com/repos/MineInAbyss/Idofront/releases/latest"
val connection = URL(githubApiUrl).openConnection()
connection.setRequestProperty("Accept", "application/vnd.github.v3+json")

val response = connection.inputStream.bufferedReader().use { it.readText() }
val latestVersion = "\"tag_name\":\\s*\"v?([^\"]+)\"".toRegex().find(response)?.groupValues?.get(1)

if (latestVersion != null) {
val gradlePropertiesFile = project.file("gradle.properties")
val properties = Properties()

gradlePropertiesFile.inputStream().use { properties.load(it) }
val currentVersion = properties.getProperty("idofrontVersion")

if (currentVersion != latestVersion) {
properties.setProperty("idofrontVersion", latestVersion)
gradlePropertiesFile.outputStream().use { properties.store(it, null) }
println("Updated idofrontVersion from $currentVersion to $latestVersion")
} else {
println("idofrontVersion is already up to date ($currentVersion)")
}
} else {
println("Failed to retrieve the latest version from GitHub")
}
}
}

0 comments on commit 41dd656

Please sign in to comment.