Skip to content

Commit

Permalink
latest mindustry mirror release
Browse files Browse the repository at this point in the history
  • Loading branch information
liplum committed Dec 19, 2023
1 parent 1c903ef commit 6521240
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
4 changes: 2 additions & 2 deletions TestProjectGroovy/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ dependencies {

mindustry {
dependency {
mindustry version: 'v146'
mindustry version: latest
// mindustryMirror version: latest
arc version: 'v146'
arc version: latest
}
modMeta {
name = 'mgpp-groovy'
Expand Down
4 changes: 2 additions & 2 deletions TestProjectKt/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ tasks.register<TestOutputTask>("iconMaker") {
}
mindustry {
dependency {
mindustry on "v146"
arc on "v146"
mindustry on latest
arc on latestRelease
}
modMeta {
name = "mgpp-kt"
Expand Down
4 changes: 4 additions & 0 deletions main/src/R.kt
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ object R {
* [The GitHub API to fetch the latest commit of mirror](https://github.com/Anuken/MindustryJitpack/commits/main)
*/
const val mirrorLatestCommit = "https://api.github.com/repos/Anuken/MindustryJitpack/commits/main"
/**
* [The GitHub API to fetch the latest release of mirror](https://github.com/Anuken/MindustryJitpack/releases/latest)
*/
const val mirrorLatestRelase = "https://api.github.com/repos/Anuken/MindustryJitpack/releases/latest"
/**
* [The GitHub API to fetch the latest commit of arc](https://github.com/Anuken/Arc/commits/master)
*/
Expand Down
20 changes: 20 additions & 0 deletions main/src/mindustry/model/Dependency.kt
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ class DependencySpec(
val version = map["version"]?.toString() ?: throw GradleException("No version specified for `mindustryMirror`")
when (version) {
Notation.latest.toString() -> mindustryMirrorLatestCommit()
Notation.latestRelease.toString() -> mindustryMirrorLatestCommit()
else -> mindustryMirror(version)
}
}
Expand Down Expand Up @@ -194,6 +195,24 @@ class DependencySpec(
}
mindustryMirror(latestVersion)
}
/**
* Fetch the latest Mindustry from [mindustry jitpack](https://github.com/Anuken/Mindustry).
*
* **Potential Issue** It has a very small chance that it won't work when the new version was just released.
*/
fun mindustryMirrorLatestRelease() {
val latestVersion = target.fetchLatestVersion("mindustry-mirror-release-dependency") {
try {
val url = URL(R.github.tag.mirrorLatestCommit)
val json = Jval.read(url.readText())
return@fetchLatestVersion json.getString("tag_name")
} catch (e: Exception) {
target.logger.warn("Failed to fetch the exact latest version of mindustry jitpack, so use ${R.version.defaultOfficial} instead")
return@fetchLatestVersion R.version.defaultOfficial
}
}
mindustryMirror(latestVersion)
}
/**
* Fetch the latest Arc from [arc jitpack](https://github.com/Anuken/Arc).
*
Expand Down Expand Up @@ -325,6 +344,7 @@ class DependencySpec(
infix fun mirror(notation: Notation) {
when (notation) {
Notation.latest -> mindustryMirrorLatestCommit()
Notation.latestRelease -> mindustryMirrorLatestRelease()
else -> throw GradleException("Unknown dependency notation of mindustry mirror $notation")
}
}
Expand Down

0 comments on commit 6521240

Please sign in to comment.