Skip to content

Commit

Permalink
The dev version of IdeaVim should calculate the version based on a pr…
Browse files Browse the repository at this point in the history
…evious non-patched release version

As the patch versions are placed not in the master branch, we should calculate the diff between releases only for releases that are located in master branch
  • Loading branch information
AlexPl292 committed Dec 1, 2023
1 parent 64538c2 commit 836e9a2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fun main(args: Array<String>) {
println("HI!")
val projectDir = args[0]
println("Working directory: $projectDir")
val (lastVersion, objectId) = getVersion(projectDir, onlyStable = true)
val (lastVersion, objectId) = getVersion(projectDir, ReleaseType.STABLE_NO_PATCH)
println("Last version: $lastVersion, hash: ${objectId.name}")

val branch = withRepo(projectDir) { it.branch }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fun main(args: Array<String>) {
println("HI!")
val projectDir = args[0]
println("Working directory: $projectDir")
val (lastVersion, _) = getVersion(projectDir, onlyStable = false)
val (lastVersion, _) = getVersion(projectDir, ReleaseType.ANY)

val nextVersion = if (lastVersion.suffixTokens.isEmpty()) {
lastVersion.nextMinor().withSuffix("eap.1").value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fun main(args: Array<String>) {
val releaseType = args[1]
println("Working directory: $projectDir")
println("Release type: $releaseType")
val (lastVersion, _) = getVersion(projectDir, onlyStable = true)
val (lastVersion, _) = getVersion(projectDir, ReleaseType.ONLY_STABLE)

val nextVersion = when (releaseType) {
"major" -> lastVersion.nextMajor()
Expand Down
16 changes: 11 additions & 5 deletions scripts/src/main/kotlin/scripts/release/util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@ internal fun checkBranch(rootDir: String, releaseType: String) {
}
}

internal fun getVersion(projectDir: String, onlyStable: Boolean): Pair<Semver, ObjectId> {
enum class ReleaseType {
ANY,
ONLY_STABLE,
STABLE_NO_PATCH, // Version that ends on 0. Like 2.5.0
}

internal fun getVersion(projectDir: String, releaseType: ReleaseType): Pair<Semver, ObjectId> {
val repository = RepositoryBuilder().setGitDir(File("$projectDir/.git")).build()
val git = Git(repository)
println(git.log().call().first())
Expand All @@ -75,10 +81,10 @@ internal fun getVersion(projectDir: String, onlyStable: Boolean): Pair<Semver, O
}
.sortedBy { it.first }

val version = if (onlyStable) {
versions.last { it.first.isStable }
} else {
versions.last()
val version = when (releaseType) {
ReleaseType.ANY -> versions.last()
ReleaseType.ONLY_STABLE -> versions.last { it.first.isStable }
ReleaseType.STABLE_NO_PATCH -> versions.last { it.first.isStable && it.first.patch == 0 }
}

return version
Expand Down

0 comments on commit 836e9a2

Please sign in to comment.