@@ -16,7 +16,9 @@ internal const val RELEASE_PREFIX = "release"
16
16
*
17
17
* TODO: add configuration for remotes other than 'origin'
18
18
*/
19
- internal fun String.shortName () = Repository .shortenRefName(this ).substringAfterLast(Constants .DEFAULT_REMOTE_NAME + " /" )
19
+ internal fun String.shortName () =
20
+ Repository .shortenRefName(this ).substringAfterLast(Constants .DEFAULT_REMOTE_NAME + " /" )
21
+
20
22
internal fun String.removeReleasePrefix () = this .substringAfterLast(" $RELEASE_PREFIX /" )
21
23
internal fun String.hasReleasePrefix () = this .startsWith(" $RELEASE_PREFIX /" )
22
24
@@ -39,7 +41,7 @@ public class Releases public constructor(private val git: Git) {
39
41
try {
40
42
git.fetch().call()
41
43
} catch (e: TransportException ) {
42
- logger.warn(" (!) Not able to fetch remote repository <${e.message} >, will proceed with local snapshot" )
44
+ logger.warn(" (!) Not able to fetch remote repository <${e.message} >, will proceed with local snapshot. " )
43
45
}
44
46
}
45
47
@@ -58,6 +60,7 @@ public class Releases public constructor(private val git: Git) {
58
60
public fun getLatestReleaseBranch (): ReleaseBranch ? =
59
61
releaseBranches.maxByOrNull { it.version }
60
62
63
+ // TODO: Not to create a release if we are now on main and on this commit there is already a release branch made
61
64
public fun createNewRelease (releaseType : SemVerReleaseType ): String {
62
65
val newVersion = getLatestReleaseBranch()
63
66
?.version
@@ -67,7 +70,7 @@ public class Releases public constructor(private val git: Git) {
67
70
if (currentCheckoutBranch != mainBranch) {
68
71
throw IllegalStateException (
69
72
" (!) Branch which is currently checked out is [${currentCheckoutBranch.ref.name} ], " +
70
- " but ${releaseType.name} release should be done from [${mainBranch.ref.name} ] branch. " +
73
+ " but ${releaseType.name} release should always be done from [${mainBranch.ref.name} ] branch. " +
71
74
" Because during the release VerCraft will create a new branch and tag."
72
75
)
73
76
} else {
@@ -79,7 +82,9 @@ public class Releases public constructor(private val git: Git) {
79
82
// FIXME: need to switch to latest release branch and latest commit and set release tag there
80
83
} else {
81
84
createBranch(newVersion)
85
+ pushBranch(newVersion)
82
86
createTag(newVersion)
87
+ pushTag(newVersion)
83
88
}
84
89
}
85
90
return " $newVersion "
@@ -91,21 +96,22 @@ public class Releases public constructor(private val git: Git) {
91
96
" (!) The branch with the version [$version ] which was selected for " +
92
97
" the new release already exists. No branches will be created, please change the version."
93
98
)
94
-
95
99
} else {
96
100
createBranch(version)
101
+ pushBranch(version)
97
102
createTag(version)
103
+ pushTag(version)
98
104
}
99
105
return version.toString()
100
106
}
101
107
102
108
private fun createTag (newVersion : SemVer ) {
103
109
git.tag()
104
- .setName(newVersion.toString() )
110
+ .setName(" v ${ newVersion} " )
105
111
.setMessage(" Release $newVersion " )
106
112
.call()
107
113
108
- logger.warn(" + Created a tag [Release $newVersion ]" )
114
+ logger.warn(" + Created a tag v $newVersion [Release $newVersion ]" )
109
115
}
110
116
111
117
private fun createBranch (newVersion : SemVer ) {
@@ -117,6 +123,32 @@ public class Releases public constructor(private val git: Git) {
117
123
logger.warn(" + Created a branch [release/$newVersion ]" )
118
124
}
119
125
126
+ private fun pushBranch (newVersion : SemVer ) {
127
+ try {
128
+ git.push()
129
+ .setCredentialsProvider(LocalCredentialsProvider )
130
+ .add(" release/$newVersion " )
131
+ .call()
132
+
133
+ logger.warn(" + Pushed a branch [release/$newVersion ]" )
134
+ } catch (e: TransportException ) {
135
+ logger.warn(" (!) Not able to push branch to remote repository <${e.message} >, please do it manually." )
136
+ }
137
+ }
138
+
139
+ private fun pushTag (newVersion : SemVer ) {
140
+ try {
141
+ git.push()
142
+ .setCredentialsProvider(LocalCredentialsProvider )
143
+ .add(" refs/tags/v$newVersion " )
144
+ .call()
145
+
146
+ logger.warn(" + Pushed a tag v$newVersion [Release $newVersion ]" )
147
+ } catch (e: TransportException ) {
148
+ logger.warn(" (!) Not able to push tag to remote repository <${e.message} >, please do it manually." )
149
+ }
150
+ }
151
+
120
152
/* *
121
153
* We have two sources for release branches: they can be created locally or can be taken from `remotes/origin`
122
154
*/
@@ -126,16 +158,20 @@ public class Releases public constructor(private val git: Git) {
126
158
val releaseBranchesFromRemote = getAndFilterReleaseBranches(git.branchList().setListMode(REMOTE ))
127
159
val localReleaseBranches = getAndFilterReleaseBranches(git.branchList().setListMode(null ))
128
160
129
- // we will union LOCAL branches with REMOTE, with a priority to LOCAL
161
+ // we will make a union of LOCAL branches and REMOTE, with a priority to LOCAL
130
162
val allReleaseBranches = (localReleaseBranches + releaseBranchesFromRemote)
131
163
.groupBy { it.branch.ref.name.shortName() }
132
164
133
165
allReleaseBranches.keys.forEach {
134
- if (allReleaseBranches[it]!! .size > 1 ) {
135
- if (allReleaseBranches[it]!! [0 ].branch.gitLog != allReleaseBranches[it]!! [1 ].branch.gitLog) {
166
+ val value = allReleaseBranches[it]
167
+ if (value!! .size > 1 ) {
168
+ if (value[0 ].branch.gitLog != value[1 ].branch.gitLog) {
136
169
// TODO: error when release branch is checked-out (and calculating version for it) and differs from remote
137
- logger.warn(" jFYI: Remote branch $it differs from the local branch $it . " +
138
- " Do you have any unpublished changes in your local branch?" )
170
+ logger.warn(
171
+ " (!) jFYI: Remote and local branches '$it ' differ. " +
172
+ " Do you have any unpublished changes in your local branch? Will use " +
173
+ " local branch to calculate versions."
174
+ )
139
175
}
140
176
}
141
177
}
0 commit comments