-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #784 Signed-off-by: Leonardo Colman Lopes <dev@leonardo.colman.com.br>
- Loading branch information
Showing
3 changed files
with
128 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/bin/bash kotlin | ||
|
||
import java.io.File | ||
import kotlin.system.exitProcess | ||
|
||
val buildGradleFile = File("./build.gradle.kts") | ||
val changelogs = "../fastlane/metadata/android/en-US/changelogs" | ||
val buildGradleContent = File("./build.gradle.kts").readText() | ||
|
||
val versionCodeRegex = Regex("""versionCode\s*=\s*(\d+)""") | ||
val versionNameRegex = Regex("""versionName\s*=\s*"([\d.]+)"""") | ||
|
||
val currentVersionCode = versionCodeRegex.find(buildGradleContent)!!.groupValues[1].toInt() | ||
val currentVersionName = versionNameRegex.find(buildGradleContent)!!.groupValues[1] | ||
|
||
println("Current version: $currentVersionName ($currentVersionCode)") | ||
println("Detecting bump type...") | ||
var bumpType = args.getOrNull(0) | ||
if(bumpType == null) { | ||
println("BUMP_TYPE not set, input one of: major, minor, patch") | ||
exitProcess(1) | ||
} | ||
|
||
check(bumpType in listOf("major", "minor", "patch")) { "BUMP_TYPE must be one of: major, minor, patch" } | ||
|
||
|
||
val versionParts = currentVersionName.split(".").map { it.toIntOrNull() ?: 0 } | ||
val (newMajor, newMinor, newPatch) = when (bumpType) { | ||
"major" -> Triple(versionParts[0] + 1, 0, 0) | ||
"minor" -> Triple(versionParts[0], versionParts[1] + 1, 0) | ||
"patch" -> Triple(versionParts[0], versionParts[1], versionParts[2] + 1) | ||
else -> throw IllegalStateException("Unknown bump type: $bumpType") | ||
} | ||
val newVersionName = "$newMajor.$newMinor.$newPatch" | ||
println("New version: $newVersionName") | ||
|
||
|
||
|
||
|
||
val newVersionCode = "${newMajor * 1000000 + newMinor * 1000 + newPatch}" | ||
println("New version code: $newVersionCode") | ||
|
||
|
||
val updatedContent = buildGradleContent | ||
.replace(versionCodeRegex, "versionCode = $newVersionCode") | ||
.replace(versionNameRegex, "versionName = \"$newVersionName\"") | ||
|
||
buildGradleFile.writeText(updatedContent) | ||
|
||
|
||
val changelogFile = File(changelogs, "$newVersionCode.txt") | ||
if (!changelogFile.exists()) { | ||
changelogFile.createNewFile() | ||
} | ||
|
||
val changelog = args.getOrNull(1) | ||
if(changelog != null) { | ||
println("Writing changelog...") | ||
changelogFile.writeText(changelog) | ||
} | ||
|
||
ProcessBuilder("git", "add", buildGradleFile.absolutePath, changelogFile.absolutePath).inheritIO().start().waitFor() | ||
ProcessBuilder("git", "commit", "-m", "🔖 Prepare Release $newVersionName ($newVersionCode)").inheritIO().start().waitFor() | ||
ProcessBuilder("git", "tag", "-a", newVersionName, "-m", "Release version $newVersionName").inheritIO().start().waitFor() | ||
ProcessBuilder("git", "push", "origin", "main", "--tags").inheritIO().start().waitFor() |