mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 16:28:12 -07:00
Added AutoGitTagConfig.
This commit is contained in:
parent
4f32f0ba2f
commit
c80020c36a
2 changed files with 50 additions and 30 deletions
|
@ -6,10 +6,10 @@ import com.google.inject.Inject
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class Git @Inject constructor() {
|
class Git @Inject constructor() {
|
||||||
fun maybeTagRelease(project: Project, uploadResult: TaskResult, autoGitTag: Triple<Boolean, String, String>) : TaskResult {
|
fun maybeTagRelease(project: Project, uploadResult: TaskResult, auto: Boolean, tag: String, message: String) : TaskResult {
|
||||||
val result =
|
val result =
|
||||||
if (uploadResult.success && autoGitTag.first) {
|
if (uploadResult.success && auto) {
|
||||||
val tagSuccess = tagRelease(project, autoGitTag)
|
val tagSuccess = tagRelease(project, auto, tag, message)
|
||||||
if (! tagSuccess) {
|
if (! tagSuccess) {
|
||||||
TaskResult(false, "Couldn't tag the project")
|
TaskResult(false, "Couldn't tag the project")
|
||||||
} else {
|
} else {
|
||||||
|
@ -21,9 +21,9 @@ class Git @Inject constructor() {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun tagRelease(project: Project, autoGitTag: Triple<Boolean, String, String>) : Boolean {
|
private fun tagRelease(project: Project, auto: Boolean, tag: String, message: String) : Boolean {
|
||||||
|
val version = if (tag.isNullOrBlank()) project.version else tag
|
||||||
val success = try {
|
val success = try {
|
||||||
val version = if (autoGitTag.second.isNullOrBlank()) project.version else autoGitTag.second
|
|
||||||
log(2, "Tagging this release as \"$version\"")
|
log(2, "Tagging this release as \"$version\"")
|
||||||
val repo = org.eclipse.jgit.storage.file.FileRepositoryBuilder()
|
val repo = org.eclipse.jgit.storage.file.FileRepositoryBuilder()
|
||||||
.setGitDir(File(KFiles.joinDir(project.directory, ".git")))
|
.setGitDir(File(KFiles.joinDir(project.directory, ".git")))
|
||||||
|
@ -31,11 +31,11 @@ class Git @Inject constructor() {
|
||||||
.findGitDir()
|
.findGitDir()
|
||||||
.build()
|
.build()
|
||||||
val git = org.eclipse.jgit.api.Git(repo)
|
val git = org.eclipse.jgit.api.Git(repo)
|
||||||
val ref = git.tag().setName(version).setMessage(autoGitTag.third).call()
|
val ref = git.tag().setName(version).setMessage(message).call()
|
||||||
git.push().setPushTags().call()
|
git.push().setPushTags().call()
|
||||||
true
|
true
|
||||||
} catch(ex: Exception) {
|
} catch(ex: Exception) {
|
||||||
warn("Couldn't create tag ${project.version}: ${ex.message}", ex)
|
warn("Couldn't create tag ${version}: ${ex.message}", ex)
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,6 +112,7 @@ class PublishPlugin @Inject constructor(val files: KFiles, val factory: PomGener
|
||||||
val jcenter = bintrayFactory.create(user, password, org)
|
val jcenter = bintrayFactory.create(user, password, org)
|
||||||
var success = false
|
var success = false
|
||||||
val configuration = bintrayConfigurations[project.name]
|
val configuration = bintrayConfigurations[project.name]
|
||||||
|
val autoGitTagConfig = autoGitTagConfigurations[project.name]
|
||||||
val messages = arrayListOf<String>()
|
val messages = arrayListOf<String>()
|
||||||
|
|
||||||
val tmpResult =
|
val tmpResult =
|
||||||
|
@ -133,7 +134,13 @@ class PublishPlugin @Inject constructor(val files: KFiles, val factory: PomGener
|
||||||
messages.add(taskResult.errorMessage!!)
|
messages.add(taskResult.errorMessage!!)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
git.maybeTagRelease(project, TaskResult(), configuration.autoGitTag)
|
if (autoGitTagConfig != null) {
|
||||||
|
with(autoGitTagConfig) {
|
||||||
|
git.maybeTagRelease(project, TaskResult(), auto, tag, message)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
TaskResult()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
context.logger.log(project.name, 2, "Couldn't find any jcenter{} configuration, not uploading anything")
|
context.logger.log(project.name, 2, "Couldn't find any jcenter{} configuration, not uploading anything")
|
||||||
TaskResult()
|
TaskResult()
|
||||||
|
@ -153,6 +160,7 @@ class PublishPlugin @Inject constructor(val files: KFiles, val factory: PomGener
|
||||||
|
|
||||||
private fun uploadGithub(project: Project) : TaskResult {
|
private fun uploadGithub(project: Project) : TaskResult {
|
||||||
val configuration = githubConfigurations[project.name]
|
val configuration = githubConfigurations[project.name]
|
||||||
|
val autoGitTagConfig = autoGitTagConfigurations[project.name]
|
||||||
|
|
||||||
//
|
//
|
||||||
// Upload individual files, if applicable
|
// Upload individual files, if applicable
|
||||||
|
@ -163,7 +171,13 @@ class PublishPlugin @Inject constructor(val files: KFiles, val factory: PomGener
|
||||||
logk(project.name, 2, "Uploading $it tag: ${project.version}")
|
logk(project.name, 2, "Uploading $it tag: ${project.version}")
|
||||||
github.uploadRelease(project.name, project.version!!, it)
|
github.uploadRelease(project.name, project.version!!, it)
|
||||||
}
|
}
|
||||||
git.maybeTagRelease(project, TaskResult(), configuration.autoGitTag)
|
if (autoGitTagConfig != null) {
|
||||||
|
with(autoGitTagConfig) {
|
||||||
|
git.maybeTagRelease(project, TaskResult(), auto, tag, message)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
TaskResult()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
warn("Couldn't find any github{} configuration, not uploading anything")
|
warn("Couldn't find any github{} configuration, not uploading anything")
|
||||||
TaskResult()
|
TaskResult()
|
||||||
|
@ -187,20 +201,29 @@ class PublishPlugin @Inject constructor(val files: KFiles, val factory: PomGener
|
||||||
fun addGithubConfiguration(projectName: String, config: GithubConfig) {
|
fun addGithubConfiguration(projectName: String, config: GithubConfig) {
|
||||||
githubConfigurations.put(projectName, config)
|
githubConfigurations.put(projectName, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map of project name -> AutoGitTagConfiguration
|
||||||
|
*/
|
||||||
|
private val autoGitTagConfigurations = hashMapOf<String, AutoGitTagConfig>()
|
||||||
|
fun addAutoGitTagConfiguration(projectName: String, config: AutoGitTagConfig) {
|
||||||
|
autoGitTagConfigurations.put(projectName, config)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data class AutoGitTagConfig(val project: Project) {
|
||||||
|
@Directive
|
||||||
|
var auto: Boolean = true
|
||||||
|
|
||||||
|
@Directive
|
||||||
|
var tag : String = project.version!!
|
||||||
|
|
||||||
|
@Directive
|
||||||
|
var message : String = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
data class GithubConfig(val project: Project) {
|
data class GithubConfig(val project: Project) {
|
||||||
val files = arrayListOf<File>()
|
val files = arrayListOf<File>()
|
||||||
var autoGitTag = Triple(true, project.version!!, "")
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If true, automatically tag this release with the current version number and push that tag to origin when
|
|
||||||
* the uploadGithub task is called.
|
|
||||||
*/
|
|
||||||
@Directive
|
|
||||||
fun autoGitTag(auto: Boolean = autoGitTag.first, tag: String = project.version!!, message: String = autoGitTag.third) {
|
|
||||||
autoGitTag = Triple(auto, tag, message)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Directive
|
@Directive
|
||||||
fun file(filePath: String, url: String) {
|
fun file(filePath: String, url: String) {
|
||||||
|
@ -215,9 +238,8 @@ fun Project.github(init: GithubConfig.() -> Unit): GithubConfig =
|
||||||
(Kobalt.findPlugin(PublishPlugin.PLUGIN_NAME) as PublishPlugin).addGithubConfiguration(name, config)
|
(Kobalt.findPlugin(PublishPlugin.PLUGIN_NAME) as PublishPlugin).addGithubConfiguration(name, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
data class BintrayConfig(val project: Project) {
|
data class BintrayConfig(val project: Project) {
|
||||||
val files = arrayListOf<Pair<String, String>>()
|
val files = arrayListOf<Pair<String, String>>()
|
||||||
var autoGitTag = Triple(true, project.version!!, "")
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If true, the uploaded file will be published in your personal space (e.g. https://dl.bintray.com/cbeust/maven).
|
* If true, the uploaded file will be published in your personal space (e.g. https://dl.bintray.com/cbeust/maven).
|
||||||
|
@ -234,15 +256,6 @@ data class BintrayConfig(val project: Project) {
|
||||||
@Directive
|
@Directive
|
||||||
var sign: Boolean = false
|
var sign: Boolean = false
|
||||||
|
|
||||||
/**
|
|
||||||
* If true, automatically tag this release with the current version number and push that tag to origin when
|
|
||||||
* the uploadBintray task is called.
|
|
||||||
*/
|
|
||||||
@Directive
|
|
||||||
fun autoGitTag(auto: Boolean = autoGitTag.first, tag: String = project.version!!, message: String = autoGitTag.third) {
|
|
||||||
autoGitTag = Triple(auto, tag, message)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Directive
|
@Directive
|
||||||
fun file(filePath: String, url: String) {
|
fun file(filePath: String, url: String) {
|
||||||
files.add(Pair(filePath, url))
|
files.add(Pair(filePath, url))
|
||||||
|
@ -261,3 +274,10 @@ fun Project.bintray(init: BintrayConfig.() -> Unit) =
|
||||||
config.init()
|
config.init()
|
||||||
(Kobalt.findPlugin(PublishPlugin.PLUGIN_NAME) as PublishPlugin).addBintrayConfiguration(name, config)
|
(Kobalt.findPlugin(PublishPlugin.PLUGIN_NAME) as PublishPlugin).addBintrayConfiguration(name, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Directive
|
||||||
|
fun Project.autoGitTag(init: AutoGitTagConfig.() -> Unit) =
|
||||||
|
AutoGitTagConfig(this).also { config ->
|
||||||
|
config.init()
|
||||||
|
(Kobalt.findPlugin(PublishPlugin.PLUGIN_NAME) as PublishPlugin).addAutoGitTagConfiguration(name, config)
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue