Skip to content

Commit 1f2f6a7

Browse files
authored
Updated version calculation for release branches (#27)
1 parent 77ffabf commit 1f2f6a7

File tree

5 files changed

+21
-13
lines changed

5 files changed

+21
-13
lines changed

.github/workflows/build_and_test.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
push:
66
branches:
77
- 'main'
8+
- 'release/**'
89

910
env:
1011
GRADLE_OPTS: -Dorg.gradle.daemon=true -Dorg.gradle.parallel=true -Dorg.gradle.welcome=never
@@ -18,7 +19,11 @@ jobs:
1819
os: [ ubuntu-latest ]
1920

2021
steps:
21-
- uses: actions/checkout@v4
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
with:
25+
# release workflow should have access to all tags
26+
fetch-depth: 0
2227
- uses: gradle/actions/wrapper-validation@v4
2328
- name: Set up JDK 21
2429
uses: actions/setup-java@v4

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ name: Create release to Maven Central
22

33
on:
44
push:
5-
tags:
6-
- 'v*'
5+
branches:
6+
- 'release/**'
77

88
env:
99
PGP_SEC: ${{ secrets.PGP_SEC }}

core/src/main/kotlin/com/akuleshov7/vercraft/core/Branch.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public class Branch(git: Git, public val ref: Ref) {
3636
if (commitInBranch.id.name == startCommit.id.name) {
3737
if (!endFound) {
3838
throw IllegalStateException(
39-
"Invalid commit order: Head commit '${endCommit.id.toString().substring(0, 5)}' was found " +
40-
"before the starting commit '${startCommit.id.toString().substring(0, 5)}'. "
39+
"Invalid commit order: Head commit '${endCommit.name.toString().substring(0, 5)}' was found " +
40+
"before the starting commit '${startCommit.name.toString().substring(0, 5)}'. "
4141
)
4242
}
4343
return count
@@ -50,8 +50,8 @@ public class Branch(git: Git, public val ref: Ref) {
5050

5151
// If we complete the loop without finding both commits, return -1
5252
throw IllegalArgumentException(
53-
"Not able to find neither commit ${startCommit.id.toString().substring(0, 5)}, " +
54-
"nor commit ${endCommit.id.toString().substring(0, 5)}"
53+
"Not able to find neither commit ${startCommit.name.toString().substring(0, 5)}, " +
54+
"nor commit ${endCommit.name.toString().substring(0, 5)}"
5555
)
5656
}
5757

core/src/main/kotlin/com/akuleshov7/vercraft/core/Releases.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,19 +163,21 @@ public class Releases public constructor(private val git: Git, private val confi
163163
val releaseBranchesFromRemote = getAndFilterReleaseBranches(git.branchList().setListMode(REMOTE))
164164
val localReleaseBranches = getAndFilterReleaseBranches(git.branchList().setListMode(null))
165165

166-
// we will make a union of LOCAL branches and REMOTE, with a priority to LOCAL
167-
val allReleaseBranches = (localReleaseBranches + releaseBranchesFromRemote)
166+
// we will make a union of LOCAL branches and REMOTE, with a priority to REMOTE
167+
// TODO: think about it once again - for LOCAL case and detached HEAD may be it will be more useful to use LOCAL
168+
// TODO: for CI case - definitely REMOTE (there is no LOCAL branches for CI)
169+
// TODO: if there are differences and changes in LOCAL branch, but we are using remote, there will be more commits and we will fail
170+
val allReleaseBranches = (releaseBranchesFromRemote + localReleaseBranches)
168171
.groupBy { it.branch.ref.name.shortName(config.remote) }
169172

170173
allReleaseBranches.keys.forEach {
171174
val value = allReleaseBranches[it]
172175
if (value!!.size > 1) {
173176
if (value[0].branch.gitLog != value[1].branch.gitLog) {
174-
// TODO: error when release branch is checked-out (and calculating version for it) and differs from remote
175177
logger.warn(
176178
"$ERROR_PREFIX Remote and local branches '$it' differ. " +
177-
"Do you have any unpublished changes in your local branch? Will use " +
178-
"local branch to calculate versions."
179+
"Do you have any non-pushed commits in your local branch? Will use " +
180+
"remote branch to calculate versions."
179181
)
180182
}
181183
}

core/src/main/kotlin/com/akuleshov7/vercraft/core/VersionCalculator.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,9 @@ public class VersionCalculator(
142142
?: throw IllegalStateException(
143143
"Can't find common ancestor commits between ${config.defaultMainBranch} " +
144144
"and ${currentCheckoutBranch.ref.name} branches. Looks like these branches have no relation " +
145-
"and that is inconsistent git state."
145+
"and that is an inconsistent git state."
146146
)
147+
147148
return currentCheckoutBranch.distanceBetweenCommits(baseCommit, headCommit)
148149
}
149150
}

0 commit comments

Comments
 (0)