Skip to content

Commit

Permalink
Change SNAPSHOT is treated now as non-special stage (higher than rc)
Browse files Browse the repository at this point in the history
  • Loading branch information
JavierSegoviaCordoba committed Jan 4, 2023
1 parent 72b1941 commit b7504f4
Show file tree
Hide file tree
Showing 18 changed files with 44 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

### Changed

- `SNAPSHOT` is treated now as non-special stage (higher than `rc`)

### Deprecated

### Removed
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
hubdle = "0.2.0-alpha.46"
jgit = "6.4.0.202211300538-r"
semverCore = "0.1.0-beta.10"
semverCore = "0.1.0-beta.12"

[libraries]
javiersc-semver-semverCore = { module = "com.javiersc.semver:semver-core", version.ref = "semverCore" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,29 @@ internal fun calculatedVersion(
val isClean: Boolean = clean || !checkClean
val isDirty: Boolean = !isClean

val stagePropertySanitized =
stageProperty?.let { name ->
if (name.equals("SNAPSHOT", ignoreCase = true)) "SNAPSHOT" else name
}

val lastSemverStageInCurrentBranchSanitized =
lastSemverStageInCurrentBranch?.let { name ->
if (name.equals("SNAPSHOT", ignoreCase = true)) "SNAPSHOT" else name
}

val lastSemverInCurrentBranch =
Version(
major = lastSemverMajorInCurrentBranch,
minor = lastSemverMinorInCurrentBranch,
patch = lastSemverPatchInCurrentBranch,
stageName = lastSemverStageInCurrentBranch,
stageName = lastSemverStageInCurrentBranchSanitized,
stageNum = lastSemverNumInCurrentBranch,
)

val previousStage: String? = lastSemverInCurrentBranch.stage?.name

val incStage: String =
(stageProperty ?: previousStage ?: "").run {
(stagePropertySanitized ?: previousStage ?: "").run {
when {
equals(Stage.Auto(), true) && !previousStage.isNullOrBlank() -> previousStage
equals(Stage.Auto(), true) -> ""
Expand All @@ -46,7 +56,9 @@ internal fun calculatedVersion(
}

val isNoStagedNoScopedNoCreatingSemverTag: Boolean =
stageProperty.isNullOrBlank() && scopeProperty.isNullOrBlank() && !isCreatingSemverTag
stagePropertySanitized.isNullOrBlank() &&
scopeProperty.isNullOrBlank() &&
!isCreatingSemverTag

val calculatedVersion: String =
when {
Expand All @@ -63,15 +75,7 @@ internal fun calculatedVersion(
)
"$lastSemverInCurrentBranch$additionalVersionData"
}
stageProperty.equals(Stage.Snapshot(), ignoreCase = true) -> {
when (scopeProperty) {
Scope.Major() -> "${lastSemverInCurrentBranch.nextSnapshotMajor()}"
Scope.Minor() -> "${lastSemverInCurrentBranch.nextSnapshotMinor()}"
Scope.Patch() -> "${lastSemverInCurrentBranch.nextSnapshotPatch()}"
else -> "${lastSemverInCurrentBranch.nextSnapshotPatch()}"
}
}
stageProperty.equals(Stage.Final(), ignoreCase = true) -> {
stagePropertySanitized.equals(Stage.Final(), ignoreCase = true) -> {
when (scopeProperty) {
Scope.Major() -> "${lastSemverInCurrentBranch.inc(Increase.Major, "")}"
Scope.Minor() -> "${lastSemverInCurrentBranch.inc(Increase.Minor, "")}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal enum class SemverProperties(val key: String) {
internal enum class Stage(private val value: String) {
Auto("auto"),
Final("final"),
Snapshot("snapshot");
;

operator fun invoke(): String = value
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1.0.0-SNAPSHOT
v1.0.0-SNAPSHOT

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
createSemverTag -Psemver.stage=snapshot -Psemver.tagPrefix=v
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
id("com.javiersc.semver.gradle.plugin")
}

semver {
tagPrefix.set("v")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1.0.0-SNAPSHOT
v1.0.0-SNAPSHOT
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
semver.tagPrefix=v
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v1.0.0-rc.3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = "sandbox-project"
9 changes: 9 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pluginManagement {
gradlePluginPortal()
mavenCentral()
google()
mavenLocal()
}

plugins {
Expand All @@ -19,3 +20,11 @@ pluginManagement {
plugins {
id("com.javiersc.hubdle.settings")
}

dependencyResolutionManagement {
repositories {
mavenCentral()
google()
mavenLocal()
}
}

0 comments on commit b7504f4

Please sign in to comment.